CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
36 class HLTMuonValidator : public DQMEDAnalyzer {
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  std::tuple<edm::EDGetTokenT<trigger::TriggerEventWithRefs>,
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  myTokens_ = HLTMuonPlotter::getTokens(pset_, consumesCollector());
84  myESTokens_ = HLTMuonPlotter::getESTokens(consumesCollector());
85 }
86 
87 vector<string> HLTMuonValidator::moduleLabels(string path) {
88  vector<string> modules = hltConfig_.moduleLabels(path);
89  vector<string>::iterator iter = modules.begin();
90 
91  while (iter != modules.end())
92  if (iter->find("Filtered") == string::npos)
93  iter = modules.erase(iter);
94  else
95  ++iter;
96 
97  return modules;
98 }
99 
100 vector<string> HLTMuonValidator::stepLabels(const vector<string> &modules) {
101  vector<string> steps(1, "All");
102  for (size_t i = 0; i < modules.size(); i++) {
103  if ((modules[i].find("IsoFiltered") != string::npos)) {
104  if (modules[i].find("L3") != string::npos)
105  steps.push_back("L3TkIso");
106  else
107  steps.push_back("L2Iso");
108  } else if ((modules[i].find("pfecalIsoRhoFiltered") != string::npos)) {
109  if (modules[i].find("L3") != string::npos)
110  steps.push_back("L3EcalIso");
111  else if (modules[i].find("TkFiltered") != string::npos)
112  steps.push_back("TkEcalIso");
113  } else if ((modules[i].find("pfhcalIsoRhoFiltered") != string::npos)) {
114  if (modules[i].find("L3") != string::npos)
115  steps.push_back("L3HcalIso");
116  else if (modules[i].find("TkFiltered") != string::npos)
117  steps.push_back("TkHcalIso");
118  } else if (modules[i].find("TkFiltered") != string::npos) {
119  steps.push_back("Tk");
120  } else if (modules[i].find("L3") != string::npos)
121  steps.push_back("L3");
122  else if (modules[i].find("L2") != string::npos)
123  steps.push_back("L2");
124  else if (modules[i].find("L1") != string::npos)
125  steps.push_back("L1");
126  else
127  return vector<string>();
128  }
129 
130  if (steps.size() < 2 || ((steps[1] != "L1") && (steps[1] != "Tk")))
131  return vector<string>();
132  return steps;
133 }
134 
135 void HLTMuonValidator::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
136  // Initialize hltConfig
137  bool changedConfig;
138  if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
139  LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
140  return;
141  }
142 
143  // Get the set of trigger paths we want to make plots for
144  set<string> hltPaths;
145  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
146  TPRegexp pattern(hltPathsToCheck_[i]);
147  for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
148  if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
149  hltPaths.insert(hltConfig_.triggerNames()[j]);
150  }
151 
152  // Initialize the analyzers
153  analyzers_.clear();
154  set<string>::iterator iPath;
155  for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
156  string path = *iPath;
157  string shortpath = path;
158  if (path.rfind("_v") < path.length())
159  shortpath = path.substr(0, path.rfind("_v"));
160 
161  vector<string> labels = moduleLabels(path);
162  vector<string> steps = stepLabels(labels);
163 
164  if (!labels.empty() && !steps.empty()) {
165  HLTMuonPlotter analyzer(pset_, shortpath, labels, steps, myTokens_, myESTokens_);
166  analyzers_.push_back(analyzer);
167  }
168  }
169 }
170 
172  // Call the beginRun (which books all the histograms)
173  vector<HLTMuonPlotter>::iterator iter;
174  for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
175  iter->beginRun(iBooker, iRun, iSetup);
176  }
177 }
178 
179 void HLTMuonValidator::analyze(const Event &iEvent, const EventSetup &iSetup) {
180  vector<HLTMuonPlotter>::iterator iter;
181  for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
182  iter->analyze(iEvent, iSetup);
183  }
184 }
185 
186 // 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 > &)
const std::vector< std::string > & triggerNames() const
names of trigger paths
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::tuple< edm::EDGetTokenT< trigger::TriggerEventWithRefs >, edm::EDGetTokenT< reco::GenParticleCollection >, edm::EDGetTokenT< reco::MuonCollection > > myTokens_
std::vector< std::string > hltPathsToCheck_
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
HLTMuonPlotter::ESTokens myESTokens_
std::vector< std::string > moduleLabels(std::string)
hltriggeroffline::L1MuonMatcherAlgo::ESTokens ESTokens
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
HLTConfigProvider hltConfig_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::string hltProcessName_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
static std::tuple< edm::EDGetTokenT< trigger::TriggerEventWithRefs >, edm::EDGetTokenT< reco::GenParticleCollection >, edm::EDGetTokenT< reco::MuonCollection > > getTokens(const edm::ParameterSet &, edm::ConsumesCollector &&)
static std::tuple< edm::ESGetToken< MagneticField, IdealMagneticFieldRecord >, edm::ESGetToken< Propagator, TrackingComponentsRecord >, edm::ESGetToken< Propagator, TrackingComponentsRecord >, edm::ESGetToken< Propagator, TrackingComponentsRecord >, edm::ESGetToken< MuonDetLayerGeometry, MuonRecoGeometryRecord > > getESTokens(edm::ConsumesCollector)
HLTMuonValidator(const edm::ParameterSet &)
Definition: Run.h:45