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 
16 // user include files
18 
24 
27 
28 #include "TDirectory.h"
29 #include "TFile.h"
30 #include "TPRegexp.h"
31 #include "boost/tuple/tuple.hpp"
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  void endRun(const edm::Run &, const edm::EventSetup &) override;
46 
47  // Extra Methods
48  std::vector<std::string> moduleLabels(std::string);
49  std::vector<std::string> stepLabels(const std::vector<std::string> &);
50 
51  // Input from Configuration File
54  std::vector<std::string> hltPathsToCheck_;
55 
56  // Member Variables
57  std::vector<HLTMuonPlotter> analyzers_;
59  boost::tuple<edm::EDGetTokenT<trigger::TriggerEventWithRefs>,
63 };
64 
67 
68 using namespace std;
69 using namespace edm;
70 using namespace reco;
71 using namespace trigger;
72 
73 typedef vector<string> vstring;
74 
77 
79  : pset_(pset),
80  hltProcessName_(pset.getParameter<string>("hltProcessName")),
81  hltPathsToCheck_(pset.getParameter<vstring>("hltPathsToCheck")) {
82  myTokens_ = HLTMuonPlotter::getTokens(pset_, consumesCollector());
83 }
84 
85 vector<string> HLTMuonValidator::moduleLabels(string path) {
86  vector<string> modules = hltConfig_.moduleLabels(path);
87  vector<string>::iterator iter = modules.begin();
88 
89  while (iter != modules.end())
90  if (iter->find("Filtered") == string::npos)
91  iter = modules.erase(iter);
92  else
93  ++iter;
94 
95  return modules;
96 }
97 
98 vector<string> HLTMuonValidator::stepLabels(const vector<string> &modules) {
99  vector<string> steps(1, "All");
100  for (size_t i = 0; i < modules.size(); i++) {
101  if ((modules[i].find("IsoFiltered") != string::npos)) {
102  if (modules[i].find("L3") != string::npos)
103  steps.push_back("L3TkIso");
104  else
105  steps.push_back("L2Iso");
106  } else if ((modules[i].find("pfecalIsoRhoFiltered") != string::npos)) {
107  if (modules[i].find("L3") != string::npos)
108  steps.push_back("L3EcalIso");
109  else if (modules[i].find("TkFiltered") != string::npos)
110  steps.push_back("TkEcalIso");
111  } else if ((modules[i].find("pfhcalIsoRhoFiltered") != string::npos)) {
112  if (modules[i].find("L3") != string::npos)
113  steps.push_back("L3HcalIso");
114  else if (modules[i].find("TkFiltered") != string::npos)
115  steps.push_back("TkHcalIso");
116  } else if (modules[i].find("TkFiltered") != string::npos) {
117  steps.push_back("Tk");
118  } else if (modules[i].find("L3") != string::npos)
119  steps.push_back("L3");
120  else if (modules[i].find("L2") != string::npos)
121  steps.push_back("L2");
122  else if (modules[i].find("L1") != string::npos)
123  steps.push_back("L1");
124  else
125  return vector<string>();
126  }
127 
128  if (steps.size() < 2 || ((steps[1] != "L1") && (steps[1] != "Tk")))
129  return vector<string>();
130  return steps;
131 }
132 
133 void HLTMuonValidator::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
134  // Initialize hltConfig
135  bool changedConfig;
136  if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
137  LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
138  return;
139  }
140 
141  // Get the set of trigger paths we want to make plots for
142  set<string> hltPaths;
143  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
144  TPRegexp pattern(hltPathsToCheck_[i]);
145  for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
146  if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
147  hltPaths.insert(hltConfig_.triggerNames()[j]);
148  }
149 
150  // Initialize the analyzers
151  analyzers_.clear();
152  set<string>::iterator iPath;
153  for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
154  string path = *iPath;
155  string shortpath = path;
156  if (path.rfind("_v") < path.length())
157  shortpath = path.substr(0, path.rfind("_v"));
158 
159  vector<string> labels = moduleLabels(path);
160  vector<string> steps = stepLabels(labels);
161 
162  if (!labels.empty() && !steps.empty()) {
163  HLTMuonPlotter analyzer(pset_, shortpath, labels, steps, myTokens_);
164  analyzers_.push_back(analyzer);
165  }
166  }
167 }
168 
170  // Call the beginRun (which books all the histograms)
171  vector<HLTMuonPlotter>::iterator iter;
172  for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
173  iter->beginRun(iBooker, iRun, iSetup);
174  }
175 }
176 
177 void HLTMuonValidator::analyze(const Event &iEvent, const EventSetup &iSetup) {
178  vector<HLTMuonPlotter>::iterator iter;
179  for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
180  iter->analyze(iEvent, iSetup);
181  }
182 }
183 
184 void HLTMuonValidator::endRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
185  // vector<HLTMuonPlotter>::iterator iter;
186  // for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
187  // iter->endRun(iRun, iSetup);
188  // }
189 }
190 
191 // define this as a plug-in
vector< string > vstring
Definition: ExoticaDQM.cc:8
boost::tuple< edm::EDGetTokenT< trigger::TriggerEventWithRefs >, edm::EDGetTokenT< reco::GenParticleCollection >, edm::EDGetTokenT< reco::MuonCollection > > myTokens_
std::vector< std::string > stepLabels(const std::vector< std::string > &)
const std::vector< std::string > & triggerNames() const
names of trigger paths
std::vector< HLTMuonPlotter > analyzers_
edm::ParameterSet pset_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< std::string > hltPathsToCheck_
static boost::tuple< edm::EDGetTokenT< trigger::TriggerEventWithRefs >, edm::EDGetTokenT< reco::GenParticleCollection >, edm::EDGetTokenT< reco::MuonCollection > > getTokens(const edm::ParameterSet &, edm::ConsumesCollector &&)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< std::string > moduleLabels(std::string)
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
void endRun(const edm::Run &, const edm::EventSetup &) override
HLTConfigProvider hltConfig_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
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