CMS 3D CMS Logo

HLTMuonValidator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTMuonValidator
4 // Class: HLTMuonValidator
5 //
6 // Jason Slaunwhite and Jeff Klukas
7 //
8 #include <algorithm>
9 #include <string>
10 #include <vector>
11 
19 
20 #include "TPRegexp.h"
21 
23 public:
24  explicit HLTMuonValidator(const edm::ParameterSet &);
25 
26 private:
27  // Analyzer Methods
28  void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
29  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
30  void analyze(const edm::Event &, const edm::EventSetup &) override;
31 
32  // Extra Methods
33  void fillLabels(std::string const &path,
34  std::vector<std::string> &moduleLabels,
35  std::vector<std::string> &stepLabels) const;
37 
38  // Input from Configuration File
41  std::vector<std::string> hltPathsToCheck_;
42 
43  // Member Variables
44  std::vector<HLTMuonPlotter> analyzers_;
46 
50 
52 };
53 
55  : pset_(pset),
56  hltProcessName_(pset.getParameter<std::string>("hltProcessName")),
57  hltPathsToCheck_(pset.getParameter<std::vector<std::string>>("hltPathsToCheck")),
58  triggerEventToken_(consumes(edm::InputTag("hltTriggerSummaryRAW"))),
59  genParticlesToken_(consumes(pset.getParameter<std::string>("genParticleLabel"))),
60  recoMuonsToken_(consumes(pset.getParameter<std::string>("recMuonLabel"))),
61  l1tMuonMatcherAlgo_(pset, consumesCollector()) {}
62 
64  std::vector<std::string> &moduleLabels,
65  std::vector<std::string> &stepLabels) const {
66  auto const &hltFilters = hltConfig_.saveTagsModules(path);
67 
68  moduleLabels.clear();
69  moduleLabels.reserve(hltFilters.size());
70 
71  stepLabels.clear();
72  stepLabels.reserve(hltFilters.size() + 1);
73 
74  for (auto const &module : hltFilters) {
75  if (module.find("Filtered") == std::string::npos)
76  continue;
77 
78  auto const step_label = stepLabel(module);
79  if (step_label.empty() or std::find(stepLabels.begin(), stepLabels.end(), step_label) != stepLabels.end())
80  continue;
81 
82  moduleLabels.emplace_back(module);
83  stepLabels.emplace_back(step_label);
84  }
85 
86  if (stepLabels.empty()) {
87  return;
88  }
89 
90  if (stepLabels[0] != "L1" and std::find(stepLabels.begin(), stepLabels.end(), "L1") != stepLabels.end()) {
91  edm::LogWarning wrn("HLTMuonValidator");
92  wrn << "Unsupported list of 'step' labels (the label 'L1' is present, but is not the first one): stepLabels=(";
93  for (auto const &foo : stepLabels)
94  wrn << " " << foo;
95  wrn << " )";
96 
97  moduleLabels.clear();
98  stepLabels.clear();
99  return;
100  }
101 
102  stepLabels.insert(stepLabels.begin(), "All");
103 }
104 
106  if (module.find("IsoFiltered") != std::string::npos) {
107  return (module.find("L3") != std::string::npos) ? "L3TkIso" : "L2Iso";
108  } else if (module.find("pfecalIsoRhoFiltered") != std::string::npos) {
109  if (module.find("L3") != std::string::npos)
110  return "L3EcalIso";
111  else if (module.find("TkFiltered") != std::string::npos)
112  return "TkEcalIso";
113  } else if (module.find("pfhcalIsoRhoFiltered") != std::string::npos) {
114  if (module.find("L3") != std::string::npos)
115  return "L3HcalIso";
116  else if (module.find("TkFiltered") != std::string::npos)
117  return "TkHcalIso";
118  } else if (module.find("TkFiltered") != std::string::npos)
119  return "Tk";
120  else if (module.find("L3") != std::string::npos)
121  return "L3";
122  else if (module.find("L2") != std::string::npos)
123  return "L2";
124  else if (module.find("L1") != std::string::npos)
125  return "L1";
126 
127  return "";
128 }
129 
130 void HLTMuonValidator::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
131  // Initialize hltConfig
132  bool changedConfig;
133  if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
134  edm::LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
135  return;
136  }
137 
138  // Get the set of trigger paths we want to make plots for
139  std::set<std::string> hltPaths;
140  for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
141  TPRegexp pattern(hltPathsToCheck_[i]);
142  for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
143  if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
144  hltPaths.insert(hltConfig_.triggerNames()[j]);
145  }
146 
147  // Initialize the analyzers
148  analyzers_.clear();
149  std::set<std::string>::iterator iPath;
150  for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
151  const std::string &path = *iPath;
152  std::string shortpath = path;
153  if (path.rfind("_v") < path.length())
154  shortpath = path.substr(0, path.rfind("_v"));
155 
156  std::vector<std::string> labels;
157  std::vector<std::string> steps;
159 
160  if (!labels.empty() && !steps.empty()) {
163  analyzers_.push_back(analyzer);
164  }
165  }
166 }
167 
169  // Call the beginRun (which books all the histograms)
170  for (auto &analyzer : analyzers_) {
171  analyzer.beginRun(iBooker, iRun, iSetup);
172  }
173 }
174 
176  for (auto &analyzer : analyzers_) {
177  analyzer.analyze(iEvent, iSetup);
178  }
179 }
180 
181 // define this as a plug-in
void fillLabels(std::string const &path, std::vector< std::string > &moduleLabels, std::vector< std::string > &stepLabels) const
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_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string stepLabel(std::string const &moduleLabel) const
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_
HLT enums.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
HLTMuonValidator(const edm::ParameterSet &)
const std::vector< std::string > & saveTagsModules(unsigned int trigger) const
Definition: Run.h:45