Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:59

0001 #include <string>
0002 #include <vector>
0003 
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/Registry.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "DQMServices/Core/interface/DQMStore.h"
0015 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0016 #include "DQMOffline/Trigger/plugins/TriggerDQMBase.h"
0017 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0018 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0019 #include "DataFormats/METReco/interface/PFMET.h"
0020 #include "DataFormats/METReco/interface/PFMETCollection.h"
0021 #include "DataFormats/JetReco/interface/PFJet.h"
0022 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0023 #include "DataFormats/JetReco/interface/CaloJet.h"
0024 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0025 #include "DataFormats/MuonReco/interface/Muon.h"
0026 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0027 #include "DataFormats/TrackReco/interface/Track.h"
0028 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0029 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0030 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0031 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0032 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0033 
0034 class PhotonMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
0035 public:
0036   typedef dqm::reco::MonitorElement MonitorElement;
0037   typedef dqm::reco::DQMStore DQMStore;
0038 
0039   PhotonMonitor(const edm::ParameterSet&);
0040   ~PhotonMonitor() throw() override;
0041   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0042 
0043 protected:
0044   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0045   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0046 
0047 private:
0048   const std::string folderName_;
0049 
0050   const bool requireValidHLTPaths_;
0051   bool hltPathsAreValid_;
0052 
0053   edm::EDGetTokenT<reco::PFMETCollection> metToken_;
0054   edm::EDGetTokenT<reco::PFJetCollection> jetToken_;
0055   edm::EDGetTokenT<reco::GsfElectronCollection> eleToken_;
0056   edm::EDGetTokenT<reco::PhotonCollection> photonToken_;
0057 
0058   std::vector<double> photon_variable_binning_;
0059   std::vector<double> diphoton_mass_binning_;
0060 
0061   MEbinning photon_binning_;
0062   MEbinning ls_binning_;
0063 
0064   ObjME subphotonEtaME_;
0065   ObjME subphotonME_;
0066   ObjME subphotonPhiME_;
0067   ObjME subphotonME_variableBinning_;
0068   ObjME subphotonEtaPhiME_;
0069   ObjME subphotonr9ME_;
0070   ObjME subphotonHoverEME_;
0071   ObjME diphotonMassME_;
0072 
0073   ObjME photonEtaME_;
0074   ObjME photonME_;
0075   ObjME photonPhiME_;
0076   ObjME photonME_variableBinning_;
0077   ObjME photonVsLS_;
0078   ObjME photonEtaPhiME_;
0079   ObjME photonr9ME_;
0080   ObjME photonHoverEME_;
0081 
0082   double MAX_PHI1 = 3.2;
0083   unsigned int N_PHI1 = 64;
0084   const MEbinning phi_binning_1{N_PHI1, -MAX_PHI1, MAX_PHI1};
0085 
0086   double MAX_ETA = 1.4442;
0087   unsigned int N_ETA = 34;
0088   const MEbinning eta_binning_{N_ETA, -MAX_ETA, MAX_ETA};
0089 
0090   double MAX_r9 = 1;
0091   double MIN_r9 = 0;
0092   unsigned int N_r9 = 50;
0093   const MEbinning r9_binning_{N_r9, MIN_r9, MAX_r9};
0094 
0095   double MAX_hoe = 0.02;
0096   double MIN_hoe = 0;
0097   const MEbinning hoe_binning_{N_r9, MIN_hoe, MAX_hoe};
0098 
0099   std::unique_ptr<GenericTriggerEventFlag> num_genTriggerEventFlag_;
0100   std::unique_ptr<GenericTriggerEventFlag> den_genTriggerEventFlag_;
0101 
0102   StringCutObjectSelector<reco::MET, true> metSelection_;
0103   StringCutObjectSelector<reco::PFJet, true> jetSelection_;
0104   StringCutObjectSelector<reco::GsfElectron, true> eleSelection_;
0105   StringCutObjectSelector<reco::Photon, true> photonSelection_;
0106   unsigned int njets_;
0107   unsigned int nphotons_;
0108   unsigned int nelectrons_;
0109 };
0110 
0111 PhotonMonitor::PhotonMonitor(const edm::ParameterSet& iConfig)
0112     : folderName_(iConfig.getParameter<std::string>("FolderName")),
0113       requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
0114       hltPathsAreValid_(false),
0115       metToken_(consumes<reco::PFMETCollection>(iConfig.getParameter<edm::InputTag>("met"))),
0116       jetToken_(mayConsume<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("jets"))),
0117       eleToken_(mayConsume<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
0118       photonToken_(mayConsume<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photons"))),
0119       photon_variable_binning_(
0120           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("photonBinning")),
0121       diphoton_mass_binning_(
0122           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("massBinning")),
0123       photon_binning_(getHistoPSet(
0124           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("photonPSet"))),
0125       ls_binning_(
0126           getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
0127       num_genTriggerEventFlag_(new GenericTriggerEventFlag(
0128           iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
0129       den_genTriggerEventFlag_(new GenericTriggerEventFlag(
0130           iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
0131       metSelection_(iConfig.getParameter<std::string>("metSelection")),
0132       jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
0133       eleSelection_(iConfig.getParameter<std::string>("eleSelection")),
0134       photonSelection_(iConfig.getParameter<std::string>("photonSelection")),
0135       njets_(iConfig.getParameter<unsigned int>("njets")),
0136       nphotons_(iConfig.getParameter<unsigned int>("nphotons")),
0137       nelectrons_(iConfig.getParameter<unsigned int>("nelectrons")) {}
0138 
0139 PhotonMonitor::~PhotonMonitor() throw() {
0140   if (num_genTriggerEventFlag_) {
0141     num_genTriggerEventFlag_.reset();
0142   }
0143   if (den_genTriggerEventFlag_) {
0144     den_genTriggerEventFlag_.reset();
0145   }
0146 }
0147 
0148 void PhotonMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0149   // Initialize the GenericTriggerEventFlag
0150   if (num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on()) {
0151     num_genTriggerEventFlag_->initRun(iRun, iSetup);
0152   }
0153   if (den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on()) {
0154     den_genTriggerEventFlag_->initRun(iRun, iSetup);
0155   }
0156 
0157   // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
0158   hltPathsAreValid_ = (num_genTriggerEventFlag_ && den_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() &&
0159                        den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
0160                        den_genTriggerEventFlag_->allHLTPathsAreValid());
0161 
0162   // if valid HLT paths are required,
0163   // create DQM outputs only if all paths are valid
0164   if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
0165     return;
0166   }
0167 
0168   std::string histname, histtitle;
0169 
0170   std::string currentFolder = folderName_;
0171   ibooker.setCurrentFolder(currentFolder);
0172 
0173   histname = "photon_pt";
0174   histtitle = "photon PT";
0175   bookME(ibooker, photonME_, histname, histtitle, photon_binning_.nbins, photon_binning_.xmin, photon_binning_.xmax);
0176   setMETitle(photonME_, "Photon pT [GeV]", "events / [GeV]");
0177 
0178   histname = "photon_pt_variable";
0179   histtitle = "photon PT";
0180   bookME(ibooker, photonME_variableBinning_, histname, histtitle, photon_variable_binning_);
0181   setMETitle(photonME_variableBinning_, "Photon pT [GeV]", "events / [GeV]");
0182 
0183   histname = "photonVsLS";
0184   histtitle = "photon pt vs LS";
0185   bookME(ibooker,
0186          photonVsLS_,
0187          histname,
0188          histtitle,
0189          ls_binning_.nbins,
0190          ls_binning_.xmin,
0191          ls_binning_.xmax,
0192          photon_binning_.xmin,
0193          photon_binning_.xmax);
0194   setMETitle(photonVsLS_, "LS", "Photon pT [GeV]");
0195 
0196   histname = "photon_phi";
0197   histtitle = "Photon phi";
0198   bookME(ibooker, photonPhiME_, histname, histtitle, phi_binning_1.nbins, phi_binning_1.xmin, phi_binning_1.xmax);
0199   setMETitle(photonPhiME_, "Photon #phi", "events / 0.1 rad");
0200 
0201   histname = "photon_eta";
0202   histtitle = "Photon eta";
0203   bookME(ibooker, photonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
0204   setMETitle(photonEtaME_, "Photon #eta", "events");
0205 
0206   histname = "photon_r9";
0207   histtitle = "Photon r9";
0208   bookME(ibooker, photonr9ME_, histname, histtitle, r9_binning_.nbins, r9_binning_.xmin, r9_binning_.xmax);
0209   setMETitle(photonr9ME_, "Photon r9", "events");
0210 
0211   histname = "photon_hoE";
0212   histtitle = "Photon hoverE";
0213   bookME(ibooker, photonHoverEME_, histname, histtitle, hoe_binning_.nbins, hoe_binning_.xmin, hoe_binning_.xmax);
0214   setMETitle(photonHoverEME_, "Photon hoE", "events");
0215 
0216   histname = "photon_etaphi";
0217   histtitle = "Photon eta-phi";
0218   bookME(ibooker,
0219          photonEtaPhiME_,
0220          histname,
0221          histtitle,
0222          eta_binning_.nbins,
0223          eta_binning_.xmin,
0224          eta_binning_.xmax,
0225          phi_binning_1.nbins,
0226          phi_binning_1.xmin,
0227          phi_binning_1.xmax);
0228   setMETitle(photonEtaPhiME_, "#eta", "#phi");
0229 
0230   // for diphotons
0231   if (nphotons_ > 1) {
0232     histname = "diphoton_mass";
0233     histtitle = "Diphoton mass";
0234     bookME(ibooker, diphotonMassME_, histname, histtitle, diphoton_mass_binning_);
0235     setMETitle(diphotonMassME_, "Diphoton mass", "events / 0.1");
0236 
0237     histname = "subphoton_pt";
0238     histtitle = "subphoton PT";
0239     bookME(
0240         ibooker, subphotonME_, histname, histtitle, photon_binning_.nbins, photon_binning_.xmin, photon_binning_.xmax);
0241     setMETitle(subphotonME_, "subPhoton pT [GeV]", "events / [GeV]");
0242 
0243     histname = "subphoton_eta";
0244     histtitle = "subPhoton eta";
0245     bookME(ibooker, subphotonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
0246     setMETitle(subphotonEtaME_, "subPhoton #eta", "events / 0.1");
0247 
0248     histname = "subphoton_phi";
0249     histtitle = "subPhoton phi";
0250     bookME(ibooker, subphotonPhiME_, histname, histtitle, phi_binning_1.nbins, phi_binning_1.xmin, phi_binning_1.xmax);
0251     setMETitle(subphotonPhiME_, "subPhoton #phi", "events / 0.1 rad");
0252 
0253     histname = "subphoton_r9";
0254     histtitle = "subPhoton r9";
0255     bookME(ibooker, subphotonr9ME_, histname, histtitle, r9_binning_.nbins, r9_binning_.xmin, r9_binning_.xmax);
0256     setMETitle(subphotonr9ME_, "subPhoton r9", "events");
0257 
0258     histname = "subphoton_hoE";
0259     histtitle = "subPhoton hoverE";
0260     bookME(ibooker, subphotonHoverEME_, histname, histtitle, hoe_binning_.nbins, hoe_binning_.xmin, hoe_binning_.xmax);
0261     setMETitle(subphotonHoverEME_, "subPhoton hoE", "events");
0262 
0263     histname = "subphoton_etaphi";
0264     histtitle = "subPhoton eta-phi";
0265     bookME(ibooker,
0266            subphotonEtaPhiME_,
0267            histname,
0268            histtitle,
0269            eta_binning_.nbins,
0270            eta_binning_.xmin,
0271            eta_binning_.xmax,
0272            phi_binning_1.nbins,
0273            phi_binning_1.xmin,
0274            phi_binning_1.xmax);
0275     setMETitle(subphotonEtaPhiME_, "#eta", "#phi");
0276   }
0277 }
0278 
0279 void PhotonMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0280   // if valid HLT paths are required,
0281   // analyze event only if all paths are valid
0282   if (requireValidHLTPaths_ and (not hltPathsAreValid_)) {
0283     return;
0284   }
0285 
0286   // Filter out events if Trigger Filtering is requested
0287   if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup)) {
0288     return;
0289   }
0290 
0291   edm::Handle<reco::PFMETCollection> metHandle;
0292   iEvent.getByToken(metToken_, metHandle);
0293   reco::PFMET pfmet = metHandle->front();
0294   if (!metSelection_(pfmet))
0295     return;
0296 
0297   //float met = pfmet.pt();
0298   //  float phi = pfmet.phi();
0299 
0300   edm::Handle<reco::PFJetCollection> jetHandle;
0301   iEvent.getByToken(jetToken_, jetHandle);
0302   std::vector<reco::PFJet> jets;
0303   jets.clear();
0304   if (jetHandle->size() < njets_)
0305     return;
0306   for (auto const& j : *jetHandle) {
0307     if (jetSelection_(j))
0308       jets.push_back(j);
0309   }
0310   if (jets.size() < njets_)
0311     return;
0312 
0313   edm::Handle<reco::GsfElectronCollection> eleHandle;
0314   iEvent.getByToken(eleToken_, eleHandle);
0315   std::vector<reco::GsfElectron> electrons;
0316   if (eleHandle->size() < nelectrons_)
0317     return;
0318   for (auto const& e : *eleHandle) {
0319     if (eleSelection_(e))
0320       electrons.push_back(e);
0321   }
0322   if (electrons.size() < nelectrons_)
0323     return;
0324 
0325   edm::Handle<reco::PhotonCollection> photonHandle;
0326   iEvent.getByToken(photonToken_, photonHandle);
0327   std::vector<reco::Photon> photons;
0328   photons.clear();
0329 
0330   if (photonHandle->size() < nphotons_)
0331     return;
0332   for (auto const& p : *photonHandle) {
0333     if (photonSelection_(p))
0334       photons.push_back(p);
0335   }
0336   if (photons.size() < nphotons_)
0337     return;
0338 
0339   // filling histograms (denominator)
0340   int ls = iEvent.id().luminosityBlock();
0341   if (!(photons.empty()))
0342 
0343   {
0344     photonME_.denominator->Fill(photons[0].pt());
0345     photonME_variableBinning_.denominator->Fill(photons[0].pt());
0346     photonPhiME_.denominator->Fill(photons[0].phi());
0347     photonEtaME_.denominator->Fill(photons[0].eta());
0348     photonVsLS_.denominator->Fill(ls, photons[0].pt());
0349     photonEtaPhiME_.denominator->Fill(photons[0].eta(), photons[0].phi());
0350     photonr9ME_.denominator->Fill(photons[0].r9());
0351     photonHoverEME_.denominator->Fill(photons[0].hadTowOverEm());
0352   }
0353 
0354   if (nphotons_ > 1)
0355   //filling diphoton histograms
0356   {
0357     subphotonME_.denominator->Fill(photons[1].pt());
0358     subphotonEtaME_.denominator->Fill(photons[1].eta());
0359     subphotonPhiME_.denominator->Fill(photons[1].phi());
0360     subphotonEtaPhiME_.denominator->Fill(photons[1].eta(), photons[1].phi());
0361     subphotonr9ME_.denominator->Fill(photons[1].r9());
0362     subphotonHoverEME_.denominator->Fill(photons[1].hadTowOverEm());
0363     diphotonMassME_.denominator->Fill(
0364         sqrt(2 * photons[0].pt() * photons[1].pt() *
0365              (cosh(photons[0].eta() - photons[1].eta()) - cos(photons[0].phi() - photons[1].phi()))));
0366   }
0367 
0368   // applying selection for numerator
0369   if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
0370     return;
0371 
0372   // filling histograms (num_genTriggerEventFlag_)
0373   if (!(photons.empty())) {
0374     photonME_.numerator->Fill(photons[0].pt());
0375     photonME_variableBinning_.numerator->Fill(photons[0].pt());
0376     photonPhiME_.numerator->Fill(photons[0].phi());
0377     photonEtaME_.numerator->Fill(photons[0].eta());
0378     photonVsLS_.numerator->Fill(ls, photons[0].pt());
0379     photonEtaPhiME_.numerator->Fill(photons[0].eta(), photons[0].phi());
0380     photonr9ME_.numerator->Fill(photons[0].r9());
0381     photonHoverEME_.numerator->Fill(photons[0].hadTowOverEm());
0382   }
0383   if (nphotons_ > 1)
0384   //filling diphoton histograms
0385   {
0386     subphotonME_.numerator->Fill(photons[1].pt());
0387     subphotonEtaME_.numerator->Fill(photons[1].eta());
0388     subphotonPhiME_.numerator->Fill(photons[1].phi());
0389     subphotonEtaPhiME_.numerator->Fill(photons[1].eta(), photons[1].phi());
0390     subphotonr9ME_.numerator->Fill(photons[1].r9());
0391     subphotonHoverEME_.numerator->Fill(photons[1].hadTowOverEm());
0392     diphotonMassME_.numerator->Fill(
0393         sqrt(2 * photons[0].pt() * photons[1].pt() *
0394              (cosh(photons[0].eta() - photons[1].eta()) - cos(photons[0].phi() - photons[1].phi()))));
0395   }
0396 }
0397 
0398 void PhotonMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0399   edm::ParameterSetDescription desc;
0400   desc.add<std::string>("FolderName", "HLT/Photon");
0401   desc.add<bool>("requireValidHLTPaths", true);
0402 
0403   desc.add<edm::InputTag>("met", edm::InputTag("pfMet"));
0404   desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
0405   desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
0406   desc.add<edm::InputTag>("photons", edm::InputTag("gedPhotons"));
0407   desc.add<std::string>("metSelection", "pt > 0");
0408   desc.add<std::string>("jetSelection", "pt > 0");
0409   desc.add<std::string>("eleSelection", "pt > 0");
0410   desc.add<std::string>(
0411       "photonSelection",
0412       "pt > 145 && eta<1.4442 && hadTowOverEm<0.0597 && full5x5_sigmaIetaIeta()<0.01031 && chargedHadronIso<1.295");
0413   //desc.add<std::string>("photonSelection", "pt > 145");
0414   desc.add<unsigned int>("njets", 0);
0415   desc.add<unsigned int>("nelectrons", 0);
0416   desc.add<unsigned int>("nphotons", 0);
0417 
0418   edm::ParameterSetDescription genericTriggerEventPSet;
0419   GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
0420   desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
0421   desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
0422 
0423   edm::ParameterSetDescription histoPSet;
0424   edm::ParameterSetDescription metPSet;
0425   fillHistoPSetDescription(metPSet);
0426   histoPSet.add<edm::ParameterSetDescription>("photonPSet", metPSet);
0427   std::vector<double> bins = {0.,   20.,  40.,  60.,  80.,  90.,  100., 110., 120., 130., 140., 150., 160.,
0428                               170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};
0429   histoPSet.add<std::vector<double> >("photonBinning", bins);
0430   std::vector<double> massbins = {90.,  91.,  92.,  93.,  94.,  95.,  96.,  97.,  98.,  99.,  100., 101., 102.,
0431                                   103., 104., 105., 106., 107., 108., 109., 110., 115., 120., 130., 150., 200.};
0432   histoPSet.add<std::vector<double> >("massBinning", massbins);
0433   edm::ParameterSetDescription lsPSet;
0434   fillHistoLSPSetDescription(lsPSet);
0435   histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
0436 
0437   desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
0438 
0439   descriptions.add("photonMonitoring", desc);
0440 }
0441 
0442 DEFINE_FWK_MODULE(PhotonMonitor);