Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:35

0001 #include <string>
0002 #include <unordered_map>
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0007 
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0015 
0016 //
0017 // class declaration
0018 //
0019 
0020 struct Histogram_TICLPFValidation {
0021   dqm::reco::MonitorElement* type_;
0022   dqm::reco::MonitorElement* energy_;
0023   dqm::reco::MonitorElement* pt_;
0024   dqm::reco::MonitorElement* eta_;
0025   dqm::reco::MonitorElement* phi_;
0026   dqm::reco::MonitorElement* charge_;
0027   dqm::reco::MonitorElement* vect_sum_pt_;  // cumulative histogram
0028 };
0029 
0030 using Histograms_TICLPFValidation = std::unordered_map<int, Histogram_TICLPFValidation>;
0031 
0032 class TICLPFValidation : public DQMGlobalEDAnalyzer<Histograms_TICLPFValidation> {
0033 public:
0034   explicit TICLPFValidation(const edm::ParameterSet&);
0035   ~TICLPFValidation() override;
0036 
0037   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0038 
0039 private:
0040   void bookHistograms(DQMStore::IBooker&,
0041                       edm::Run const&,
0042                       edm::EventSetup const&,
0043                       Histograms_TICLPFValidation&) const override;
0044 
0045   void dqmAnalyze(edm::Event const&, edm::EventSetup const&, Histograms_TICLPFValidation const&) const override;
0046 
0047   // ----------member data ---------------------------
0048   std::string folder_;
0049   edm::EDGetTokenT<reco::PFCandidateCollection> pfCandidates_;
0050 };
0051 
0052 //
0053 // constants, enums and typedefs
0054 //
0055 
0056 //
0057 // static data member definitions
0058 //
0059 
0060 //
0061 // constructors and destructor
0062 //
0063 TICLPFValidation::TICLPFValidation(const edm::ParameterSet& iConfig)
0064     : folder_(iConfig.getParameter<std::string>("folder")),
0065       pfCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("ticlPFCandidates"))) {
0066   //now do what ever initialization is needed
0067 }
0068 
0069 TICLPFValidation::~TICLPFValidation() {
0070   // do anything here that needs to be done at desctruction time
0071   // (e.g. close files, deallocate resources etc.)
0072 }
0073 
0074 //
0075 // member functions
0076 //
0077 
0078 // ------------ method called for each event  ------------
0079 
0080 void TICLPFValidation::dqmAnalyze(edm::Event const& iEvent,
0081                                   edm::EventSetup const& iSetup,
0082                                   Histograms_TICLPFValidation const& histos) const {
0083   using namespace edm;
0084 
0085   Handle<reco::PFCandidateCollection> pfCandidatesHandle;
0086   iEvent.getByToken(pfCandidates_, pfCandidatesHandle);
0087   reco::PFCandidateCollection const& pfCandidates = *pfCandidatesHandle;
0088 
0089   // pfCandidates
0090   double ptx_tot = 0.;
0091   double pty_tot = 0.;
0092   for (auto const& pfc : pfCandidates) {
0093     size_t type = pfc.particleId();
0094     ptx_tot += pfc.px();
0095     pty_tot += pfc.py();
0096     histos.at(0).type_->Fill(type);
0097     auto& histo = histos.at(type);
0098     histo.energy_->Fill(pfc.energy());
0099     histo.pt_->Fill(pfc.pt());
0100     histo.eta_->Fill(pfc.eta());
0101     histo.phi_->Fill(pfc.phi());
0102     histo.charge_->Fill(pfc.charge());
0103   }
0104   auto& histo = histos.at(0);
0105   histo.vect_sum_pt_->Fill(std::sqrt(ptx_tot * ptx_tot + pty_tot * pty_tot));
0106 }
0107 
0108 void TICLPFValidation::bookHistograms(DQMStore::IBooker& ibook,
0109                                       edm::Run const& run,
0110                                       edm::EventSetup const& iSetup,
0111                                       Histograms_TICLPFValidation& histos) const {
0112   ibook.setCurrentFolder(folder_ + "TICLPFCandidates/");
0113   histos[0].type_ = ibook.book1D("Type", "Type", 10, -0.5, 9.5);
0114   histos[0].vect_sum_pt_ = ibook.book1D("PtVectSum", "PtVectSum", 200, 0., 200.);
0115   for (size_t type = reco::PFCandidate::X; type <= reco::PFCandidate::egamma_HF; type++) {
0116     ibook.setCurrentFolder(folder_ + "TICLPFCandidates/" + std::to_string(type));
0117     auto& histo = histos[type];
0118     histo.energy_ = ibook.book1D("Energy", "Energy", 250, 0., 250.);
0119     histo.pt_ = ibook.book1D("Pt", "Pt", 250, 0., 250.);
0120     histo.eta_ = ibook.book1D("Eta", "Eta", 100, -5., 5.);
0121     histo.phi_ = ibook.book1D("Phi", "Phi", 100, -4., 4.);
0122     histo.charge_ = ibook.book1D("Charge", "Charge", 3, -1.5, 1.5);
0123   }
0124 }
0125 
0126 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0127 void TICLPFValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0128   //The following says we do not know what parameters are allowed so do no validation
0129   // Please change this to state exactly what you do use, even if it is no parameters
0130   edm::ParameterSetDescription desc;
0131   desc.add<std::string>("folder", "HGCAL/");  // Please keep the trailing '/'
0132   desc.add<edm::InputTag>("ticlPFCandidates", edm::InputTag("pfTICL"));
0133   descriptions.add("ticlPFValidationDefault", desc);
0134 }
0135 
0136 //define this as a plug-in
0137 DEFINE_FWK_MODULE(TICLPFValidation);