Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:38

0001 // -*- C++ -*-
0002 //
0003 // Class:      CaloParticleValidation
0004 // Original Author:  Marco Rovere
0005 // Created:  Thu, 18 Jan 2018 15:54:55 GMT
0006 //
0007 //
0008 
0009 #include <string>
0010 #include <unordered_map>
0011 
0012 // user include files
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0015 
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 
0021 #include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
0022 #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h"
0023 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0024 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0025 #include "SimDataFormats/Vertex/interface/SimVertex.h"
0026 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0027 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0028 
0029 //
0030 // class declaration
0031 //
0032 
0033 struct Histogram_CaloParticleSingle {
0034   dqm::reco::MonitorElement* simPFSuperClusterSize_;
0035   dqm::reco::MonitorElement* simPFSuperClusterEnergy_;
0036   dqm::reco::MonitorElement* pfcandidateType_;
0037   dqm::reco::MonitorElement* pfcandidateEnergy_;
0038   dqm::reco::MonitorElement* pfcandidatePt_;
0039   dqm::reco::MonitorElement* pfcandidateEta_;
0040   dqm::reco::MonitorElement* pfcandidatePhi_;
0041   dqm::reco::MonitorElement* pfcandidateElementsInBlocks_;
0042   dqm::reco::MonitorElement* pfcandidate_vect_sum_pt_;  // This is indeed a cumulative istogram
0043 };
0044 
0045 using Histograms_CaloParticleValidation = std::unordered_map<int, Histogram_CaloParticleSingle>;
0046 
0047 class CaloParticleValidation : public DQMGlobalEDAnalyzer<Histograms_CaloParticleValidation> {
0048 public:
0049   explicit CaloParticleValidation(const edm::ParameterSet&);
0050   ~CaloParticleValidation() override;
0051 
0052   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0053 
0054 private:
0055   void bookHistograms(DQMStore::IBooker&,
0056                       edm::Run const&,
0057                       edm::EventSetup const&,
0058                       Histograms_CaloParticleValidation&) const override;
0059 
0060   void dqmAnalyze(edm::Event const&, edm::EventSetup const&, Histograms_CaloParticleValidation const&) const override;
0061 
0062   // ----------member data ---------------------------
0063   std::string folder_;
0064   edm::EDGetTokenT<std::vector<reco::SuperCluster>> simPFClusters_;
0065   edm::EDGetTokenT<reco::PFCandidateCollection> simPFCandidates_;
0066 };
0067 
0068 //
0069 // constants, enums and typedefs
0070 //
0071 
0072 //
0073 // static data member definitions
0074 //
0075 
0076 //
0077 // constructors and destructor
0078 //
0079 CaloParticleValidation::CaloParticleValidation(const edm::ParameterSet& iConfig)
0080     : folder_(iConfig.getParameter<std::string>("folder")),
0081       simPFClusters_(consumes<std::vector<reco::SuperCluster>>(iConfig.getParameter<edm::InputTag>("simPFClusters"))),
0082       simPFCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("simPFCandidates"))) {
0083   //now do what ever initialization is needed
0084 }
0085 
0086 CaloParticleValidation::~CaloParticleValidation() {
0087   // do anything here that needs to be done at desctruction time
0088   // (e.g. close files, deallocate resources etc.)
0089 }
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called for each event  ------------
0096 
0097 void CaloParticleValidation::dqmAnalyze(edm::Event const& iEvent,
0098                                         edm::EventSetup const& iSetup,
0099                                         Histograms_CaloParticleValidation const& histos) const {
0100   using namespace edm;
0101 
0102   Handle<std::vector<reco::SuperCluster>> simPFClustersHandle;
0103   iEvent.getByToken(simPFClusters_, simPFClustersHandle);
0104   std::vector<reco::SuperCluster> const& simPFClusters = *simPFClustersHandle;
0105 
0106   Handle<reco::PFCandidateCollection> simPFCandidatesHandle;
0107   iEvent.getByToken(simPFCandidates_, simPFCandidatesHandle);
0108   reco::PFCandidateCollection const& simPFCandidates = *simPFCandidatesHandle;
0109 
0110   // simPFSuperClusters
0111   for (auto const& sc : simPFClusters) {
0112     histos.at(0).simPFSuperClusterSize_->Fill((float)sc.clustersSize());
0113     histos.at(0).simPFSuperClusterEnergy_->Fill(sc.rawEnergy());
0114   }
0115 
0116   // simPFCandidates
0117   int offset = 100000;
0118   double ptx_tot = 0.;
0119   double pty_tot = 0.;
0120   for (auto const& pfc : simPFCandidates) {
0121     size_t type = offset + pfc.particleId();
0122     ptx_tot += pfc.px();
0123     pty_tot += pfc.py();
0124     histos.at(offset).pfcandidateType_->Fill(type - offset);
0125     auto& histo = histos.at(type);
0126     histo.pfcandidateEnergy_->Fill(pfc.energy());
0127     histo.pfcandidatePt_->Fill(pfc.pt());
0128     histo.pfcandidateEta_->Fill(pfc.eta());
0129     histo.pfcandidatePhi_->Fill(pfc.phi());
0130     histo.pfcandidateElementsInBlocks_->Fill(pfc.elementsInBlocks().size());
0131   }
0132   auto& histo = histos.at(offset);
0133   histo.pfcandidate_vect_sum_pt_->Fill(std::sqrt(ptx_tot * ptx_tot + pty_tot * pty_tot));
0134 }
0135 
0136 void CaloParticleValidation::bookHistograms(DQMStore::IBooker& ibook,
0137                                             edm::Run const& run,
0138                                             edm::EventSetup const& iSetup,
0139                                             Histograms_CaloParticleValidation& histos) const {
0140   int offset = 100000;
0141   ibook.setCurrentFolder(folder_ + "PFCandidates");
0142   histos[offset].pfcandidateType_ = ibook.book1D("PFCandidateType", "PFCandidateType", 10, 0, 10);
0143   histos[offset].pfcandidate_vect_sum_pt_ = ibook.book1D("PFCandidatePtVectSum", "PFCandidatePtVectSum", 200, 0., 200.);
0144   for (size_t type = reco::PFCandidate::h; type <= reco::PFCandidate::egamma_HF; type++) {
0145     ibook.setCurrentFolder(folder_ + "PFCandidates/" + std::to_string(type));
0146     auto& histo = histos[offset + type];
0147     histo.pfcandidateEnergy_ = ibook.book1D("PFCandidateEnergy", "PFCandidateEnergy", 250, 0., 250.);
0148     histo.pfcandidatePt_ = ibook.book1D("PFCandidatePt", "PFCandidatePt", 250, 0., 250.);
0149     histo.pfcandidateEta_ = ibook.book1D("PFCandidateEta", "PFCandidateEta", 100, -5., 5.);
0150     histo.pfcandidatePhi_ = ibook.book1D("PFCandidatePhi", "PFCandidatePhi", 100, -4., 4.);
0151     histo.pfcandidateElementsInBlocks_ = ibook.book1D("PFCandidateElements", "PFCandidateElements", 20, 0., 20.);
0152   }
0153   // Folder '0' is meant to be cumulative, with no connection to pdgId
0154   ibook.setCurrentFolder(folder_ + std::to_string(0));
0155   histos[0].simPFSuperClusterSize_ = ibook.book1D("SimPFSuperClusterSize", "SimPFSuperClusterSize", 40, 0., 40.);
0156   histos[0].simPFSuperClusterEnergy_ =
0157       ibook.book1D("SimPFSuperClusterEnergy", "SimPFSuperClusterEnergy", 250, 0., 500.);
0158 }
0159 
0160 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0161 void CaloParticleValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0162   //The following says we do not know what parameters are allowed so do no validation
0163   // Please change this to state exactly what you do use, even if it is no parameters
0164   edm::ParameterSetDescription desc;
0165   desc.add<std::string>("folder", "HGCAL/");  // Please keep the trailing '/'
0166   desc.add<edm::InputTag>("simPFClusters", edm::InputTag("simPFProducer", "perfect"));
0167   desc.add<edm::InputTag>("simPFCandidates", edm::InputTag("simPFProducer"));
0168   descriptions.add("caloparticlevalidationDefault", desc);
0169 }
0170 
0171 //define this as a plug-in
0172 DEFINE_FWK_MODULE(CaloParticleValidation);