CMS 3D CMS Logo

HLTMuonValidator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTMuonValidator
4 // Class: HLTMuonValidator
5 //
6 
7 //
8 // Jason Slaunwhite and Jeff Klukas
9 //
10 //
11 
12 // system include files
13 #include <iostream>
14 #include <memory>
15 #include <tuple>
16 
17 // user include files
19 
25 
28 
29 #include "TDirectory.h"
30 #include "TFile.h"
31 #include "TPRegexp.h"
32 
35 
37 public:
38  explicit HLTMuonValidator(const edm::ParameterSet &);
39 
40 private:
41  // Analyzer Methods
42  void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
43  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
44  void analyze(const edm::Event &, const edm::EventSetup &) override;
45 
46  // Extra Methods
47  std::vector<std::string> moduleLabels(std::string);
48  std::vector<std::string> stepLabels(const std::vector<std::string> &);
49 
50  // Input from Configuration File
53  std::vector<std::string> hltPathsToCheck_;
54 
55  // Member Variables
56  std::vector<HLTMuonPlotter> analyzers_;
58 
62 
64 };
65 
68 
69 using namespace std;
70 using namespace edm;
71 using namespace reco;
72 using namespace trigger;
73 
74 typedef vector<string> vstring;
75 
78 
80  : pset_(pset),
81  hltProcessName_(pset.getParameter<string>("hltProcessName")),
82  hltPathsToCheck_(pset.getParameter<vstring>("hltPathsToCheck")),
83  triggerEventToken_(consumes(edm::InputTag("hltTriggerSummaryRAW"))),
84  genParticlesToken_(consumes(pset.getParameter<string>("genParticleLabel"))),
85  recoMuonsToken_(consumes(pset.getParameter<string>("recMuonLabel"))),
86  l1tMuonMatcherAlgo_(pset, consumesCollector()) {}
87 
88 vector<string> HLTMuonValidator::moduleLabels(string path) {
89  vector<string> modules = hltConfig_.moduleLabels(path);
90  vector<string>::iterator iter = modules.begin();
91 
92  while (iter != modules.end())
93  if (iter->find("Filtered") == string::npos)
94  iter = modules.erase(iter);
95  else
96  ++iter;
97 
98  return modules;
99 }
100 
101 vector<string> HLTMuonValidator::stepLabels(const vector<string> &modules) {
102  vector<string> steps(1, "All");
103  for (size_t i = 0; i < modules.size(); i++) {
104  if ((modules[i].find("IsoFiltered") != string::npos)) {
105  if (modules[i].find("L3") != string::npos)
106  steps.push_back("L3TkIso");
107  else
108  steps.push_back("L2Iso");
109  } else if ((modules[i].find("pfecalIsoRhoFiltered") != string::npos)) {
110  if (modules[i].find("L3") != string::npos)
111  steps.push_back("L3EcalIso");
112  else if (modules[i].find("TkFiltered") != string::npos)
113  steps.push_back("TkEcalIso");
114  } else if ((modules[i].find("pfhcalIsoRhoFiltered") != string::npos)) {
115  if (modules[i].find("L3") != string::npos)
116  steps.push_back("L3HcalIso");
117  else if (modules[i].find("TkFiltered") != string::npos)
118  steps.push_back("TkHcalIso");
119  } else if (modules[i].find("TkFiltered") != string::npos) {
120  steps.push_back("Tk");
121  } else if (modules[i].find("L3") != string::npos)
122  steps.push_back("L3");
123  else if (modules[i].find("L2") != string::npos)
124  steps.push_back("L2");
125  else if (modules[i].find("L1") != string::npos)
126  steps.push_back("L1");
127  else
128  return vector<string>();
129  }
130 
131  if (steps.size() < 2 || ((steps[1] != "L1") && (steps[1] != "Tk")))
132  return vector<string>();
133  return steps;
134 }
135 
136 void HLTMuonValidator::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
137  // Initialize hltConfig
138  bool changedConfig;
139  if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
140  LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
141  return;
142  }
143 
144  // Get the set of trigger paths we want to make plots for
145  set<string> hltPaths;
146  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
147  TPRegexp pattern(hltPathsToCheck_[i]);
148  for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
149  if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
150  hltPaths.insert(hltConfig_.triggerNames()[j]);
151  }
152 
153  // Initialize the analyzers
154  analyzers_.clear();
155  set<string>::iterator iPath;
156  for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
157  string path = *iPath;
158  string shortpath = path;
159  if (path.rfind("_v") < path.length())
160  shortpath = path.substr(0, path.rfind("_v"));
161 
162  vector<string> labels = moduleLabels(path);
163  vector<string> steps = stepLabels(labels);
164 
165  if (!labels.empty() && !steps.empty()) {
168  analyzers_.push_back(analyzer);
169  }
170  }
171 }
172 
174  // Call the beginRun (which books all the histograms)
175  vector<HLTMuonPlotter>::iterator iter;
176  for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
177  iter->beginRun(iBooker, iRun, iSetup);
178  }
179 }
180 
181 void HLTMuonValidator::analyze(const Event &iEvent, const EventSetup &iSetup) {
182  vector<HLTMuonPlotter>::iterator iter;
183  for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
184  iter->analyze(iEvent, iSetup);
185  }
186 }
187 
188 // define this as a plug-in
vector< string > vstring
Definition: ExoticaDQM.cc:8
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< std::string > stepLabels(const std::vector< std::string > &)
edm::EDGetTokenT< reco::MuonCollection > const recoMuonsToken_
HLTMuonPlotter::L1MuonMatcherAlgoForDQM const l1tMuonMatcherAlgo_
std::vector< HLTMuonPlotter > analyzers_
edm::ParameterSet pset_
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< std::string > hltPathsToCheck_
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< trigger::TriggerEventWithRefs > const triggerEventToken_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< std::string > moduleLabels(std::string)
HLTConfigProvider hltConfig_
edm::EDGetTokenT< reco::GenParticleCollection > const genParticlesToken_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const std::vector< std::string > & triggerNames() const
names of trigger paths
std::string hltProcessName_
fixed size matrix
HLT enums.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
vector< string > vstring
HLTMuonValidator(const edm::ParameterSet &)
Definition: Run.h:45