Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:02

0001 // -*- C++ -*-
0002 //
0003 // Package:     HLTMuonValidator
0004 // Class:       HLTMuonValidator
0005 //
0006 
0007 //
0008 // Jason Slaunwhite and Jeff Klukas
0009 //
0010 //
0011 
0012 // system include files
0013 #include <iostream>
0014 #include <memory>
0015 #include <tuple>
0016 
0017 // user include files
0018 #include "HLTriggerOffline/Muon/interface/HLTMuonPlotter.h"
0019 
0020 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0028 
0029 #include "TDirectory.h"
0030 #include "TFile.h"
0031 #include "TPRegexp.h"
0032 
0033 //////////////////////////////////////////////////////////////////////////////
0034 //////// Define the interface ////////////////////////////////////////////////
0035 
0036 class HLTMuonValidator : public DQMEDAnalyzer {
0037 public:
0038   explicit HLTMuonValidator(const edm::ParameterSet &);
0039 
0040 private:
0041   // Analyzer Methods
0042   void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
0043   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0044   void analyze(const edm::Event &, const edm::EventSetup &) override;
0045 
0046   // Extra Methods
0047   std::vector<std::string> moduleLabels(std::string);
0048   std::vector<std::string> stepLabels(const std::vector<std::string> &);
0049 
0050   // Input from Configuration File
0051   edm::ParameterSet pset_;
0052   std::string hltProcessName_;
0053   std::vector<std::string> hltPathsToCheck_;
0054 
0055   // Member Variables
0056   std::vector<HLTMuonPlotter> analyzers_;
0057   HLTConfigProvider hltConfig_;
0058 
0059   edm::EDGetTokenT<trigger::TriggerEventWithRefs> const triggerEventToken_;
0060   edm::EDGetTokenT<reco::GenParticleCollection> const genParticlesToken_;
0061   edm::EDGetTokenT<reco::MuonCollection> const recoMuonsToken_;
0062 
0063   HLTMuonPlotter::L1MuonMatcherAlgoForDQM const l1tMuonMatcherAlgo_;
0064 };
0065 
0066 //////////////////////////////////////////////////////////////////////////////
0067 //////// Namespaces, Typedefs, and Constants /////////////////////////////////
0068 
0069 using namespace std;
0070 using namespace edm;
0071 using namespace reco;
0072 using namespace trigger;
0073 
0074 typedef vector<string> vstring;
0075 
0076 //////////////////////////////////////////////////////////////////////////////
0077 //////// Class Methods ///////////////////////////////////////////////////////
0078 
0079 HLTMuonValidator::HLTMuonValidator(const ParameterSet &pset)
0080     : pset_(pset),
0081       hltProcessName_(pset.getParameter<string>("hltProcessName")),
0082       hltPathsToCheck_(pset.getParameter<vstring>("hltPathsToCheck")),
0083       triggerEventToken_(consumes(edm::InputTag("hltTriggerSummaryRAW"))),
0084       genParticlesToken_(consumes(pset.getParameter<string>("genParticleLabel"))),
0085       recoMuonsToken_(consumes(pset.getParameter<string>("recMuonLabel"))),
0086       l1tMuonMatcherAlgo_(pset, consumesCollector()) {}
0087 
0088 vector<string> HLTMuonValidator::moduleLabels(string path) {
0089   vector<string> modules = hltConfig_.moduleLabels(path);
0090   vector<string>::iterator iter = modules.begin();
0091 
0092   while (iter != modules.end())
0093     if (iter->find("Filtered") == string::npos)
0094       iter = modules.erase(iter);
0095     else
0096       ++iter;
0097 
0098   return modules;
0099 }
0100 
0101 vector<string> HLTMuonValidator::stepLabels(const vector<string> &modules) {
0102   vector<string> steps(1, "All");
0103   for (size_t i = 0; i < modules.size(); i++) {
0104     if ((modules[i].find("IsoFiltered") != string::npos)) {
0105       if (modules[i].find("L3") != string::npos)
0106         steps.push_back("L3TkIso");
0107       else
0108         steps.push_back("L2Iso");
0109     } else if ((modules[i].find("pfecalIsoRhoFiltered") != string::npos)) {
0110       if (modules[i].find("L3") != string::npos)
0111         steps.push_back("L3EcalIso");
0112       else if (modules[i].find("TkFiltered") != string::npos)
0113         steps.push_back("TkEcalIso");
0114     } else if ((modules[i].find("pfhcalIsoRhoFiltered") != string::npos)) {
0115       if (modules[i].find("L3") != string::npos)
0116         steps.push_back("L3HcalIso");
0117       else if (modules[i].find("TkFiltered") != string::npos)
0118         steps.push_back("TkHcalIso");
0119     } else if (modules[i].find("TkFiltered") != string::npos) {
0120       steps.push_back("Tk");
0121     } else if (modules[i].find("L3") != string::npos)
0122       steps.push_back("L3");
0123     else if (modules[i].find("L2") != string::npos)
0124       steps.push_back("L2");
0125     else if (modules[i].find("L1") != string::npos)
0126       steps.push_back("L1");
0127     else
0128       return vector<string>();
0129   }
0130 
0131   if (steps.size() < 2 || ((steps[1] != "L1") && (steps[1] != "Tk")))
0132     return vector<string>();
0133   return steps;
0134 }
0135 
0136 void HLTMuonValidator::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
0137   // Initialize hltConfig
0138   bool changedConfig;
0139   if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
0140     LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
0141     return;
0142   }
0143 
0144   // Get the set of trigger paths we want to make plots for
0145   set<string> hltPaths;
0146   for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
0147     TPRegexp pattern(hltPathsToCheck_[i]);
0148     for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
0149       if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
0150         hltPaths.insert(hltConfig_.triggerNames()[j]);
0151   }
0152 
0153   // Initialize the analyzers
0154   analyzers_.clear();
0155   set<string>::iterator iPath;
0156   for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
0157     string path = *iPath;
0158     string shortpath = path;
0159     if (path.rfind("_v") < path.length())
0160       shortpath = path.substr(0, path.rfind("_v"));
0161 
0162     vector<string> labels = moduleLabels(path);
0163     vector<string> steps = stepLabels(labels);
0164 
0165     if (!labels.empty() && !steps.empty()) {
0166       HLTMuonPlotter analyzer(
0167           pset_, shortpath, labels, steps, triggerEventToken_, genParticlesToken_, recoMuonsToken_, l1tMuonMatcherAlgo_);
0168       analyzers_.push_back(analyzer);
0169     }
0170   }
0171 }
0172 
0173 void HLTMuonValidator::bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &iRun, edm::EventSetup const &iSetup) {
0174   // Call the beginRun (which books all the histograms)
0175   vector<HLTMuonPlotter>::iterator iter;
0176   for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
0177     iter->beginRun(iBooker, iRun, iSetup);
0178   }
0179 }
0180 
0181 void HLTMuonValidator::analyze(const Event &iEvent, const EventSetup &iSetup) {
0182   vector<HLTMuonPlotter>::iterator iter;
0183   for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
0184     iter->analyze(iEvent, iSetup);
0185   }
0186 }
0187 
0188 // define this as a plug-in
0189 DEFINE_FWK_MODULE(HLTMuonValidator);