Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:40

0001 #include "DQMOffline/Trigger/interface/HLTTauDQMTagAndProbePlotter.h"
0002 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0003 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0004 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0005 
0006 #include <boost/algorithm/string.hpp>
0007 #include "Math/GenVector/VectorUtil.h"
0008 
0009 namespace {
0010   std::string stripVersion(const std::string& pathName) {
0011     size_t versionStart = pathName.rfind("_v");
0012     if (versionStart == std::string::npos)
0013       return pathName;
0014     return pathName.substr(0, versionStart);
0015   }
0016 }  // namespace
0017 
0018 //HLTTauDQMTagAndProbePlotter::HLTTauDQMTagAndProbePlotter(const edm::ParameterSet& iConfig, std::unique_ptr<GenericTriggerEventFlag> numFlag, std::unique_ptr<GenericTriggerEventFlag> denFlag, const std::string& dqmBaseFolder) :
0019 HLTTauDQMTagAndProbePlotter::HLTTauDQMTagAndProbePlotter(const edm::ParameterSet& iConfig,
0020                                                          const std::vector<std::string>& modLabels,
0021                                                          const std::string& dqmBaseFolder)
0022     : HLTTauDQMPlotter(stripVersion(iConfig.getParameter<std::string>("name")), dqmBaseFolder),
0023       nbinsPt_(iConfig.getParameter<int>("nPtBins")),
0024       ptmin_(iConfig.getParameter<double>("ptmin")),
0025       ptmax_(iConfig.getParameter<double>("ptmax")),
0026       nbinsPhi_(iConfig.getParameter<int>("nPhiBins")),
0027       phimin_(iConfig.getParameter<double>("phimin")),
0028       phimax_(iConfig.getParameter<double>("phimax")),
0029       xvariable(iConfig.getParameter<std::string>("xvariable")) {
0030   numTriggers =
0031       iConfig.getParameter<edm::ParameterSet>("numerator").getParameter<std::vector<std::string> >("hltPaths");
0032   denTriggers =
0033       iConfig.getParameter<edm::ParameterSet>("denominator").getParameter<std::vector<std::string> >("hltPaths");
0034 
0035   moduleLabels = modLabels;
0036 
0037   boost::algorithm::to_lower(xvariable);
0038 
0039   if (xvariable != "met") {
0040     nbinsEta_ = iConfig.getParameter<int>("nEtaBins");
0041     etamin_ = iConfig.getParameter<double>("etamin");
0042     etamax_ = iConfig.getParameter<double>("etamax");
0043   }
0044 
0045   nOfflineObjs = iConfig.getUntrackedParameter<unsigned int>("nOfflObjs", 1);
0046 }
0047 
0048 #include <algorithm>
0049 void HLTTauDQMTagAndProbePlotter::bookHistograms(HistoWrapper& iWrapper,
0050                                                  DQMStore::IBooker& iBooker,
0051                                                  edm::Run const& iRun,
0052                                                  edm::EventSetup const& iSetup) {
0053   if (!isValid())
0054     return;
0055 
0056   // Efficiency helpers
0057   iBooker.setCurrentFolder(triggerTag() + "/helpers");
0058   h_num_pt = iWrapper.book1D(iBooker, xvariable + "EtEffNum", "", nbinsPt_, ptmin_, ptmax_, kVital);
0059   h_den_pt = iWrapper.book1D(iBooker, xvariable + "EtEffDenom", "", nbinsPt_, ptmin_, ptmax_, kVital);
0060 
0061   if (xvariable != "met") {
0062     h_num_eta = iWrapper.book1D(iBooker, xvariable + "EtaEffNum", "", nbinsEta_, etamin_, etamax_);
0063     h_den_eta = iWrapper.book1D(iBooker, xvariable + "EtaEffDenom", "", nbinsEta_, etamin_, etamax_);
0064 
0065     h_num_etaphi = iWrapper.book2D(
0066         iBooker, xvariable + "EtaPhiEffNum", "", nbinsEta_, etamin_, etamax_, nbinsPhi_, phimin_, phimax_);
0067     h_den_etaphi = iWrapper.book2D(
0068         iBooker, xvariable + "EtaPhiEffDenom", "", nbinsEta_, etamin_, etamax_, nbinsPhi_, phimin_, phimax_);
0069     if (h_den_etaphi)
0070       h_den_etaphi->setOption("COL");
0071   }
0072 
0073   h_num_phi = iWrapper.book1D(iBooker, xvariable + "PhiEffNum", "", nbinsPhi_, phimin_, phimax_);
0074   h_den_phi = iWrapper.book1D(iBooker, xvariable + "PhiEffDenom", "", nbinsPhi_, phimin_, phimax_);
0075 
0076   iBooker.setCurrentFolder(triggerTag());
0077 }
0078 
0079 HLTTauDQMTagAndProbePlotter::~HLTTauDQMTagAndProbePlotter() = default;
0080 
0081 LV HLTTauDQMTagAndProbePlotter::findTrgObject(std::string pathName, const trigger::TriggerEvent& triggerEvent) {
0082   trigger::TriggerObjectCollection trigObjs = triggerEvent.getObjects();
0083   const unsigned moduleIndex = moduleLabels.size() - 2;
0084 
0085   const unsigned hltFilterIndex = triggerEvent.filterIndex(edm::InputTag(moduleLabels[moduleIndex], "", "HLT"));
0086 
0087   if (hltFilterIndex < triggerEvent.sizeFilters()) {
0088     const trigger::Keys& triggerKeys(triggerEvent.filterKeys(hltFilterIndex));
0089     const trigger::Vids& triggerVids(triggerEvent.filterIds(hltFilterIndex));
0090 
0091     const unsigned nTriggers = triggerVids.size();
0092     for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
0093       const trigger::TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
0094       //         std::cout << "        trigger objs pt,eta,phi: " << triggerKeys[iTrig] << " "
0095       //                   << trigObject.pt() << " " << trigObject.eta() << " " << trigObject.phi() << " " << trigObject.id() << std::endl;
0096       return LV(trigObject.px(), trigObject.py(), trigObject.pz(), trigObject.energy());
0097     }
0098   }
0099   return LV(0, 0, 0, 0);
0100 }
0101 
0102 void HLTTauDQMTagAndProbePlotter::analyze(edm::Event const& iEvent,
0103                                           const edm::TriggerResults& triggerResults,
0104                                           const trigger::TriggerEvent& triggerEvent,
0105                                           const HLTTauDQMOfflineObjects& refCollection) {
0106   std::vector<LV> offlineObjects;
0107   if (xvariable == "tau")
0108     offlineObjects = refCollection.taus;
0109   if (xvariable == "muon")
0110     offlineObjects = refCollection.muons;
0111   if (xvariable == "electron")
0112     offlineObjects = refCollection.electrons;
0113   if (xvariable == "met")
0114     offlineObjects = refCollection.met;
0115 
0116   if (offlineObjects.size() < nOfflineObjs)
0117     return;
0118 
0119   const edm::TriggerNames& trigNames = iEvent.triggerNames(triggerResults);
0120 
0121   for (const LV& offlineObject : offlineObjects) {
0122     // Filter out events if Trigger Filtering is requested
0123     bool passTrigger = false;
0124     bool hltMatched = false;
0125     for (size_t i = 0; i < denTriggers.size(); ++i) {
0126       LV trgObject = findTrgObject(denTriggers[i], triggerEvent);
0127 
0128       for (unsigned int hltIndex = 0; hltIndex < trigNames.size(); ++hltIndex) {
0129         passTrigger = (trigNames.triggerName(hltIndex).find(denTriggers[i]) != std::string::npos &&
0130                        triggerResults.wasrun(hltIndex) && triggerResults.accept(hltIndex));
0131 
0132         if (passTrigger) {
0133           double dr = ROOT::Math::VectorUtil::DeltaR(trgObject, offlineObject);
0134           if (dr < 0.4)
0135             hltMatched = true;
0136           break;
0137         }
0138       }
0139       if (passTrigger)
0140         break;
0141     }
0142     if (!passTrigger)
0143       return;
0144     if (hltMatched)
0145       return;  // do not consider offline objects which match the tag trigger
0146 
0147     if (h_den_pt)
0148       h_den_pt->Fill(offlineObject.pt());
0149     if (xvariable != "met") {
0150       if (h_den_eta)
0151         h_den_eta->Fill(offlineObject.eta());
0152       if (h_den_etaphi)
0153         h_den_etaphi->Fill(offlineObject.eta(), offlineObject.phi());
0154     }
0155     if (h_den_phi)
0156       h_den_phi->Fill(offlineObject.phi());
0157 
0158     // applying selection for numerator
0159     passTrigger = false;
0160     for (size_t i = 0; i < numTriggers.size(); ++i) {
0161       for (unsigned int hltIndex = 0; hltIndex < trigNames.size(); ++hltIndex) {
0162         passTrigger = (trigNames.triggerName(hltIndex).find(numTriggers[i]) != std::string::npos &&
0163                        triggerResults.wasrun(hltIndex) && triggerResults.accept(hltIndex));
0164         if (passTrigger)
0165           break;
0166       }
0167       if (passTrigger)
0168         break;
0169     }
0170     if (!passTrigger)
0171       return;
0172 
0173     if (h_num_pt)
0174       h_num_pt->Fill(offlineObject.pt());
0175     if (xvariable != "met") {
0176       if (h_num_eta)
0177         h_num_eta->Fill(offlineObject.eta());
0178       if (h_num_etaphi)
0179         h_num_etaphi->Fill(offlineObject.eta(), offlineObject.phi());
0180     }
0181     if (h_num_phi)
0182       h_num_phi->Fill(offlineObject.phi());
0183   }
0184 }