Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-11 04:32:54

0001 #include <string>
0002 #include <vector>
0003 
0004 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0005 #include "DQMOffline/Trigger/plugins/TriggerDQMBase.h"
0006 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0007 #include "DQMServices/Core/interface/DQMStore.h"
0008 #include "DataFormats/Common/interface/TriggerResults.h"
0009 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0010 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0011 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0012 #include "DataFormats/JetReco/interface/PFJet.h"
0013 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0014 #include "DataFormats/Math/interface/deltaR.h"
0015 #include "FWCore/Common/interface/TriggerNames.h"
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0020 #include "FWCore/Utilities/interface/EDGetToken.h"
0021 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0022 #include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"
0023 
0024 #include "TLorentzVector.h"
0025 #include <cassert>
0026 #include "TPRegexp.h"
0027 
0028 class ZGammaplusJetsMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
0029 public:
0030   typedef dqm::reco::MonitorElement MonitorElement;
0031   typedef dqm::reco::DQMStore DQMStore;
0032 
0033   ZGammaplusJetsMonitor(const edm::ParameterSet&);
0034   ~ZGammaplusJetsMonitor() throw() override;
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 protected:
0039   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0040   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0041   void dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0042 
0043   bool islowRefPt(double RefPt);
0044   bool ismediumRefPt(double RefPt);
0045   bool ishighRefPt(double RefPt);
0046 
0047   bool isBarrel(double eta);
0048   bool isEndCapInner(double eta);
0049   bool isEndCapOuter(double eta);
0050   bool isForward(double eta);
0051 
0052   bool isMatched(double hltJetEta, double hltJetPhi, double OffJetEta, double OffJetPhi);
0053 
0054   void bookMESub(DQMStore::IBooker&,
0055                  ObjME* a_me,
0056                  const int len_,
0057                  const std::string& h_Name,
0058                  const std::string& h_Title,
0059                  const std::string& h_subOptName,
0060                  const std::string& h_subOptTitle,
0061                  const bool doDirectBalancevsReferencePt = true,
0062                  const bool bookDen = false);
0063 
0064   void fillME(ObjME* a_me,
0065               const double directbalance_,
0066               const double Difjetref_,
0067               const double Assymetry_,
0068               const double ReferencePt_,
0069               const double Jetpt_,
0070               const bool doDirectBalancevsReferencePt = true);
0071 
0072 private:
0073   const std::string folderName_;
0074 
0075   const std::string processName_;  // process name of (HLT) process for which to get HLT configuration
0076   // The instance of the HLTConfigProvider as a data member
0077   HLTConfigProvider hltConfig_;
0078 
0079   const edm::EDGetTokenT<trigger::TriggerEvent> triggerEventObject_;
0080   const edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
0081   const std::string pathName;
0082   const std::string moduleName;
0083   const edm::InputTag jetInputTag_;
0084   const edm::EDGetTokenT<reco::PFJetCollection> jetToken_;
0085   const edm::EDGetTokenT<reco::JetCorrector> correctorToken_;
0086 
0087   double muon_pt;
0088   double muon_eta;
0089   double pt_cut;
0090   double Z_DM;
0091   double Z_Pt;
0092   double dphi_cut;
0093   double offline_cut;
0094   bool isMuonPath_;
0095 
0096   std::vector<double> directbalance_Binning;
0097   std::vector<double> TrObjPt_Binning;
0098   std::vector<double> jetpt_Binning;
0099   MEbinning DifJetRefPT_Binning{50, -75.0, 75.0};
0100 
0101   //# of variables: 1. direct balance, 2. difference, 3. asymmetry, 4. hltobjectPt, 5. hltJetPt, 6. directbalanceVShltobjectPt
0102   ObjME a_ME[6];
0103   ObjME a_ME_HB[6];
0104   ObjME a_ME_HE_I[6];
0105   ObjME a_ME_HE_O[6];
0106   ObjME a_ME_HF[6];
0107   ObjME a_ME_HB_lowRefPt[6];
0108   ObjME a_ME_HE_I_lowRefPt[6];
0109   ObjME a_ME_HE_O_lowRefPt[6];
0110   ObjME a_ME_HF_lowRefPt[6];
0111   ObjME a_ME_HB_mediumRefPt[6];
0112   ObjME a_ME_HE_I_mediumRefPt[6];
0113   ObjME a_ME_HE_O_mediumRefPt[6];
0114   ObjME a_ME_HF_mediumRefPt[6];
0115   ObjME a_ME_HB_highRefPt[6];
0116   ObjME a_ME_HE_I_highRefPt[6];
0117   ObjME a_ME_HE_O_highRefPt[6];
0118   ObjME a_ME_HF_highRefPt[6];
0119 
0120   ObjME mZMassME_;
0121   ObjME DPhiRefJetME_;
0122 
0123   std::vector<double> v_jetpt;
0124   std::vector<double> v_jeteta;
0125   std::vector<double> v_jetphi;
0126 
0127   std::vector<double> trigobj_pt;
0128   std::vector<double> trigobj_eta;
0129   std::vector<double> trigobj_phi;
0130 
0131   TLorentzVector muon_1;
0132   TLorentzVector muon_2;
0133   TLorentzVector Zhltreco;
0134   std::string fullpathName;
0135 };
0136 
0137 ZGammaplusJetsMonitor::ZGammaplusJetsMonitor(const edm::ParameterSet& iConfig)
0138     : folderName_(iConfig.getParameter<std::string>("FolderName")),
0139       processName_(iConfig.getParameter<std::string>("processName")),
0140       triggerEventObject_(consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("triggerEventObject"))),
0141       triggerResultsToken_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("TriggerResultsLabel"))),
0142       pathName(iConfig.getParameter<std::string>("PathName")),
0143       moduleName(iConfig.getParameter<std::string>("ModuleName")),
0144       jetInputTag_(iConfig.getParameter<edm::InputTag>("jets")),
0145       jetToken_(mayConsume<reco::PFJetCollection>(jetInputTag_)),
0146       correctorToken_(mayConsume<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("corrector"))),
0147       muon_pt(iConfig.getParameter<double>("muonpt")),
0148       muon_eta(iConfig.getParameter<double>("muoneta")),
0149       pt_cut(iConfig.getParameter<double>("ptcut")),
0150       Z_DM(iConfig.getParameter<double>("Z_Dmass")),
0151       Z_Pt(iConfig.getParameter<double>("Z_pt")),
0152       dphi_cut(iConfig.getParameter<double>("DeltaPhi")),
0153       offline_cut(iConfig.getParameter<double>("OfflineCut")),
0154       isMuonPath_(iConfig.getParameter<bool>("isMuonPath")),
0155       directbalance_Binning(iConfig.getParameter<edm::ParameterSet>("histoPSet")
0156                                 .getParameter<std::vector<double> >("directbalanceBinning")),
0157       TrObjPt_Binning(
0158           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("TrObjPtBinning")),
0159       jetpt_Binning(
0160           iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("jetptBinning")) {}
0161 
0162 ZGammaplusJetsMonitor::~ZGammaplusJetsMonitor() throw() {}
0163 
0164 void ZGammaplusJetsMonitor::bookHistograms(DQMStore::IBooker& ibooker,
0165                                            edm::Run const& iRun,
0166                                            edm::EventSetup const& iSetup) {
0167   std::string histname, histtitle;
0168   std::string hist_obtag = "";
0169   std::string histtitle_obtag = "";
0170   std::string currentFolder = folderName_;
0171   ibooker.setCurrentFolder(currentFolder);
0172 
0173   if (isMuonPath_) {
0174     hist_obtag = "Z";
0175     histtitle_obtag = "Z ";
0176     histname = "DiMuonMass";
0177     histtitle = "DiMuonMass";
0178     bookME(ibooker, mZMassME_, histname, histtitle, 50, 71., 111., false);
0179   } else {
0180     hist_obtag = "Photon";
0181     histtitle_obtag = "Photon";
0182   }
0183 
0184   histname = "DPhi" + hist_obtag + "Jet";
0185   histtitle = "DPhi " + hist_obtag + " Jet";
0186   bookME(ibooker, DPhiRefJetME_, histname, histtitle, 100, 0., acos(-1.), false);
0187 
0188   bookMESub(ibooker, a_ME, sizeof(a_ME) / sizeof(a_ME[0]), hist_obtag, histtitle_obtag, "", "");
0189   bookMESub(ibooker, a_ME_HB, sizeof(a_ME_HB) / sizeof(a_ME_HB[0]), hist_obtag, histtitle_obtag, "HB", "(HB)", true);
0190   bookMESub(ibooker,
0191             a_ME_HE_I,
0192             sizeof(a_ME_HE_I) / sizeof(a_ME_HE_I[0]),
0193             hist_obtag,
0194             histtitle_obtag,
0195             "HEInner",
0196             "(HE Inner)",
0197             true);
0198   bookMESub(ibooker,
0199             a_ME_HE_O,
0200             sizeof(a_ME_HE_O) / sizeof(a_ME_HE_O[0]),
0201             hist_obtag,
0202             histtitle_obtag,
0203             "HEOuter",
0204             "(HE Outer)",
0205             true);
0206   bookMESub(ibooker, a_ME_HF, sizeof(a_ME_HF) / sizeof(a_ME_HF[0]), hist_obtag, histtitle_obtag, "HF", "(HF)", true);
0207   bookMESub(ibooker,
0208             a_ME_HB_lowRefPt,
0209             sizeof(a_ME_HB_lowRefPt) / sizeof(a_ME_HB_lowRefPt[0]),
0210             hist_obtag,
0211             histtitle_obtag,
0212             "HB_lowRefPt",
0213             "(HB) lowRefPt",
0214             true);
0215   bookMESub(ibooker,
0216             a_ME_HE_I_lowRefPt,
0217             sizeof(a_ME_HE_I_lowRefPt) / sizeof(a_ME_HE_I_lowRefPt[0]),
0218             hist_obtag,
0219             histtitle_obtag,
0220             "HEInner_lowRefPt",
0221             "(HE Inner) lowRefPt",
0222             true);
0223   bookMESub(ibooker,
0224             a_ME_HE_O_lowRefPt,
0225             sizeof(a_ME_HE_O_lowRefPt) / sizeof(a_ME_HE_O_lowRefPt[0]),
0226             hist_obtag,
0227             histtitle_obtag,
0228             "HEOuter_lowRefPt",
0229             "(HE Outer) lowRefPt",
0230             true);
0231   bookMESub(ibooker,
0232             a_ME_HF_lowRefPt,
0233             sizeof(a_ME_HF_lowRefPt) / sizeof(a_ME_HF_lowRefPt[0]),
0234             hist_obtag,
0235             histtitle_obtag,
0236             "HF_lowRefPt",
0237             "(HF) lowRefPt",
0238             true);
0239   bookMESub(ibooker,
0240             a_ME_HB_mediumRefPt,
0241             sizeof(a_ME_HB_mediumRefPt) / sizeof(a_ME_HB_mediumRefPt[0]),
0242             hist_obtag,
0243             histtitle_obtag,
0244             "HB_mediumRefPt",
0245             "(HB) mediumRefPt",
0246             true);
0247   bookMESub(ibooker,
0248             a_ME_HE_I_mediumRefPt,
0249             sizeof(a_ME_HE_I_mediumRefPt) / sizeof(a_ME_HE_I_mediumRefPt[0]),
0250             hist_obtag,
0251             histtitle_obtag,
0252             "HEInner_mediumRefPt",
0253             "(HE Inner) mediumRefPt",
0254             true);
0255   bookMESub(ibooker,
0256             a_ME_HE_O_mediumRefPt,
0257             sizeof(a_ME_HE_O_mediumRefPt) / sizeof(a_ME_HE_O_mediumRefPt[0]),
0258             hist_obtag,
0259             histtitle_obtag,
0260             "HEOuter_mediumRefPt",
0261             "(HE Outer) mediumRefPt",
0262             true);
0263   bookMESub(ibooker,
0264             a_ME_HF_mediumRefPt,
0265             sizeof(a_ME_HF_mediumRefPt) / sizeof(a_ME_HF_mediumRefPt[0]),
0266             hist_obtag,
0267             histtitle_obtag,
0268             "HF_mediumRefPt",
0269             "(HF) mediumRefPt",
0270             true);
0271   bookMESub(ibooker,
0272             a_ME_HB_highRefPt,
0273             sizeof(a_ME_HB_highRefPt) / sizeof(a_ME_HB_highRefPt[0]),
0274             hist_obtag,
0275             histtitle_obtag,
0276             "HB_highRefPt",
0277             "(HB) highRefPt",
0278             true);
0279   bookMESub(ibooker,
0280             a_ME_HE_I_highRefPt,
0281             sizeof(a_ME_HE_I_highRefPt) / sizeof(a_ME_HE_I_highRefPt[0]),
0282             hist_obtag,
0283             histtitle_obtag,
0284             "HEInner_highRefPt",
0285             "(HE Inner) highRefPt",
0286             true);
0287   bookMESub(ibooker,
0288             a_ME_HE_O_highRefPt,
0289             sizeof(a_ME_HE_O_highRefPt) / sizeof(a_ME_HE_O_highRefPt[0]),
0290             hist_obtag,
0291             histtitle_obtag,
0292             "HEOuter_highRefPt",
0293             "(HE Outer) highRefPt",
0294             true);
0295   bookMESub(ibooker,
0296             a_ME_HF_highRefPt,
0297             sizeof(a_ME_HF_highRefPt) / sizeof(a_ME_HF_highRefPt[0]),
0298             hist_obtag,
0299             histtitle_obtag,
0300             "HF_highRefPt",
0301             "(HF) highRefPt",
0302             true);
0303 }
0304 
0305 void ZGammaplusJetsMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0306   v_jetpt.clear();
0307   v_jeteta.clear();
0308   v_jetphi.clear();
0309 
0310   trigobj_pt.clear();
0311   trigobj_eta.clear();
0312   trigobj_phi.clear();
0313 
0314   // ------------------ Get TriggerResults -----------------
0315   edm::Handle<edm::TriggerResults> triggerResults;
0316   iEvent.getByToken(triggerResultsToken_, triggerResults);
0317   if (!triggerResults.isValid())
0318     return;
0319 
0320   edm::Handle<trigger::TriggerEvent> aodTriggerEvent;
0321   iEvent.getByToken(triggerEventObject_, aodTriggerEvent);
0322   if (!aodTriggerEvent.isValid())
0323     return;
0324 
0325   edm::TriggerNames triggerNames_ = iEvent.triggerNames(*triggerResults);  // all trigger names available
0326 
0327   bool passTrig = false;
0328 
0329   unsigned hltcfgIndex = hltConfig_.triggerIndex(fullpathName);
0330   unsigned index = triggerNames_.triggerIndex(fullpathName);  // find in which index is that path
0331   if (!(hltcfgIndex == index)) {
0332     edm::LogInfo("ZGammaplusJetsMonitor") << " Error in trigger index";
0333     return;
0334   }
0335 
0336   if (index > 0 && index < triggerNames_.size() &&
0337       triggerResults->accept(index)) {  //trigger is accepted and index is valid
0338     edm::LogInfo("ZGammaplusJetsMonitor") << " Trigger accepted";
0339     passTrig = true;
0340   }
0341   if (!passTrig) {
0342     edm::LogInfo("ZGammaplusJetsMonitor") << " Trigger did not pass";  // skip event if trigger fails
0343     return;
0344   }
0345 
0346   // ---------------- find module for this path ------------------------
0347   const unsigned int module_size = hltConfig_.size(index);
0348   std::vector<std::string> module_names = hltConfig_.moduleLabels(index);  // (pathname) works too
0349   if (!(module_size == module_names.size())) {
0350     edm::LogInfo("ZGammaplusJetsMonitor") << "ERROR IN MODULES COUNTING";
0351     return;
0352   }
0353   if (module_size == 0) {
0354     edm::LogInfo("ZGammaplusJetsMonitor") << "no modules in this path ?!?!";
0355     return;
0356   }
0357 
0358   // Find the module
0359   edm::InputTag moduleFilter;
0360   moduleFilter = edm::InputTag(moduleName, "", processName_);
0361   edm::LogInfo("ZGammaplusJetsMonitor") << " ModuleFilter " << moduleFilter;
0362 
0363   // check whether the module is packed up in TriggerEvent product
0364   trigger::size_type filterIndex_ = aodTriggerEvent->filterIndex(moduleFilter);
0365   edm::LogInfo("ZGammaplusJetsMonitor") << " filter index " << filterIndex_ << " | filter size  "
0366                                         << aodTriggerEvent->sizeFilters();
0367   if (filterIndex_ >= aodTriggerEvent->sizeFilters()) {
0368     return;
0369   }
0370 
0371   edm::LogInfo("ZGammaplusJetsMonitor") << " filter label|filter index" << moduleName << "|" << filterIndex_;
0372 
0373   const trigger::Vids& VIDS_ = aodTriggerEvent->filterIds(filterIndex_);
0374   const trigger::Keys& KEYS_ = aodTriggerEvent->filterKeys(filterIndex_);
0375   const trigger::size_type nI_ = VIDS_.size();
0376   const trigger::size_type nK_ = KEYS_.size();
0377   assert(nI_ == nK_);
0378   const trigger::TriggerObjectCollection& TOC(aodTriggerEvent->getObjects());
0379   for (trigger::size_type idx = 0; idx < nI_; ++idx) {
0380     const trigger::TriggerObject& TO(TOC[KEYS_[idx]]);
0381     //VIDS :  muons-->83 / jets-->85  / met-->87 / photon-->81
0382     edm::LogInfo("ZGammaplusJetsMonitor") << " idx:  " << idx << "| vid  " << VIDS_[idx] << "|"
0383                                           << " keys  " << KEYS_[idx] << "triggerobject: "
0384                                           << " obj_id " << TO.id() << " Pt " << TO.pt() << " eta " << TO.eta()
0385                                           << " phi " << TO.phi() << " mass " << TO.mass();
0386   }
0387   if (VIDS_[0] == 81) {  //photon
0388     for (const auto& key : KEYS_) {
0389       trigobj_pt.push_back(TOC[key].pt());
0390       trigobj_eta.push_back(TOC[key].eta());
0391       trigobj_phi.push_back(TOC[key].phi());
0392     }
0393   }
0394   if (VIDS_[0] == 83 && nK_ < 2) {  //muon
0395     edm::LogInfo("ZGammaplusJetsMonitor") << " under 2 objects cant have a dimuon";
0396     return;
0397   } else {
0398     for (const auto& key : KEYS_) {
0399       double pt = TOC[key].pt();
0400       double eta = TOC[key].eta();
0401       double phi = TOC[key].phi();
0402       double mass = TOC[key].mass();
0403       int id = TOC[key].id();
0404       unsigned int kCnt0 = 0;
0405 
0406       TLorentzVector v1;         //keep first muon
0407       if (std::abs(id) == 13) {  // check if it is a muon
0408         v1.SetPtEtaPhiM(pt, eta, phi, mass);
0409       } else {
0410         v1.SetPtEtaPhiM(0., 0., 0., 0.);
0411       }
0412       unsigned int kCnt1 = 0;
0413       for (const auto& key1 : KEYS_) {
0414         if (key != key1 && kCnt1 > kCnt0) {  // avoid double counting separate objs
0415 
0416           double pt2 = TOC[key1].pt();
0417           double eta2 = TOC[key1].eta();
0418           double phi2 = TOC[key1].phi();
0419           double mass2 = TOC[key1].mass();
0420           int id2 = TOC[key1].id();
0421 
0422           if ((id + id2) == 0) {  // check di-object system charge and flavor
0423 
0424             TLorentzVector v2;
0425             if (std::abs(id2) == 13) {  // check if it is a muon
0426               v2.SetPtEtaPhiM(pt2, eta2, phi2, mass2);
0427             } else {
0428               v2.SetPtEtaPhiM(0., 0., 0., 0.0);
0429             }
0430 
0431             muon_1 = v1;
0432             muon_2 = v2;
0433             bool muon_pass = muon_1.Pt() > muon_pt && muon_2.Pt() > muon_pt && std::abs(muon_1.Eta()) < muon_eta &&
0434                              std::abs(muon_2.Eta()) < muon_eta;
0435             if (!muon_pass) {
0436               return;
0437             }
0438 
0439             Zhltreco = muon_1 + muon_2;
0440             bool Z_pass = std::abs(Zhltreco.M() - 91.2) < Z_DM && Zhltreco.Pt() > Z_Pt;
0441             if (!Z_pass) {
0442               return;
0443             }
0444             trigobj_pt.push_back(Zhltreco.Pt());
0445             trigobj_eta.push_back(Zhltreco.Eta());
0446             trigobj_phi.push_back(Zhltreco.Phi());
0447           }  //end check di-object
0448           else {  //if not di-object
0449             return;
0450           }
0451         }  // end avoid duplicate objects
0452         kCnt1++;
0453       }  // key1
0454       kCnt0++;
0455     }  // key
0456   }  // end else
0457 
0458   // ---------------- module for Jet leg Jets --------------------------
0459   // index of last module executed in this Path
0460   const unsigned int moduleIndex = triggerResults->index(index);  // here would be HLTBool at the end
0461   edm::LogInfo("ZGammaplusJetsMonitor")
0462       << " Module Index " << moduleIndex - 1 << " Module Name  "
0463       << module_names[moduleIndex - 1];  // the second to last would be the last module that is saved
0464   assert(moduleIndex < module_size);
0465 
0466   // results from TriggerEvent product
0467   const std::string& ImoduleLabel = module_names[moduleIndex - 1];
0468   const std::string ImoduleType = hltConfig_.moduleType(ImoduleLabel);
0469   edm::LogInfo("ZGammaplusJetsMonitor") << ImoduleLabel << " |  " << ImoduleType;
0470   // check whether the module is packed up in TriggerEvent product
0471   const unsigned int filterIndex = aodTriggerEvent->filterIndex(edm::InputTag(ImoduleLabel, "", processName_));
0472   if (filterIndex >= aodTriggerEvent->sizeFilters()) {
0473     return;
0474   }
0475   const trigger::Vids& VIDS = aodTriggerEvent->filterIds(filterIndex);
0476   const trigger::Keys& KEYS = aodTriggerEvent->filterKeys(filterIndex);
0477   const trigger::size_type nI = VIDS.size();
0478   const trigger::size_type nK = KEYS.size();
0479   assert(nI == nK);
0480   const trigger::TriggerObjectCollection& objects(aodTriggerEvent->getObjects());
0481   for (trigger::size_type idx = 0; idx < nI; ++idx) {
0482     const trigger::TriggerObject& TO_(objects[KEYS[idx]]);
0483     //VIDS :  muons-->83 / jets-->85  / met-->87
0484     edm::LogInfo("ZGammaplusJetsMonitor")
0485         << " idx  " << idx << " vid  " << VIDS[idx] << "/"
0486         << " keys  " << KEYS[idx] << ": "
0487         << " obj_id " << TO_.id() << " " << TO_.pt() << " " << TO_.eta() << " " << TO_.phi() << " " << TO_.mass();
0488   }
0489   for (const auto& key : KEYS) {
0490     v_jetpt.push_back(objects[key].pt());
0491     v_jeteta.push_back(objects[key].eta());
0492     v_jetphi.push_back(objects[key].phi());
0493   }
0494   bool Jet_pass = (!v_jetpt.empty() && v_jetpt[0] >= pt_cut);
0495   if (!Jet_pass) {
0496     return;
0497   }
0498   double dphi = std::abs(v_jetphi[0] - trigobj_phi[0]);
0499   if (dphi > M_PI) {
0500     dphi = 2 * M_PI - dphi;
0501   }
0502   if (dphi < dphi_cut) {  // be sure is back to back
0503     return;
0504   }
0505   // --- offline Jets -----
0506   edm::Handle<reco::PFJetCollection> jetHandle;
0507   iEvent.getByToken(jetToken_, jetHandle);
0508   edm::Handle<reco::JetCorrector> Corrector;
0509   iEvent.getByToken(correctorToken_, Corrector);
0510   double leading_JetPt = -10.0;
0511   double leading_JetEta = -10.0;
0512   double leading_JetPhi = -10.0;
0513   int ind = 0;
0514 
0515   if (!jetHandle.isValid()) {
0516     edm::LogWarning("ZGammaplusJetsMonitor")
0517         << "skipping events because the collection " << jetInputTag_.label().c_str() << " is not available";
0518     return;
0519   }
0520   for (auto const& j : *jetHandle) {
0521     if (Corrector.isValid()) {
0522       double jec = Corrector->correction(j);
0523       double cor_jet = jec * j.pt();
0524       if (cor_jet > leading_JetPt) {
0525         leading_JetPt = cor_jet;
0526         leading_JetEta = j.eta();
0527         leading_JetPhi = j.phi();
0528       }
0529     } else if (!Corrector.isValid() && ind == 0) {
0530       leading_JetPt = j.pt();
0531       leading_JetEta = j.eta();
0532       leading_JetPhi = j.phi();
0533       ind += 1;
0534     }
0535   }
0536   if (leading_JetPt < offline_cut) {  // offline cuts
0537     return;
0538   }
0539 
0540   if (!(isMatched(v_jeteta[0], v_jetphi[0], leading_JetEta, leading_JetPhi))) {
0541     return;
0542   }
0543 
0544   double DirectBalance_ = v_jetpt[0] / trigobj_pt[0];
0545   double DifJ1PtTrObjPt_ = v_jetpt[0] - trigobj_pt[0];
0546   double asymmetry = (trigobj_pt[0] - v_jetpt[0]) / (trigobj_pt[0] + v_jetpt[0]);
0547 
0548   // ------------------------- Filling Histos -----------------------------------
0549   if (isMuonPath_) {
0550     mZMassME_.numerator->Fill(Zhltreco.M());
0551   }
0552   DPhiRefJetME_.numerator->Fill(dphi);
0553   fillME(a_ME, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0554   if (isBarrel(v_jeteta[0])) {
0555     fillME(a_ME_HB, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0556     if (islowRefPt(trigobj_pt[0])) {
0557       fillME(a_ME_HB_lowRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0558     } else if (ismediumRefPt(trigobj_pt[0])) {
0559       fillME(a_ME_HB_mediumRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0560     } else if (ishighRefPt(trigobj_pt[0])) {
0561       fillME(a_ME_HB_highRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0562     }
0563   }  // end is barrel
0564   if (isEndCapInner(v_jeteta[0])) {
0565     fillME(a_ME_HE_I, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0566     if (islowRefPt(trigobj_pt[0])) {
0567       fillME(a_ME_HE_I_lowRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0568     } else if (ismediumRefPt(trigobj_pt[0])) {
0569       fillME(a_ME_HE_I_mediumRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0570     } else if (ishighRefPt(trigobj_pt[0])) {
0571       fillME(a_ME_HE_I_highRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0572     }
0573   }  // end is endcap-inner
0574   if (isEndCapOuter(v_jeteta[0])) {
0575     fillME(a_ME_HE_O, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0576     if (islowRefPt(trigobj_pt[0])) {
0577       fillME(a_ME_HE_O_lowRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0578     } else if (ismediumRefPt(trigobj_pt[0])) {
0579       fillME(a_ME_HE_O_mediumRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0580     } else if (ishighRefPt(trigobj_pt[0])) {
0581       fillME(a_ME_HE_O_highRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0582     }
0583   }  // end is endcap-outer
0584   if (isForward(v_jeteta[0])) {
0585     fillME(a_ME_HF, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0586     if (islowRefPt(trigobj_pt[0])) {
0587       fillME(a_ME_HF_lowRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0588     } else if (ismediumRefPt(trigobj_pt[0])) {
0589       fillME(a_ME_HF_mediumRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0590     } else if (ishighRefPt(trigobj_pt[0])) {
0591       fillME(a_ME_HF_highRefPt, DirectBalance_, DifJ1PtTrObjPt_, asymmetry, trigobj_pt[0], v_jetpt[0], true);
0592     }
0593   }  // end is Forward
0594 }
0595 // ----- Reference'Pt categories: low[30,50), medium[50,100), high[100,inf) -----
0596 bool ZGammaplusJetsMonitor::islowRefPt(double refPt) {
0597   bool output = false;
0598   if (refPt >= 30. && refPt < 50.)
0599     output = true;
0600   return output;
0601 }
0602 
0603 bool ZGammaplusJetsMonitor::ismediumRefPt(double refPt) {
0604   bool output = false;
0605   if (refPt >= 50. && refPt < 100.)
0606     output = true;
0607   return output;
0608 }
0609 
0610 bool ZGammaplusJetsMonitor::ishighRefPt(double refPt) {
0611   bool output = false;
0612   if (refPt >= 100.)
0613     output = true;
0614   return output;
0615 }
0616 // --------- detector areas ---------------------------------------------------
0617 bool ZGammaplusJetsMonitor::isBarrel(double eta) {
0618   bool output = false;
0619   if (std::abs(eta) <= 1.3)
0620     output = true;
0621   return output;
0622 }
0623 
0624 bool ZGammaplusJetsMonitor::isEndCapInner(double eta) {
0625   bool output = false;
0626   if (std::abs(eta) <= 2.5 && std::abs(eta) > 1.3)
0627     output = true;
0628   return output;
0629 }
0630 
0631 bool ZGammaplusJetsMonitor::isEndCapOuter(double eta) {
0632   bool output = false;
0633   if (std::abs(eta) <= 3.0 && std::abs(eta) > 2.5)
0634     output = true;
0635   return output;
0636 }
0637 
0638 bool ZGammaplusJetsMonitor::isForward(double eta) {
0639   bool output = false;
0640   if (std::abs(eta) > 3.0)
0641     output = true;
0642   return output;
0643 }
0644 // --------- Matching ---------------------------------------------------------------
0645 bool ZGammaplusJetsMonitor::isMatched(double hltJetEta, double hltJetPhi, double OffJetEta, double OffJetPhi) {
0646   bool output = false;
0647   double DRMatched2 = 0.16;
0648   double dR2 = deltaR2(hltJetEta, hltJetPhi, OffJetEta, OffJetPhi);
0649   if (dR2 < DRMatched2)
0650     output = true;
0651   return output;
0652 }
0653 
0654 void ZGammaplusJetsMonitor::fillME(ObjME* a_me,
0655                                    const double directbalance_,
0656                                    const double Difjetref_,
0657                                    const double Asymmetry_,
0658                                    const double ReferencePt_,
0659                                    const double Jetpt_,
0660                                    const bool doDirectBalancevsReferencePt) {
0661   a_me[0].numerator->Fill(directbalance_);  // index 0 = DirectBalance
0662   a_me[1].numerator->Fill(Difjetref_);      // index 1 = Leading JetPt minus Reference Pt
0663   a_me[2].numerator->Fill(Asymmetry_);      // index 2 =  asymmetry
0664   a_me[3].numerator->Fill(ReferencePt_);    // index 3 = Reference Pt
0665   a_me[4].numerator->Fill(Jetpt_);          // index 4 = Jet Pt
0666   if (doDirectBalancevsReferencePt) {
0667     a_me[5].numerator->Fill(ReferencePt_, directbalance_);  // index 5 = Balance vs Reference' Pt
0668   }
0669 }
0670 
0671 void ZGammaplusJetsMonitor::bookMESub(DQMStore::IBooker& Ibooker,
0672                                       ObjME* a_me,
0673                                       const int len_,
0674                                       const std::string& h_Name,
0675                                       const std::string& h_Title,
0676                                       const std::string& h_subOptName,
0677                                       const std::string& hSubT,
0678                                       const bool doDirectBalancevsReferencePt,
0679                                       const bool bookDen) {
0680   std::string hName = h_Name;
0681   std::string hTitle = h_Title;
0682   const std::string hSubN = h_subOptName.empty() ? "" : "_" + h_subOptName;
0683 
0684   int nbin_DifJetRef = DifJetRefPT_Binning.nbins;
0685   double maxbin_DifJetRef = DifJetRefPT_Binning.xmax;
0686   double minbin_DifJetRef = DifJetRefPT_Binning.xmin;
0687 
0688   hName = "DirectBalance" + hSubN;
0689   hTitle = " DirectBalance " + hSubT;
0690   bookME(Ibooker, a_me[0], hName, hTitle, directbalance_Binning, bookDen);
0691   setMETitle(a_me[0], "HLTJetPt/" + h_Name + "Pt", "events");
0692 
0693   hName = "JetPt1_minus_" + h_Name + "Pt" + hSubN;
0694   hTitle = "LeadingJet Pt minus " + h_Name + " Pt " + hSubT;
0695   bookME(Ibooker, a_me[1], hName, hTitle, nbin_DifJetRef, minbin_DifJetRef, maxbin_DifJetRef, bookDen);
0696   setMETitle(a_me[1], "Pt dif [GeV]", "events");
0697 
0698   hName = h_Name + "JetAsymmetry" + hSubN;
0699   hTitle = h_Title + " Jet Asymmetry " + hSubT;
0700   bookME(Ibooker, a_me[2], hName, hTitle, directbalance_Binning, bookDen);
0701   setMETitle(a_me[2], hTitle, "events");
0702 
0703   hName = h_Name + "pT" + hSubN;
0704   hTitle = h_Title + " pT " + hSubT;
0705   bookME(Ibooker, a_me[3], hName, hTitle, TrObjPt_Binning, bookDen);
0706   setMETitle(a_me[3], h_Title + " pT [GeV]", "events / [GeV]");
0707 
0708   hName = "JetpT" + hSubN;
0709   hTitle = "Jet pT " + hSubN;
0710   bookME(Ibooker, a_me[4], hName, hTitle, jetpt_Binning, bookDen);
0711   setMETitle(a_me[4], hTitle + " [GeV]", "events / [GeV]");
0712 
0713   if (doDirectBalancevsReferencePt) {
0714     hName = "DirectBalanceVs" + h_Name + "Pt" + hSubN;
0715     hTitle = "Direct Balance vs " + h_Title + " Pt " + hSubT;
0716     bookME(Ibooker, a_me[5], hName, hTitle, TrObjPt_Binning, directbalance_Binning, bookDen);
0717     setMETitle(a_me[5], h_Title + " pt", "Direct Balance");
0718   }
0719 }
0720 
0721 void ZGammaplusJetsMonitor::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0722   TPRegexp pattern(pathName);
0723   // https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideHighLevelTrigger#Access_to_the_HLT_configuration
0724   // "init" return value indicates whether intitialisation has succeeded
0725   // "changed" parameter indicates whether the config has actually changed
0726   bool changed(true);
0727   if (hltConfig_.init(iRun, iSetup, processName_, changed)) {
0728     // if init returns TRUE, initialisation has succeeded!
0729     if (changed) {
0730       // The HLT config has actually changed wrt the previous Run, hence rebook your
0731       // histograms or do anything else dependent on the revised HLT config
0732       std::vector<std::string> triggerPaths = hltConfig_.triggerNames();
0733       for (const auto& PATHNAME : triggerPaths) {
0734         edm::LogInfo("ZGammaplusJetsMonitor::dqmBeginRun ") << PATHNAME;
0735         if (TString(PATHNAME).Contains(pattern)) {
0736           fullpathName = PATHNAME;
0737         }
0738       }
0739     }
0740   } else {
0741     // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
0742     // with the file and/or code and needs to be investigated!
0743     edm::LogError("ZGammaplusJetsMonitor") << " HLT config extraction failure with process name " << processName_;
0744     // In this case, all access methods will return empty values!
0745   }
0746 }
0747 
0748 void ZGammaplusJetsMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0749   edm::ParameterSetDescription desc;
0750   desc.add<std::string>("FolderName", "HLT/JME/ZGammaPlusJets");
0751   desc.add<std::string>("processName", "HLT");
0752   desc.add<edm::InputTag>("triggerEventObject", edm::InputTag("hltTriggerSummaryAOD::HLT"));
0753   desc.add<edm::InputTag>("TriggerResultsLabel", edm::InputTag("TriggerResults::HLT"));
0754   desc.add<std::string>("PathName", "");
0755   desc.add<std::string>("ModuleName", "");
0756   desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsPuppi"));
0757   desc.add<edm::InputTag>("corrector", edm::InputTag("ak4PFPuppiL1FastL2L3Corrector"));
0758 
0759   desc.add<double>("muonpt", 20.);
0760   desc.add<double>("muoneta", 2.3);
0761   desc.add<double>("ptcut", 30.);
0762   desc.add<double>("Z_Dmass", 20.);
0763   desc.add<double>("Z_pt", 30.);
0764   desc.add<double>("DeltaPhi", 2.7);
0765   desc.add<double>("OfflineCut", 20.0);
0766   desc.add<bool>("isMuonPath", true);
0767 
0768   edm::ParameterSetDescription histoPSet;
0769 
0770   std::vector<double> bins = {
0771       -3.99, -3.97, -3.95, -3.93, -3.91, -3.89, -3.87, -3.85, -3.83, -3.81, -3.79, -3.77, -3.75, -3.73, -3.71, -3.69,
0772       -3.67, -3.65, -3.63, -3.61, -3.59, -3.57, -3.55, -3.53, -3.51, -3.49, -3.47, -3.45, -3.43, -3.41, -3.39, -3.37,
0773       -3.35, -3.33, -3.31, -3.29, -3.27, -3.25, -3.23, -3.21, -3.19, -3.17, -3.15, -3.13, -3.11, -3.09, -3.07, -3.05,
0774       -3.03, -3.01, -2.99, -2.97, -2.95, -2.93, -2.91, -2.89, -2.87, -2.85, -2.83, -2.81, -2.79, -2.77, -2.75, -2.73,
0775       -2.71, -2.69, -2.67, -2.65, -2.63, -2.61, -2.59, -2.57, -2.55, -2.53, -2.51, -2.49, -2.47, -2.45, -2.43, -2.41,
0776       -2.39, -2.37, -2.35, -2.33, -2.31, -2.29, -2.27, -2.25, -2.23, -2.21, -2.19, -2.17, -2.15, -2.13, -2.11, -2.09,
0777       -2.07, -2.05, -2.03, -2.01, -1.99, -1.97, -1.95, -1.93, -1.91, -1.89, -1.87, -1.85, -1.83, -1.81, -1.79, -1.77,
0778       -1.75, -1.73, -1.71, -1.69, -1.67, -1.65, -1.63, -1.61, -1.59, -1.57, -1.55, -1.53, -1.51, -1.49, -1.47, -1.45,
0779       -1.43, -1.41, -1.39, -1.37, -1.35, -1.33, -1.31, -1.29, -1.27, -1.25, -1.23, -1.21, -1.19, -1.17, -1.15, -1.13,
0780       -1.11, -1.09, -1.07, -1.05, -1.03, -1.01, -0.99, -0.97, -0.95, -0.93, -0.91, -0.89, -0.87, -0.85, -0.83, -0.81,
0781       -0.79, -0.77, -0.75, -0.73, -0.71, -0.69, -0.67, -0.65, -0.63, -0.61, -0.59, -0.57, -0.55, -0.53, -0.51, -0.49,
0782       -0.47, -0.45, -0.43, -0.41, -0.39, -0.37, -0.35, -0.33, -0.31, -0.29, -0.27, -0.25, -0.23, -0.21, -0.19, -0.17,
0783       -0.15, -0.13, -0.11, -0.09, -0.07, -0.05, -0.03, -0.01, 0.01,  0.03,  0.05,  0.07,  0.09,  0.11,  0.13,  0.15,
0784       0.17,  0.19,  0.21,  0.23,  0.25,  0.27,  0.29,  0.31,  0.33,  0.35,  0.37,  0.39,  0.41,  0.43,  0.45,  0.47,
0785       0.49,  0.51,  0.53,  0.55,  0.57,  0.59,  0.61,  0.63,  0.65,  0.67,  0.69,  0.71,  0.73,  0.75,  0.77,  0.79,
0786       0.81,  0.83,  0.85,  0.87,  0.89,  0.91,  0.93,  0.95,  0.97,  0.99,  1.01,  1.03,  1.05,  1.07,  1.09,  1.11,
0787       1.13,  1.15,  1.17,  1.19,  1.21,  1.23,  1.25,  1.27,  1.29,  1.31,  1.33,  1.35,  1.37,  1.39,  1.41,  1.43,
0788       1.45,  1.47,  1.49,  1.51,  1.53,  1.55,  1.57,  1.59,  1.61,  1.63,  1.65,  1.67,  1.69,  1.71,  1.73,  1.75,
0789       1.77,  1.79,  1.81,  1.83,  1.85,  1.87,  1.89,  1.91,  1.93,  1.95,  1.97,  1.99,  2.01,  2.03,  2.05,  2.07,
0790       2.09,  2.11,  2.13,  2.15,  2.17,  2.19,  2.21,  2.23,  2.25,  2.27,  2.29,  2.31,  2.33,  2.35,  2.37,  2.39,
0791       2.41,  2.43,  2.45,  2.47,  2.49,  2.51,  2.53,  2.55,  2.57,  2.59,  2.61,  2.63,  2.65,  2.67,  2.69,  2.71,
0792       2.73,  2.75,  2.77,  2.79,  2.81,  2.83,  2.85,  2.87,  2.89,  2.91,  2.93,  2.95,  2.97,  2.99,  3.01,  3.03,
0793       3.05,  3.07,  3.09,  3.11,  3.13,  3.15,  3.17,  3.19,  3.21,  3.23,  3.25,  3.27,  3.29,  3.31,  3.33,  3.35,
0794       3.37,  3.39,  3.41,  3.43,  3.45,  3.47,  3.49,  3.51,  3.53,  3.55,  3.57,  3.59,  3.61,  3.63,  3.65,  3.67,
0795       3.69,  3.71,  3.73,  3.75,  3.77,  3.79,  3.81,  3.83,  3.85,  3.87,  3.89,  3.91,  3.93,  3.95,  3.97,  3.99,
0796       4.01,  4.03,  4.05,  4.07,  4.09,  4.11,  4.13,  4.15,  4.17,  4.19,  4.21,  4.23,  4.25,  4.27,  4.29,  4.31,
0797       4.33,  4.35,  4.37,  4.39,  4.41,  4.43,  4.45,  4.47,  4.49,  4.51,  4.53,  4.55,  4.57,  4.59,  4.61,  4.63,
0798       4.65,  4.67,  4.69,  4.71,  4.73,  4.75,  4.77,  4.79,  4.81,  4.83,  4.85,  4.87,  4.89,  4.91,  4.93,  4.95,
0799       4.97,  4.99,  5.01,  5.03,  5.05,  5.07,  5.09,  5.11,  5.13,  5.15,  5.17,  5.19,  5.21,  5.23,  5.25,  5.27,
0800       5.29,  5.31,  5.33,  5.35,  5.37,  5.39,  5.41,  5.43,  5.45,  5.47,  5.49,  5.51,  5.53,  5.55,  5.57,  5.59,
0801       5.61,  5.63,  5.65,  5.67,  5.69,  5.71,  5.73,  5.75,  5.77,  5.79,  5.81,  5.83,  5.85,  5.87,  5.89,  5.91,
0802       5.93,  5.95,  5.97,  5.99};
0803 
0804   histoPSet.add<std::vector<double> >("directbalanceBinning", bins);
0805 
0806   std::vector<double> bins_ = {12, 15,  20,  25,  30,  35,  40,  45,  50,  60,   70,
0807                                85, 105, 130, 175, 230, 300, 400, 500, 700, 1000, 1500};  // Z or photon pT Binning
0808   histoPSet.add<std::vector<double> >("TrObjPtBinning", bins_);
0809   std::vector<double> Jbins_ = {
0810       0.,   20.,  40.,  60.,  80.,  90.,  100., 110., 120., 130., 140., 150., 160.,
0811       170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};  // Jet pT Binning
0812   histoPSet.add<std::vector<double> >("jetptBinning", Jbins_);
0813 
0814   desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
0815 
0816   descriptions.add("zgammajetsmonitoring", desc);
0817 }
0818 
0819 DEFINE_FWK_MODULE(ZGammaplusJetsMonitor);