Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:02

0001 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0002 #include "DataFormats/Math/interface/deltaPhi.h"
0003 #include "FWCore/Common/interface/TriggerNames.h"
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "HLTriggerOffline/SUSYBSM/interface/SUSY_HLT_DiJet_MET.h"
0008 
0009 SUSY_HLT_DiJet_MET::SUSY_HLT_DiJet_MET(const edm::ParameterSet &ps) {
0010   edm::LogInfo("SUSY_HLT_DiJet_MET") << "Constructor SUSY_HLT_DiJet_MET::SUSY_HLT_DiJet_MET " << std::endl;
0011   // Get parameters from configuration file
0012   theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
0013   thePfMETCollection_ = consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"));
0014   theCaloMETCollection_ = consumes<reco::CaloMETCollection>(ps.getParameter<edm::InputTag>("caloMETCollection"));
0015   thePfJetCollection_ = consumes<reco::PFJetCollection>(ps.getParameter<edm::InputTag>("pfJetCollection"));
0016   theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
0017   triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
0018   HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
0019   triggerPath_ = ps.getParameter<std::string>("TriggerPath");
0020   triggerPathAuxiliaryForHadronic_ = ps.getParameter<std::string>("TriggerPathAuxiliaryForHadronic");
0021   triggerFilter_ = ps.getParameter<edm::InputTag>("TriggerFilter");
0022   triggerJetFilter_ = ps.getParameter<edm::InputTag>("TriggerJetFilter");
0023   ptThrJetTrig_ = ps.getUntrackedParameter<double>("PtThrJetTrig");
0024   etaThrJetTrig_ = ps.getUntrackedParameter<double>("EtaThrJetTrig");
0025   ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
0026   etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
0027   metCut_ = ps.getUntrackedParameter<double>("OfflineMetCut");
0028 }
0029 
0030 SUSY_HLT_DiJet_MET::~SUSY_HLT_DiJet_MET() {
0031   edm::LogInfo("SUSY_HLT_DiJet_MET") << "Destructor SUSY_HLT_DiJet_MET::~SUSY_HLT_DiJet_MET " << std::endl;
0032 }
0033 
0034 void SUSY_HLT_DiJet_MET::dqmBeginRun(edm::Run const &run, edm::EventSetup const &e) {
0035   bool changed;
0036 
0037   if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
0038     edm::LogError("SUSY_HLT_DiJet_MET") << "Initialization of HLTConfigProvider failed!!";
0039     return;
0040   }
0041 
0042   bool pathFound = false;
0043   const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
0044   for (size_t j = 0; j < allTrigNames.size(); ++j) {
0045     if (allTrigNames[j].find(triggerPath_) != std::string::npos) {
0046       pathFound = true;
0047     }
0048   }
0049 
0050   if (!pathFound) {
0051     LogDebug("SUSY_HLT_DiJet_MET") << "Path not found"
0052                                    << "\n";
0053     return;
0054   }
0055 
0056   edm::LogInfo("SUSY_HLT_DiJet_MET") << "SUSY_HLT_DiJet_MET::beginRun" << std::endl;
0057 }
0058 
0059 void SUSY_HLT_DiJet_MET::bookHistograms(DQMStore::IBooker &ibooker_, edm::Run const &, edm::EventSetup const &) {
0060   edm::LogInfo("SUSY_HLT_DiJet_MET") << "SUSY_HLT_DiJet_MET::bookHistograms" << std::endl;
0061   // book at beginRun
0062   bookHistos(ibooker_);
0063 }
0064 
0065 void SUSY_HLT_DiJet_MET::analyze(edm::Event const &e, edm::EventSetup const &eSetup) {
0066   edm::LogInfo("SUSY_HLT_DiJet_MET") << "SUSY_HLT_DiJet_MET::analyze" << std::endl;
0067 
0068   //-------------------------------
0069   //--- MET
0070   //-------------------------------
0071   edm::Handle<reco::PFMETCollection> pfMETCollection;
0072   e.getByToken(thePfMETCollection_, pfMETCollection);
0073   if (!pfMETCollection.isValid()) {
0074     edm::LogError("SUSY_HLT_DiJet_MET") << "invalid collection: PFMET"
0075                                         << "\n";
0076     return;
0077   }
0078   edm::Handle<reco::CaloMETCollection> caloMETCollection;
0079   e.getByToken(theCaloMETCollection_, caloMETCollection);
0080   if (!caloMETCollection.isValid()) {
0081     edm::LogError("SUSY_HLT_DiJet_MET") << "invalid collection: CaloMET"
0082                                         << "\n";
0083     return;
0084   }
0085   //-------------------------------
0086   //--- Jets
0087   //-------------------------------
0088   edm::Handle<reco::PFJetCollection> pfJetCollection;
0089   e.getByToken(thePfJetCollection_, pfJetCollection);
0090   if (!pfJetCollection.isValid()) {
0091     edm::LogError("SUSY_HLT_DiJet_MET") << "invalid collection: PFJets"
0092                                         << "\n";
0093     return;
0094   }
0095   edm::Handle<reco::CaloJetCollection> caloJetCollection;
0096   e.getByToken(theCaloJetCollection_, caloJetCollection);
0097   if (!caloJetCollection.isValid()) {
0098     edm::LogError("SUSY_HLT_DiJet_MET") << "invalid collection: CaloJets"
0099                                         << "\n";
0100     return;
0101   }
0102 
0103   //-------------------------------
0104   //--- Trigger
0105   //-------------------------------
0106   edm::Handle<edm::TriggerResults> hltresults;
0107   e.getByToken(triggerResults_, hltresults);
0108   if (!hltresults.isValid()) {
0109     edm::LogError("SUSY_HLT_DiJet_MET") << "invalid collection: TriggerResults"
0110                                         << "\n";
0111     return;
0112   }
0113   edm::Handle<trigger::TriggerEvent> triggerSummary;
0114   e.getByToken(theTrigSummary_, triggerSummary);
0115   if (!triggerSummary.isValid()) {
0116     edm::LogError("SUSY_HLT_DiJet_MET") << "invalid collection: TriggerSummary"
0117                                         << "\n";
0118     return;
0119   }
0120 
0121   // get online objects
0122 
0123   size_t filterIndex = triggerSummary->filterIndex(triggerFilter_);
0124   size_t jetFilterIndex = triggerSummary->filterIndex(triggerJetFilter_);
0125   trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0126 
0127   if (!(filterIndex >= triggerSummary->sizeFilters())) {
0128     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndex);
0129     for (size_t j = 0; j < keys.size(); ++j) {
0130       trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0131       h_triggerMet->Fill(foundObject.pt());
0132       h_triggerMetPhi->Fill(foundObject.phi());
0133     }
0134   }
0135 
0136   std::vector<float> ptJet, etaJet, phiJet;
0137   if (!(jetFilterIndex >= triggerSummary->sizeFilters())) {
0138     const trigger::Keys &keys_jetfilter = triggerSummary->filterKeys(jetFilterIndex);
0139     for (size_t j = 0; j < keys_jetfilter.size(); ++j) {
0140       trigger::TriggerObject foundObject = triggerObjects[keys_jetfilter[j]];
0141       h_triggerJetPt->Fill(foundObject.pt());
0142       h_triggerJetEta->Fill(foundObject.eta());
0143       h_triggerJetPhi->Fill(foundObject.phi());
0144       if (foundObject.pt() > ptThrJetTrig_ && fabs(foundObject.eta()) < etaThrJetTrig_) {
0145         ptJet.push_back(foundObject.pt());
0146         etaJet.push_back(foundObject.eta());
0147         phiJet.push_back(foundObject.phi());
0148       }
0149     }
0150   }
0151 
0152   bool hasFired = false;
0153   bool hasFiredAuxiliaryForHadronicLeg = false;
0154   const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
0155   unsigned int numTriggers = trigNames.size();
0156   for (unsigned int hltIndex = 0; hltIndex < numTriggers; ++hltIndex) {
0157     if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) &&
0158         hltresults->accept(hltIndex))
0159       hasFired = true;
0160     if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForHadronic_) != std::string::npos &&
0161         hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0162       hasFiredAuxiliaryForHadronicLeg = true;
0163   }
0164 
0165   if (hasFiredAuxiliaryForHadronicLeg) {
0166     int offlineJetCounter = 0;
0167     int offlineCentralJets = 0;
0168     int nMatch = 0, jet1Index = -1, jet2Index = -1;
0169 
0170     for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end();
0171          ++i_pfjet) {
0172       if (i_pfjet->pt() > ptThrJet_ && fabs(i_pfjet->eta()) < etaThrJet_) {
0173         offlineCentralJets++;
0174         if (offlineCentralJets == 2 && pfMETCollection->begin()->et() > metCut_)
0175           h_pfJet2PtTurnOn_den->Fill(i_pfjet->pt());
0176 
0177         for (unsigned int itrigjet = 0; itrigjet < ptJet.size(); ++itrigjet) {
0178           if (itrigjet < 2 &&
0179               (sqrt((i_pfjet->phi() - phiJet.at(itrigjet)) * (i_pfjet->phi() - phiJet.at(itrigjet)) +
0180                     (i_pfjet->eta() - etaJet.at(itrigjet)) * (i_pfjet->eta() - etaJet.at(itrigjet))) < 0.4)) {
0181             nMatch++;
0182             if (nMatch == 1)
0183               jet1Index = offlineJetCounter;
0184             if (nMatch == 2)
0185               jet2Index = offlineJetCounter;
0186 
0187             if (hasFired) {
0188               h_pfJetPt->Fill(i_pfjet->pt());
0189               h_pfJetEta->Fill(i_pfjet->eta());
0190               h_pfJetPhi->Fill(i_pfjet->phi());
0191               if (offlineCentralJets == 2 && pfMETCollection->begin()->et() > metCut_)
0192                 h_pfJet2PtTurnOn_num->Fill(i_pfjet->pt());
0193             }
0194 
0195             break;
0196           }
0197         }
0198       }
0199 
0200       offlineJetCounter++;
0201     }
0202 
0203     if (hasFired) {
0204       h_pfMetTurnOn_num->Fill(pfMETCollection->begin()->et());
0205       h_pfMetPhi->Fill(pfMETCollection->begin()->phi());
0206       h_caloMetvsPFMet->Fill(pfMETCollection->begin()->et(), caloMETCollection->begin()->et());
0207 
0208       if (jet1Index > -1 && jet2Index > -1) {
0209         h_pfJet1Jet2DPhi->Fill(
0210             fabs(reco::deltaPhi(pfJetCollection->at(jet1Index).phi(), pfJetCollection->at(jet2Index).phi())));
0211       }
0212     }
0213 
0214     h_pfMetTurnOn_den->Fill(pfMETCollection->begin()->et());
0215   }
0216 
0217   ptJet.clear();
0218   etaJet.clear();
0219   phiJet.clear();
0220 }
0221 
0222 void SUSY_HLT_DiJet_MET::bookHistos(DQMStore::IBooker &ibooker_) {
0223   ibooker_.cd();
0224   ibooker_.setCurrentFolder("HLT/SUSYBSM/" + triggerPath_);
0225 
0226   // offline quantities
0227   h_pfMetPhi = ibooker_.book1D("pfMetPhi", "PF MET Phi", 20, -3.5, 3.5);
0228   h_pfJetPt = ibooker_.book1D("pfJetPt", "PF Jet p_{T} (trigger-matched jets, |#eta| < 2.4); GeV", 20, 0.0, 500.0);
0229   h_pfJetEta = ibooker_.book1D("pfJetEta", "PF Jet #eta (trigger-matched jets, |#eta| < 2.4)", 20, -3.0, 3.0);
0230   h_pfJetPhi = ibooker_.book1D("pfJetPhi", "PF Jet #phi (trigger-matched jets, |#eta| < 2.4)", 20, -3.5, 3.5);
0231   h_pfJet1Jet2DPhi =
0232       ibooker_.book1D("pfJet1Jet2DPhi", "|#Delta#phi| between two leading trigger-matched jets", 20, 0.0, 3.5);
0233   h_caloMetvsPFMet = ibooker_.book2D("caloMetvsPFMet", "Calo MET vs PF MET; GeV; GeV", 25, 0.0, 500.0, 25, 0.0, 500.0);
0234 
0235   // online quantities
0236   h_triggerMet = ibooker_.book1D("triggerMet", "Trigger MET; GeV", 20, 0.0, 500.0);
0237   h_triggerMetPhi = ibooker_.book1D("triggerMetPhi", "Trigger MET Phi", 20, -3.5, 3.5);
0238   h_triggerJetPt = ibooker_.book1D("triggerJetPt", "Trigger Jet p_{T}; GeV", 20, 0.0, 500.0);
0239   h_triggerJetEta = ibooker_.book1D("triggerJetEta", "Trigger Jet Eta", 20, -3.0, 3.0);
0240   h_triggerJetPhi = ibooker_.book1D("triggerJetPhi", "Trigger Jet Phi", 20, -3.5, 3.5);
0241 
0242   // num and den hists to be divided in harvesting step to make turn on curves
0243   h_pfMetTurnOn_num = ibooker_.book1D("pfMetTurnOn_num", "PF MET", 20, 0.0, 500.0);
0244   h_pfMetTurnOn_den = ibooker_.book1D("pfMetTurnOn_den", "PF MET Turn On Denominator", 20, 0.0, 500.0);
0245   h_pfJet2PtTurnOn_num =
0246       ibooker_.book1D("pfJet2PtTurnOn_num", "PF Jet2 Pt (NCentralPFJets >= 2, PFMET > 250)", 20, 0.0, 500.0);
0247   h_pfJet2PtTurnOn_den = ibooker_.book1D("pfJet2PtTurnOn_den", "PF Jet2 Pt Turn On Denominator", 20, 0.0, 500.0);
0248 
0249   ibooker_.cd();
0250 }
0251 
0252 // define this as a plug-in
0253 DEFINE_FWK_MODULE(SUSY_HLT_DiJet_MET);