Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:58

0001 #include "HLTriggerOffline/SUSYBSM/interface/SUSY_HLT_SingleLepton.h"
0002 
0003 #include <algorithm>
0004 #include <limits>
0005 
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include "FWCore/Common/interface/TriggerNames.h"
0011 
0012 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0013 
0014 #include "DataFormats/Math/interface/deltaR.h"
0015 
0016 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
0017 #include "DataFormats/EgammaCandidates/interface/ConversionFwd.h"
0018 #include "CommonTools/Egamma/interface/ConversionTools.h"
0019 
0020 namespace {
0021   typedef dqm::reco::DQMStore DQMStore;
0022   typedef dqm::reco::MonitorElement MonitorElement;
0023 
0024   bool Contains(const std::string &text, const std::string &pattern) { return text.find(pattern) != std::string::npos; }
0025 
0026   void SetBinLabels(MonitorElement *const me) {
0027     if (!me)
0028       return;
0029     me->setBinLabel(1, "No CSV Reqs.");
0030     me->setBinLabel(2, "N_{CSVL} >= 1");
0031     me->setBinLabel(3, "N_{CSVL} >= 2");
0032     me->setBinLabel(4, "N_{CSVL} >= 3");
0033     me->setBinLabel(5, "N_{CSVL} >= 4");
0034     me->setBinLabel(6, "N_{CSVM} >= 1");
0035     me->setBinLabel(7, "N_{CSVM} >= 2");
0036     me->setBinLabel(8, "N_{CSVM} >= 3");
0037     me->setBinLabel(9, "N_{CSVM} >= 4");
0038     me->setBinLabel(10, "N_{CSVT} >= 1");
0039     me->setBinLabel(11, "N_{CSVT} >= 2");
0040     me->setBinLabel(12, "N_{CSVT} >= 3");
0041     me->setBinLabel(13, "N_{CSVT} >= 4");
0042   }
0043 
0044   bool IsGood(const reco::GsfElectron &el,
0045               const reco::Vertex::Point &pv_position,
0046               const reco::BeamSpot::Point &bs_position,
0047               const edm::Handle<reco::ConversionCollection> &convs) {
0048     const float dEtaIn = el.deltaEtaSuperClusterTrackAtVtx();
0049     const float dPhiIn = el.deltaPhiSuperClusterTrackAtVtx();
0050     const float sigmaietaieta = el.full5x5_sigmaIetaIeta();
0051     const float hOverE = el.hcalOverEcal();
0052     float d0 = 0.0, dz = 0.0;
0053 
0054     if (el.gsfTrack().isNull()) {
0055       edm::LogError("SUSY_HLT_SingleLepton") << "Could not read electron.gsfTrack().\n";
0056       return false;
0057     }
0058     d0 = -(el.gsfTrack()->dxy(pv_position));
0059     dz = el.gsfTrack()->dz(pv_position);
0060 
0061     float ooemoop = 1e30;
0062     if (el.ecalEnergy() > 0.0 && std::isfinite(el.ecalEnergy())) {
0063       ooemoop = fabs(1.0 / el.ecalEnergy() - el.eSuperClusterOverP() / el.ecalEnergy());
0064     }
0065     const auto &iso = el.pfIsolationVariables();
0066     const float absiso =
0067         iso.sumChargedHadronPt + std::max(0.0, iso.sumNeutralHadronEt + iso.sumPhotonEt - 0.5 * iso.sumPUPt);
0068     const float relisowithdb = absiso / el.pt();
0069 
0070     bool pass_conversion = false;
0071     if (convs.isValid()) {
0072       pass_conversion = !ConversionTools::hasMatchedConversion(el, *convs, bs_position);
0073     } else {
0074       edm::LogError("SUSY_HLT_SingleLepton") << "Electron conversion matching failed.\n";
0075       return false;
0076     }
0077 
0078     float etasc = 0.0;
0079     if (el.superCluster().isNull()) {
0080       edm::LogError("SUSY_HLT_SingleLepton") << "Could not read electron.superCluster().\n";
0081       return false;
0082     }
0083     etasc = el.superCluster()->eta();
0084     if (fabs(etasc) > 2.5) {
0085       return false;
0086     } else if (fabs(etasc) > 1.479) {
0087       if (fabs(dEtaIn) > 0.0106)
0088         return false;
0089       if (fabs(dPhiIn) > 0.0359)
0090         return false;
0091       if (sigmaietaieta > 0.0305)
0092         return false;
0093       if (hOverE > 0.0835)
0094         return false;
0095       if (fabs(d0) > 0.0163)
0096         return false;
0097       if (fabs(dz) > 0.5999)
0098         return false;
0099       if (fabs(ooemoop) > 0.1126)
0100         return false;
0101       if (relisowithdb > 0.2075)
0102         return false;
0103       if (!pass_conversion)
0104         return false;
0105     } else {
0106       if (fabs(dEtaIn) > 0.0091)
0107         return false;
0108       if (fabs(dPhiIn) > 0.031)
0109         return false;
0110       if (sigmaietaieta > 0.0106)
0111         return false;
0112       if (hOverE > 0.0532)
0113         return false;
0114       if (fabs(d0) > 0.0126)
0115         return false;
0116       if (fabs(dz) > 0.0116)
0117         return false;
0118       if (fabs(ooemoop) > 0.0609)
0119         return false;
0120       if (relisowithdb > 0.1649)
0121         return false;
0122       if (!pass_conversion)
0123         return false;
0124     }
0125     return true;
0126   }
0127 
0128   bool IsGood(const reco::Muon &mu, const reco::Vertex::Point &pv_position) {
0129     if (!mu.isGlobalMuon())
0130       return false;
0131     if (!mu.isPFMuon())
0132       return false;
0133     if (mu.globalTrack().isNull()) {
0134       edm::LogWarning("SUSY_HLT_SingleLepton") << "Could not read muon.globalTrack().\n";
0135       return false;
0136     }
0137     if (mu.globalTrack()->normalizedChi2() >= 10.)
0138       return false;
0139     if (mu.globalTrack()->hitPattern().numberOfValidMuonHits() <= 0)
0140       return false;
0141     if (mu.numberOfMatchedStations() <= 1)
0142       return false;
0143     if (mu.muonBestTrack().isNull()) {
0144       edm::LogWarning("SUSY_HLT_SingleLepton") << "Could not read muon.muonBestTrack().\n";
0145       return false;
0146     }
0147     if (fabs(mu.muonBestTrack()->dxy(pv_position)) >= 0.2)
0148       return false;
0149     if (fabs(mu.muonBestTrack()->dz(pv_position)) >= 0.5)
0150       return false;
0151     if (mu.innerTrack().isNull()) {
0152       edm::LogWarning("SUSY_HLT_SingleLepton") << "Could not read muon.innerTrack().\n";
0153       return false;
0154     }
0155     if (mu.innerTrack()->hitPattern().numberOfValidPixelHits() <= 0)
0156       return false;
0157     if (mu.innerTrack()->hitPattern().trackerLayersWithMeasurement() <= 5)
0158       return false;
0159 
0160     return true;
0161   }
0162 }  // namespace
0163 
0164 SUSY_HLT_SingleLepton::SUSY_HLT_SingleLepton(const edm::ParameterSet &ps)
0165     : theElectronTag_(ps.getParameter<edm::InputTag>("electronCollection")),
0166       theElectronCollection_(consumes<reco::GsfElectronCollection>(theElectronTag_)),
0167       theMuonTag_(ps.getParameter<edm::InputTag>("muonCollection")),
0168       theMuonCollection_(consumes<reco::MuonCollection>(theMuonTag_)),
0169       thePfMETTag_(ps.getParameter<edm::InputTag>("pfMetCollection")),
0170       thePfMETCollection_(consumes<reco::PFMETCollection>(thePfMETTag_)),
0171       thePfJetTag_(ps.getParameter<edm::InputTag>("pfJetCollection")),
0172       thePfJetCollection_(consumes<reco::PFJetCollection>(thePfJetTag_)),
0173       theJetTagTag_(ps.getParameter<edm::InputTag>("jetTagCollection")),
0174       theJetTagCollection_(consumes<reco::JetTagCollection>(theJetTagTag_)),
0175 
0176       theVertexCollectionTag_(ps.getParameter<edm::InputTag>("vertexCollection")),
0177       theVertexCollection_(consumes<reco::VertexCollection>(theVertexCollectionTag_)),
0178       theConversionCollectionTag_(ps.getParameter<edm::InputTag>("conversionCollection")),
0179       theConversionCollection_(consumes<reco::ConversionCollection>(theConversionCollectionTag_)),
0180       theBeamSpotTag_(ps.getParameter<edm::InputTag>("beamSpot")),
0181       theBeamSpot_(consumes<reco::BeamSpot>(theBeamSpotTag_)),
0182 
0183       theLeptonFilterTag_(ps.getParameter<edm::InputTag>("leptonFilter")),
0184       theHLTHTTag_(ps.getParameter<edm::InputTag>("hltHt")),
0185       theHLTHT_(consumes<reco::METCollection>(theHLTHTTag_)),
0186       theHLTMETTag_(ps.getParameter<edm::InputTag>("hltMet")),
0187       theHLTMET_(consumes<reco::METCollection>(theHLTMETTag_)),
0188       theHLTJetCollectionTag_(ps.getParameter<edm::InputTag>("hltJets")),
0189       theHLTJetCollection_(consumes<reco::CaloJetCollection>(theHLTJetCollectionTag_)),
0190       theHLTJetTagCollectionTag_(ps.getParameter<edm::InputTag>("hltJetTags")),
0191       theHLTJetTagCollection_(consumes<reco::JetTagCollection>(theHLTJetTagCollectionTag_)),
0192 
0193       theTriggerResultsTag_(ps.getParameter<edm::InputTag>("triggerResults")),
0194       theTriggerResults_(consumes<edm::TriggerResults>(theTriggerResultsTag_)),
0195       theTrigSummaryTag_(ps.getParameter<edm::InputTag>("trigSummary")),
0196       theTrigSummary_(consumes<trigger::TriggerEvent>(theTrigSummaryTag_)),
0197 
0198       fHltConfig_(),
0199 
0200       HLTProcess_(ps.getParameter<std::string>("hltProcess")),
0201 
0202       triggerPath_(ps.getParameter<std::string>("triggerPath")),
0203       triggerPathAuxiliary_(ps.getParameter<std::string>("triggerPathAuxiliary")),
0204       triggerPathLeptonAuxiliary_(ps.getParameter<std::string>("triggerPathLeptonAuxiliary")),
0205 
0206       csvlCut_(ps.getUntrackedParameter<double>("csvlCut")),
0207       csvmCut_(ps.getUntrackedParameter<double>("csvmCut")),
0208       csvtCut_(ps.getUntrackedParameter<double>("csvtCut")),
0209 
0210       jetPtCut_(ps.getUntrackedParameter<double>("jetPtCut")),
0211       jetEtaCut_(ps.getUntrackedParameter<double>("jetEtaCut")),
0212       metCut_(ps.getUntrackedParameter<double>("metCut")),
0213       htCut_(ps.getUntrackedParameter<double>("htCut")),
0214 
0215       lep_pt_threshold_(ps.getUntrackedParameter<double>("leptonPtThreshold")),
0216       ht_threshold_(ps.getUntrackedParameter<double>("htThreshold")),
0217       met_threshold_(ps.getUntrackedParameter<double>("metThreshold")),
0218       csv_threshold_(ps.getUntrackedParameter<double>("csvThreshold")),
0219 
0220       h_triggerLepPt_(nullptr),
0221       h_triggerLepEta_(nullptr),
0222       h_triggerLepPhi_(nullptr),
0223       h_HT_(nullptr),
0224       h_MET_(nullptr),
0225       h_maxCSV_(nullptr),
0226       h_leptonTurnOn_num_(nullptr),
0227       h_leptonTurnOn_den_(nullptr),
0228       h_pfHTTurnOn_num_(nullptr),
0229       h_pfHTTurnOn_den_(nullptr),
0230       h_pfMetTurnOn_num_(nullptr),
0231       h_pfMetTurnOn_den_(nullptr),
0232       h_CSVTurnOn_num_(nullptr),
0233       h_CSVTurnOn_den_(nullptr),
0234       h_btagTurnOn_num_(nullptr),
0235       h_btagTurnOn_den_(nullptr) {
0236   edm::LogInfo("SUSY_HLT_SingleLepton") << "Constructor SUSY_HLT_SingleLepton::SUSY_HLT_SingleLepton\n";
0237 }
0238 
0239 SUSY_HLT_SingleLepton::~SUSY_HLT_SingleLepton() {
0240   edm::LogInfo("SUSY_HLT_SingleLepton") << "Destructor SUSY_HLT_SingleLepton::~SUSY_HLT_SingleLepton\n";
0241 }
0242 
0243 void SUSY_HLT_SingleLepton::dqmBeginRun(const edm::Run &run, const edm::EventSetup &e) {
0244   bool changed;
0245 
0246   if (!fHltConfig_.init(run, e, HLTProcess_, changed)) {
0247     edm::LogError("SUSY_HLT_SingleLepton") << "Initialization of HLTConfigProvider failed!!\n";
0248     return;
0249   }
0250 
0251   bool pathFound = false;
0252   for (const auto &trig_name : fHltConfig_.triggerNames()) {
0253     if (Contains(trig_name, triggerPath_))
0254       pathFound = true;
0255   }
0256 
0257   if (!pathFound) {
0258     LogDebug("SUSY_HLT_SingleLepton") << "Path not found: " << triggerPath_ << '\n';
0259     return;
0260   }
0261 
0262   edm::LogInfo("SUSY_HLT_SingleLepton") << "SUSY_HLT_SingleLepton::beginRun\n";
0263 }
0264 
0265 void SUSY_HLT_SingleLepton::bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) {
0266   edm::LogInfo("SUSY_HLT_SingleLepton") << "SUSY_HLT_SingleLepton::bookHistograms\n";
0267   // book at beginRun
0268   ibooker.cd();
0269   ibooker.setCurrentFolder("HLT/SUSYBSM/" + triggerPath_);
0270 
0271   bool is_mu = false;
0272   bool is_ele = false;
0273   if (theElectronTag_.label().empty() && !theMuonTag_.label().empty()) {
0274     is_mu = true;
0275   } else if (!theElectronTag_.label().empty() && theMuonTag_.label().empty()) {
0276     is_ele = true;
0277   }
0278   std::string lepton = "lepton", Lepton = "Lepton";
0279   if (is_mu && !is_ele) {
0280     lepton = "muon";
0281     Lepton = "Muon";
0282   } else if (is_ele && !is_mu) {
0283     lepton = "electron";
0284     Lepton = "Electron";
0285   }
0286 
0287   // online quantities
0288   h_triggerLepPt_ = ibooker.book1D("triggerLepPt", (";" + Lepton + " p_{T} [GeV];").c_str(), 20, 0.0, 500.0);
0289   h_triggerLepEta_ = ibooker.book1D("triggerLepEta", (";" + Lepton + " #eta;").c_str(), 20, -3.0, 3.0);
0290   h_triggerLepPhi_ = ibooker.book1D("triggerLepPhi", (";" + Lepton + " #phi;").c_str(), 20, -3.5, 3.5);
0291 
0292   if (!theHLTHTTag_.label().empty()) {
0293     h_HT_ = ibooker.book1D("HT", ";HLT HT [GeV];", 40, 0.0, 1000.0);
0294   }
0295 
0296   if (!theHLTMETTag_.label().empty()) {
0297     h_MET_ = ibooker.book1D("MET", ";HLT MET [GeV];", 40, 0.0, 1000.0);
0298   }
0299 
0300   if (!theHLTJetCollectionTag_.label().empty() && !theHLTJetTagCollectionTag_.label().empty()) {
0301     h_maxCSV_ = ibooker.book1D("maxCSV", ";Max HLT CSV;", 20, 0.0, 1.0);
0302   }
0303 
0304   // num and den hists to be divided in harvesting step to make turn on curves
0305   h_leptonTurnOn_num_ =
0306       ibooker.book1D("leptonTurnOn_num", ("Numerator;Offline " + lepton + " p_{T} [GeV];").c_str(), 30, 0.0, 150);
0307   h_leptonTurnOn_den_ =
0308       ibooker.book1D("leptonTurnOn_den", ("Denominator;Offline " + lepton + " p_{T} [GeV];").c_str(), 30, 0.0, 150.0);
0309   h_pfHTTurnOn_num_ = ibooker.book1D("pfHTTurnOn_num", "Numerator;Offline H_{T} [GeV];", 30, 0.0, 1500.0);
0310   h_pfHTTurnOn_den_ = ibooker.book1D("pfHTTurnOn_den", "Denominator;Offline H_{T} [GeV];", 30, 0.0, 1500.0);
0311 
0312   if (!theHLTMETTag_.label().empty()) {
0313     h_pfMetTurnOn_num_ = ibooker.book1D("pfMetTurnOn_num", "Numerator;Offline MET [GeV];", 20, 0.0, 500.0);
0314     h_pfMetTurnOn_den_ = ibooker.book1D("pfMetTurnOn_den", "Denominator;Offline MET [GeV];", 20, 0.0, 500.0);
0315   }
0316 
0317   if (!theHLTJetCollectionTag_.label().empty() && !theHLTJetTagCollectionTag_.label().empty()) {
0318     h_CSVTurnOn_num_ = ibooker.book1D("CSVTurnOn_num", "Numerator;Offline Max CSV Discriminant;", 20, 0.0, 1.0);
0319     h_CSVTurnOn_den_ = ibooker.book1D("CSVTurnOn_den", "Denominator;Offline Max CSV Discriminant;", 20, 0.0, 1.0);
0320 
0321     h_btagTurnOn_num_ = ibooker.book1D("btagTurnOn_num", "Numerator;Offline CSV Requirement;", 13, -0.5, 12.5);
0322     h_btagTurnOn_den_ = ibooker.book1D("btagTurnOn_den", "Denominator;Offline CSV Requirements;", 13, -0.5, 12.5);
0323 
0324     SetBinLabels(h_btagTurnOn_num_);
0325     SetBinLabels(h_btagTurnOn_den_);
0326   }
0327   ibooker.cd();
0328 }
0329 
0330 void SUSY_HLT_SingleLepton::analyze(const edm::Event &e, const edm::EventSetup &eSetup) {
0331   edm::LogInfo("SUSY_HLT_SingleLepton") << "SUSY_HLT_SingleLepton::analyze\n";
0332 
0333   // HLT HT
0334   edm::Handle<reco::METCollection> HLTHT;
0335   if (!theHLTHTTag_.label().empty()) {
0336     e.getByToken(theHLTHT_, HLTHT);
0337     if (!HLTHT.isValid()) {
0338       edm::LogInfo("SUSY_HLT_SingleLepton") << "Invalid METCollection: " << theHLTHTTag_.label() << '\n';
0339     }
0340   }
0341 
0342   // HLT MET
0343   edm::Handle<reco::METCollection> HLTMET;
0344   if (!theHLTMETTag_.label().empty()) {
0345     e.getByToken(theHLTMET_, HLTMET);
0346     if (!HLTMET.isValid()) {
0347       edm::LogInfo("SUSY_HLT_SingleLepton") << "Invalid METCollection: " << theHLTMETTag_.label() << '\n';
0348     }
0349   }
0350 
0351   // HLT Jets
0352   edm::Handle<reco::CaloJetCollection> HLTJetCollection;
0353   if (!theHLTJetCollectionTag_.label().empty()) {
0354     e.getByToken(theHLTJetCollection_, HLTJetCollection);
0355     if (!HLTJetCollection.isValid()) {
0356       edm::LogInfo("SUSY_HLT_SingleLepton") << "Invalid CaloJetCollection: " << theHLTJetCollectionTag_.label() << '\n';
0357     }
0358   }
0359 
0360   // HLT Jet Tags
0361   edm::Handle<reco::JetTagCollection> HLTJetTagCollection;
0362   if (!theHLTJetTagCollectionTag_.label().empty()) {
0363     e.getByToken(theHLTJetTagCollection_, HLTJetTagCollection);
0364     if (!HLTJetTagCollection.isValid()) {
0365       edm::LogInfo("SUSY_HLT_SingleLepton")
0366           << "Invalid JetTagCollection: " << theHLTJetTagCollectionTag_.label() << '\n';
0367     }
0368   }
0369 
0370   // Vertex
0371   edm::Handle<reco::VertexCollection> VertexCollection;
0372   if (!theVertexCollectionTag_.label().empty()) {
0373     e.getByToken(theVertexCollection_, VertexCollection);
0374     if (!VertexCollection.isValid()) {
0375       edm::LogWarning("SUSY_HLT_SingleLepton")
0376           << "Invalid VertexCollection: " << theVertexCollectionTag_.label() << '\n';
0377     }
0378   }
0379 
0380   // Conversions
0381   edm::Handle<reco::ConversionCollection> ConversionCollection;
0382   if (!theConversionCollectionTag_.label().empty()) {
0383     e.getByToken(theConversionCollection_, ConversionCollection);
0384     if (!ConversionCollection.isValid()) {
0385       edm::LogWarning("SUSY_HLT_SingleLepton")
0386           << "Invalid ConversionCollection: " << theConversionCollectionTag_.label() << '\n';
0387     }
0388   }
0389 
0390   // Beam Spot
0391   edm::Handle<reco::BeamSpot> BeamSpot;
0392   if (!theBeamSpotTag_.label().empty()) {
0393     e.getByToken(theBeamSpot_, BeamSpot);
0394     if (!BeamSpot.isValid()) {
0395       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid BeamSpot: " << theBeamSpotTag_.label() << '\n';
0396     }
0397   }
0398 
0399   // MET
0400   edm::Handle<reco::PFMETCollection> pfMETCollection;
0401   if (!thePfMETTag_.label().empty()) {
0402     e.getByToken(thePfMETCollection_, pfMETCollection);
0403     if (!pfMETCollection.isValid()) {
0404       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid PFMETCollection: " << thePfMETTag_.label() << '\n';
0405     }
0406   }
0407 
0408   // Jets
0409   edm::Handle<reco::PFJetCollection> pfJetCollection;
0410   if (!thePfJetTag_.label().empty()) {
0411     e.getByToken(thePfJetCollection_, pfJetCollection);
0412     if (!pfJetCollection.isValid()) {
0413       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid PFJetCollection: " << thePfJetTag_.label() << '\n';
0414     }
0415   }
0416 
0417   // b-tags
0418   edm::Handle<reco::JetTagCollection> jetTagCollection;
0419   if (!theJetTagTag_.label().empty()) {
0420     e.getByToken(theJetTagCollection_, jetTagCollection);
0421     if (!jetTagCollection.isValid()) {
0422       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid JetTagCollection: " << theJetTagTag_.label() << '\n';
0423     }
0424   }
0425 
0426   // Electron
0427   edm::Handle<reco::GsfElectronCollection> ElectronCollection;
0428   if (!theElectronTag_.label().empty()) {
0429     e.getByToken(theElectronCollection_, ElectronCollection);
0430     if (!ElectronCollection.isValid()) {
0431       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid GsfElectronCollection: " << theElectronTag_.label() << '\n';
0432     }
0433   }
0434 
0435   // Muon
0436   edm::Handle<reco::MuonCollection> MuonCollection;
0437   if (!theMuonTag_.label().empty()) {
0438     e.getByToken(theMuonCollection_, MuonCollection);
0439     if (!MuonCollection.isValid()) {
0440       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid MuonCollection: " << theMuonTag_.label() << '\n';
0441     }
0442   }
0443 
0444   // Trigger
0445   edm::Handle<edm::TriggerResults> hltresults;
0446   if (!theTriggerResultsTag_.label().empty()) {
0447     e.getByToken(theTriggerResults_, hltresults);
0448     if (!hltresults.isValid()) {
0449       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid TriggerResults: " << theTriggerResultsTag_.label() << '\n';
0450     }
0451   }
0452   edm::Handle<trigger::TriggerEvent> triggerSummary;
0453   if (!theTrigSummaryTag_.label().empty()) {
0454     e.getByToken(theTrigSummary_, triggerSummary);
0455     if (!triggerSummary.isValid()) {
0456       edm::LogWarning("SUSY_HLT_SingleLepton") << "Invalid TriggerEvent: " << theTrigSummaryTag_.label() << '\n';
0457     }
0458   }
0459 
0460   // Get online leptons
0461   std::vector<float> ptLepton, etaLepton, phiLepton;
0462   if (triggerSummary.isValid()) {
0463     // Leptons
0464     size_t filterIndex = triggerSummary->filterIndex(theLeptonFilterTag_);
0465     trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0466     if (!(filterIndex >= triggerSummary->sizeFilters())) {
0467       size_t ilep = 0, num_keys = triggerSummary->filterKeys(filterIndex).size();
0468       ptLepton.resize(num_keys);
0469       etaLepton.resize(num_keys);
0470       phiLepton.resize(num_keys);
0471       for (const auto &key : triggerSummary->filterKeys(filterIndex)) {
0472         const trigger::TriggerObject &foundObject = triggerObjects[key];
0473 
0474         if (h_triggerLepPt_)
0475           h_triggerLepPt_->Fill(foundObject.pt());
0476         if (h_triggerLepEta_)
0477           h_triggerLepEta_->Fill(foundObject.eta());
0478         if (h_triggerLepPhi_)
0479           h_triggerLepPhi_->Fill(foundObject.phi());
0480 
0481         ptLepton.at(ilep) = foundObject.pt();
0482         etaLepton.at(ilep) = foundObject.eta();
0483         phiLepton.at(ilep) = foundObject.phi();
0484         ++ilep;
0485       }
0486     }
0487   }
0488 
0489   // Get online ht and met
0490   const float hlt_ht = ((HLTHT.isValid() && !HLTHT->empty()) ? HLTHT->front().sumEt() : -1.0);
0491   if (h_HT_)
0492     h_HT_->Fill(hlt_ht);
0493   const float hlt_met = ((HLTMET.isValid() && !HLTMET->empty()) ? HLTMET->front().pt() : -1.0);
0494   if (h_MET_)
0495     h_MET_->Fill(hlt_met);
0496 
0497   // Get online csv and fill plot
0498   float hlt_csv = -1.0;
0499   if (HLTJetCollection.isValid() && HLTJetTagCollection.isValid()) {
0500     for (const auto &jet : *HLTJetTagCollection) {
0501       if (jet.second > hlt_csv)
0502         hlt_csv = jet.second;
0503     }
0504   }
0505   if (h_maxCSV_)
0506     h_maxCSV_->Fill(hlt_csv);
0507 
0508   // Test whether main and auxilliary triggers fired
0509   bool hasFired = false;
0510   bool hasFiredAuxiliary = false;
0511   bool hasFiredLeptonAuxiliary = false;
0512   if (hltresults.isValid()) {
0513     const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
0514     for (unsigned int hltIndex = 0; hltIndex < trigNames.size(); ++hltIndex) {
0515       if (hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex)) {
0516         const std::string &name = trigNames.triggerName(hltIndex);
0517         if (Contains(name, triggerPath_))
0518           hasFired = true;
0519         if (Contains(name, triggerPathAuxiliary_))
0520           hasFiredAuxiliary = true;
0521         if (Contains(name, triggerPathLeptonAuxiliary_))
0522           hasFiredLeptonAuxiliary = true;
0523       }
0524     }
0525   }
0526 
0527   // Get offline HT
0528   double pfHT = -1.0;
0529   if (pfJetCollection.isValid()) {
0530     pfHT = 0.0;
0531     for (const auto &pfjet : *pfJetCollection) {
0532       if (pfjet.pt() < jetPtCut_)
0533         continue;
0534       if (fabs(pfjet.eta()) > jetEtaCut_)
0535         continue;
0536       pfHT += pfjet.pt();
0537     }
0538   }
0539 
0540   // Get offline MET
0541   double pfMET = -1.0;
0542   if (pfMETCollection.isValid() && !pfMETCollection->empty()) {
0543     pfMET = pfMETCollection->front().et();
0544   }
0545 
0546   // Get offline b-tagging info
0547   float maxCSV = -1.0;
0548   unsigned num_csvl = 0;
0549   unsigned num_csvm = 0;
0550   unsigned num_csvt = 0;
0551   if (jetTagCollection.isValid()) {
0552     for (const auto &jet : *jetTagCollection) {
0553       const float CSV = jet.second;
0554       if (jet.first->pt() > jetPtCut_) {
0555         if (CSV > maxCSV) {
0556           maxCSV = CSV;
0557         }
0558         if (CSV > csvlCut_) {
0559           ++num_csvl;
0560           if (CSV > csvmCut_) {
0561             ++num_csvm;
0562             if (CSV > csvtCut_) {
0563               ++num_csvt;
0564             }
0565           }
0566         }
0567       }
0568     }
0569   }
0570   if (h_maxCSV_)
0571     h_maxCSV_->Fill(maxCSV);
0572 
0573   // Fill lepton pt efficiency plot
0574   double lep_max_pt = -1.0;
0575   if (VertexCollection.isValid() && !VertexCollection->empty()) {  // for quality checks
0576     // Try to find a reco electron
0577     if (ElectronCollection.isValid() && ConversionCollection.isValid() && BeamSpot.isValid()) {
0578       for (const auto &electron : *ElectronCollection) {
0579         if (IsGood(electron, VertexCollection->front().position(), BeamSpot->position(), ConversionCollection)) {
0580           if (electron.pt() > lep_max_pt)
0581             lep_max_pt = electron.pt();
0582         }
0583       }
0584     }
0585 
0586     // Try to find a reco muon
0587     if (MuonCollection.isValid()) {
0588       for (const auto &muon : *MuonCollection) {
0589         if (IsGood(muon, VertexCollection->front().position())) {
0590           if (muon.pt() > lep_max_pt) {
0591             lep_max_pt = muon.pt();
0592           }
0593         }
0594       }
0595     }
0596   }
0597 
0598   const bool lep_plateau = lep_max_pt > lep_pt_threshold_ || lep_pt_threshold_ < 0.0;
0599   const bool ht_plateau = pfHT > ht_threshold_ || ht_threshold_ < 0.0;
0600   const bool met_plateau = pfMET > met_threshold_ || met_threshold_ < 0.0;
0601   const bool csv_plateau = maxCSV > csv_threshold_ || csv_threshold_ < 0.0;
0602 
0603   // Fill lepton turn-on histograms
0604   if (hasFiredLeptonAuxiliary || triggerPathLeptonAuxiliary_.empty() || !e.isRealData()) {
0605     // Fill histograms using highest pt reco lepton
0606     if (ht_plateau && met_plateau && csv_plateau && (pfMET > metCut_ || metCut_ < 0.0) &&
0607         (pfHT > htCut_ || htCut_ < 0.0)) {
0608       if (h_leptonTurnOn_den_)
0609         h_leptonTurnOn_den_->Fill(lep_max_pt);
0610       if (h_leptonTurnOn_num_ && hasFired)
0611         h_leptonTurnOn_num_->Fill(lep_max_pt);
0612     }
0613   }
0614 
0615   // Fill remaining turn-on histograms
0616   if (hasFiredAuxiliary || triggerPathAuxiliary_.empty() || !e.isRealData()) {
0617     // Fill HT efficiency plot
0618     if (lep_plateau && met_plateau && csv_plateau) {
0619       if (h_pfHTTurnOn_den_)
0620         h_pfHTTurnOn_den_->Fill(pfHT);
0621       if (h_pfHTTurnOn_num_ && hasFired)
0622         h_pfHTTurnOn_num_->Fill(pfHT);
0623     }
0624 
0625     // Fill MET efficiency plot
0626     if (lep_plateau && ht_plateau && csv_plateau) {
0627       if (h_pfMetTurnOn_den_)
0628         h_pfMetTurnOn_den_->Fill(pfMET);
0629       if (h_pfMetTurnOn_num_ && hasFired)
0630         h_pfMetTurnOn_num_->Fill(pfMET);
0631     }
0632 
0633     // Fill CSV efficiency plot
0634     if (lep_plateau && ht_plateau && met_plateau) {
0635       if (h_CSVTurnOn_den_)
0636         h_CSVTurnOn_den_->Fill(maxCSV);
0637       if (h_CSVTurnOn_num_ && hasFired)
0638         h_CSVTurnOn_num_->Fill(maxCSV);
0639 
0640       if (h_btagTurnOn_den_) {
0641         switch (num_csvl) {
0642           default:
0643             h_btagTurnOn_den_->Fill(4);
0644             [[fallthrough]];
0645           case 3:
0646             h_btagTurnOn_den_->Fill(3);
0647             [[fallthrough]];
0648           case 2:
0649             h_btagTurnOn_den_->Fill(2);
0650             [[fallthrough]];
0651           case 1:
0652             h_btagTurnOn_den_->Fill(1);
0653             [[fallthrough]];
0654           case 0:
0655             h_btagTurnOn_den_->Fill(0);
0656         }
0657         switch (num_csvm) {
0658           default:
0659             h_btagTurnOn_den_->Fill(8);
0660             [[fallthrough]];
0661           case 3:
0662             h_btagTurnOn_den_->Fill(7);
0663             [[fallthrough]];
0664           case 2:
0665             h_btagTurnOn_den_->Fill(6);
0666             [[fallthrough]];
0667           case 1:
0668             h_btagTurnOn_den_->Fill(5);
0669             [[fallthrough]];
0670           case 0:
0671             break;  // Don't double count in the no tag bin
0672         }
0673         switch (num_csvt) {
0674           default:
0675             h_btagTurnOn_den_->Fill(12);
0676             [[fallthrough]];
0677           case 3:
0678             h_btagTurnOn_den_->Fill(11);
0679             [[fallthrough]];
0680           case 2:
0681             h_btagTurnOn_den_->Fill(10);
0682             [[fallthrough]];
0683           case 1:
0684             h_btagTurnOn_den_->Fill(9);
0685             [[fallthrough]];
0686           case 0:
0687             break;  // Don't double count in the no tag bin
0688         }
0689       }
0690       if (h_btagTurnOn_num_ && hasFired) {
0691         switch (num_csvl) {
0692           default:
0693             h_btagTurnOn_num_->Fill(4);
0694             [[fallthrough]];
0695           case 3:
0696             h_btagTurnOn_num_->Fill(3);
0697             [[fallthrough]];
0698           case 2:
0699             h_btagTurnOn_num_->Fill(2);
0700             [[fallthrough]];
0701           case 1:
0702             h_btagTurnOn_num_->Fill(1);
0703             [[fallthrough]];
0704           case 0:
0705             h_btagTurnOn_num_->Fill(0);
0706         }
0707         switch (num_csvm) {
0708           default:
0709             h_btagTurnOn_num_->Fill(8);
0710             [[fallthrough]];
0711           case 3:
0712             h_btagTurnOn_num_->Fill(7);
0713             [[fallthrough]];
0714           case 2:
0715             h_btagTurnOn_num_->Fill(6);
0716             [[fallthrough]];
0717           case 1:
0718             h_btagTurnOn_num_->Fill(5);
0719             [[fallthrough]];
0720           case 0:
0721             break;  // Don't double count in the no tag bin
0722         }
0723         switch (num_csvt) {
0724           default:
0725             h_btagTurnOn_num_->Fill(12);
0726             [[fallthrough]];
0727           case 3:
0728             h_btagTurnOn_num_->Fill(11);
0729             [[fallthrough]];
0730           case 2:
0731             h_btagTurnOn_num_->Fill(10);
0732             [[fallthrough]];
0733           case 1:
0734             h_btagTurnOn_num_->Fill(9);
0735             [[fallthrough]];
0736           case 0:
0737             break;  // Don't double count in the no tag bin
0738         }
0739       }
0740     }
0741   }
0742 }
0743 
0744 // define this as a plug-in
0745 DEFINE_FWK_MODULE(SUSY_HLT_SingleLepton);