Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:49

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTriggerOffline/B2G
0004 // Class:      B2GSingleLeptonHLTValidation
0005 //
0006 /**\class B2GSingleLeptonHLTValidation B2GSingleLeptonHLTValidation.cc
0007 HLTriggerOffline/B2G/src/B2GSingleLeptonHLTValidation.cc
0008 
0009 Description:
0010 
0011 Description: compute efficiencies of trigger paths on offline reco selection
0012 with respect to pt and eta
0013 
0014 Implementation:
0015 harvesting
0016 */
0017 //
0018 // Original Author:  Elvire Bouvier
0019 //         Created:  Thu, 16 Jan 2014 16:27:35 GMT
0020 //
0021 //
0022 #include "HLTriggerOffline/B2G/interface/B2GSingleLeptonHLTValidation.h"
0023 
0024 // system include files
0025 #include <memory>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/ServiceRegistry/interface/Service.h"
0035 
0036 #include "DataFormats/MuonReco/interface/MuonPFIsolation.h"
0037 #include "FWCore/Common/interface/TriggerNames.h"
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0040 #include "TString.h"
0041 //
0042 // member functions
0043 //
0044 
0045 // ------------ method called for each event  ------------
0046 void B2GSingleLeptonHLTValidation::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0047   using namespace edm;
0048 
0049   isAll_ = false;
0050   isSel_ = false;
0051 
0052   // Electrons
0053   Handle<edm::View<reco::GsfElectron>> electrons;
0054   if (!iEvent.getByToken(tokElectrons_, electrons))
0055     edm::LogWarning("B2GSingleLeptonHLTValidation") << "Electrons collection not found \n";
0056   unsigned int nGoodE = 0;
0057   for (edm::View<reco::GsfElectron>::const_iterator e = electrons->begin(); e != electrons->end(); ++e) {
0058     if (e->pt() < ptElectrons_)
0059       continue;
0060     if (fabs(e->eta()) > etaElectrons_)
0061       continue;
0062     nGoodE++;
0063     if (nGoodE == 1)
0064       elec_ = electrons->ptrAt(e - electrons->begin());
0065   }
0066   // Muons
0067   Handle<edm::View<reco::Muon>> muons;
0068   if (!iEvent.getByToken(tokMuons_, muons))
0069     edm::LogWarning("B2GSingleLeptonHLTValidation") << "Muons collection not found \n";
0070   unsigned int nGoodM = 0;
0071   for (edm::View<reco::Muon>::const_iterator m = muons->begin(); m != muons->end(); ++m) {
0072     if (!m->isPFMuon() || !m->isGlobalMuon())
0073       continue;
0074     if (m->pt() < ptMuons_)
0075       continue;
0076     if (fabs(m->eta()) > etaMuons_)
0077       continue;
0078     nGoodM++;
0079     if (nGoodM == 1)
0080       mu_ = muons->ptrAt(m - muons->begin());
0081   }
0082   // Jets
0083   Handle<edm::View<reco::Jet>> jets;
0084   if (!iEvent.getByToken(tokJets_, jets))
0085     edm::LogWarning("B2GSingleLeptonHLTValidation") << "Jets collection not found \n";
0086   unsigned int nGoodJ = 0;
0087 
0088   // Check to see if we want asymmetric jet pt cuts
0089   if (ptJets0_ > 0.0 || ptJets1_ > 0.0) {
0090     if (ptJets0_ > 0.0) {
0091       if (!jets->empty() && jets->at(0).pt() > ptJets0_) {
0092         nGoodJ++;
0093         jet_ = jets->ptrAt(0);
0094       }
0095     }
0096     if (ptJets1_ > 0.0) {
0097       if (jets->size() > 1 && jets->at(1).pt() > ptJets1_) {
0098         nGoodJ++;
0099         jet_ = jets->ptrAt(1);
0100       }
0101     }
0102   } else {
0103     for (edm::View<reco::Jet>::const_iterator j = jets->begin(); j != jets->end(); ++j) {
0104       if (j->pt() < ptJets_)
0105         continue;
0106       if (fabs(j->eta()) > etaJets_)
0107         continue;
0108       nGoodJ++;
0109       if (nGoodJ == minJets_)
0110         jet_ = jets->ptrAt(j - jets->begin());
0111     }
0112   }
0113 
0114   if (nGoodE >= minElectrons_ && nGoodM >= minMuons_ && nGoodJ >= minJets_)
0115     isAll_ = true;
0116 
0117   // Trigger
0118   Handle<edm::TriggerResults> triggerTable;
0119   if (!iEvent.getByToken(tokTrigger_, triggerTable))
0120     edm::LogWarning("B2GSingleLeptonHLTValidation") << "Trigger collection not found \n";
0121   const edm::TriggerNames &triggerNames = iEvent.triggerNames(*triggerTable);
0122   bool isInteresting = false;
0123   for (unsigned int i = 0; i < triggerNames.triggerNames().size(); ++i) {
0124     TString name = triggerNames.triggerNames()[i].c_str();
0125     for (unsigned int j = 0; j < vsPaths_.size(); j++) {
0126       if (name.Contains(TString(vsPaths_[j]), TString::kIgnoreCase)) {
0127         isInteresting = true;
0128         break;
0129       }
0130     }
0131     if (isInteresting)
0132       break;
0133   }
0134 
0135   if (isAll_ && isInteresting)
0136     isSel_ = true;
0137   else
0138     isSel_ = false;
0139 
0140   // Histos
0141   if (isAll_) {
0142     if (minElectrons_ > 0 && elec_.isNonnull()) {
0143       hDenLeptonPt->Fill(elec_->pt());
0144       hDenLeptonEta->Fill(elec_->eta());
0145     }
0146     if (minMuons_ > 0 && mu_.isNonnull()) {
0147       hDenLeptonPt->Fill(mu_->pt());
0148       hDenLeptonEta->Fill(mu_->eta());
0149     }
0150     if (jet_.isNonnull()) {
0151       hDenJetPt->Fill(jet_->pt());
0152       hDenJetEta->Fill(jet_->eta());
0153     }
0154     for (unsigned int idx = 0; idx < vsPaths_.size(); ++idx) {
0155       hDenTriggerMon->Fill(idx + 0.5);
0156     }
0157   }
0158   if (isSel_) {
0159     if (minElectrons_ > 0 && elec_.isNonnull()) {
0160       hNumLeptonPt->Fill(elec_->pt());
0161       hNumLeptonEta->Fill(elec_->eta());
0162     }
0163     if (minMuons_ > 0 && mu_.isNonnull()) {
0164       hNumLeptonPt->Fill(mu_->pt());
0165       hNumLeptonEta->Fill(mu_->eta());
0166     }
0167     if (jet_.isNonnull()) {
0168       hNumJetPt->Fill(jet_->pt());
0169       hNumJetEta->Fill(jet_->eta());
0170     }
0171     for (unsigned int i = 0; i < triggerNames.triggerNames().size(); ++i) {
0172       TString name = triggerNames.triggerNames()[i].c_str();
0173       for (unsigned int j = 0; j < vsPaths_.size(); j++) {
0174         if (name.Contains(TString(vsPaths_[j]), TString::kIgnoreCase)) {
0175           hNumTriggerMon->Fill(j + 0.5);
0176         }
0177       }
0178     }
0179   }
0180 }
0181 
0182 // ------------ booking histograms -----------
0183 void B2GSingleLeptonHLTValidation::bookHistograms(DQMStore::IBooker &dbe, edm::Run const &, edm::EventSetup const &) {
0184   dbe.setCurrentFolder(sDir_);
0185   hDenLeptonPt = dbe.book1D("PtLeptonAll", "PtLeptonAll", 50, 0., 2500.);
0186   hDenLeptonEta = dbe.book1D("EtaLeptonAll", "EtaLeptonAll", 30, -3., 3.);
0187   hDenJetPt = dbe.book1D("PtLastJetAll", "PtLastJetAll", 60, 0., 3000.);
0188   hDenJetEta = dbe.book1D("EtaLastJetAll", "EtaLastJetAll", 30, -3., 3.);
0189   hNumLeptonPt = dbe.book1D("PtLeptonSel", "PtLeptonSel", 50, 0., 2500.);
0190   hNumLeptonEta = dbe.book1D("EtaLeptonSel", "EtaLeptonSel", 30, -3., 3.);
0191   hNumJetPt = dbe.book1D("PtLastJetSel", "PtLastJetSel", 60, 0., 3000.);
0192   hNumJetEta = dbe.book1D("EtaLastJetSel", "EtaLastJetSel", 30, -3., 3.);
0193   // determine number of bins for trigger monitoring
0194   unsigned int nPaths = vsPaths_.size();
0195   // monitored trigger occupancy for single lepton triggers
0196   hNumTriggerMon = dbe.book1D("TriggerMonSel", "TriggerMonSel", nPaths, 0., nPaths);
0197   hDenTriggerMon = dbe.book1D("TriggerMonAll", "TriggerMonAll", nPaths, 0., nPaths);
0198   // set bin labels for trigger monitoring
0199   triggerBinLabels(vsPaths_);
0200 }
0201 
0202 // ------------ method fills 'descriptions' with the allowed parameters for the
0203 // module  ------------
0204 void B2GSingleLeptonHLTValidation::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0205   // The following says we do not know what parameters are allowed so do no
0206   // validation
0207   // Please change this to state exactly what you do use, even if it is no
0208   // parameters
0209   edm::ParameterSetDescription desc;
0210   desc.setUnknown();
0211   descriptions.addDefault(desc);
0212 }