CMS 3D CMS Logo

TriggerRatesMonitor.cc
Go to the documentation of this file.
1 // Note to self: the implementation uses TH1F's to store the L1 and HLT rates.
2 // Assuming a maximum rate of 100 kHz times a period of 23.31 s, one needs to store counts up to ~2.3e6.
3 // A "float" has 24 bits of precision, so it can store up to 2**24 ~ 16.7e6 without loss of precision.
4 
5 // C++ headers
6 #include <string>
7 #include <cstring>
8 
9 #include <fmt/printf.h>
10 
11 // boost headers
12 #include <boost/regex.hpp>
13 
14 // Root headers
15 #include <TH1F.h>
16 
17 // CMSSW headers
39 
40 namespace {
41 
42  struct RunBasedHistograms {
44  // HLT configuration
45  struct HLTIndices {
46  unsigned int index_l1_seed;
47  unsigned int index_prescale;
48 
49  HLTIndices() : index_l1_seed((unsigned int)-1), index_prescale((unsigned int)-1) {}
50  };
51 
53  std::vector<HLTIndices> hltIndices;
54 
55  std::vector<std::vector<unsigned int>> datasets;
56  std::vector<std::vector<unsigned int>> streams;
57 
58  // L1T and HLT rate plots
59 
60  // per-path HLT plots
61  struct HLTRatesPlots {
62  dqm::reco::MonitorElement *pass_l1_seed;
63  dqm::reco::MonitorElement *pass_prescale;
67  };
68 
69  // overall event count and event types
70  dqm::reco::MonitorElement *events_processed;
71  std::vector<dqm::reco::MonitorElement *> tcds_counts;
72 
73  // L1T triggers
74  std::vector<dqm::reco::MonitorElement *> l1t_counts;
75 
76  // HLT triggers
77  std::vector<std::vector<HLTRatesPlots>> hlt_by_dataset_counts;
78 
79  // datasets
80  std::vector<dqm::reco::MonitorElement *> dataset_counts;
81 
82  // streams
83  std::vector<dqm::reco::MonitorElement *> stream_counts;
84 
85  RunBasedHistograms()
86  : // L1T and HLT configuration
87  hltConfig(),
88  hltIndices(),
89  datasets(),
90  streams(),
91  // overall event count and event types
92  events_processed(),
93  tcds_counts(),
94  // L1T triggers
95  l1t_counts(),
96  // HLT triggers
97  hlt_by_dataset_counts(),
98  // datasets
99  dataset_counts(),
100  // streams
101  stream_counts() {}
102  };
103 } // namespace
104 
105 class TriggerRatesMonitor : public DQMGlobalEDAnalyzer<RunBasedHistograms> {
106 public:
107  explicit TriggerRatesMonitor(edm::ParameterSet const &);
108  ~TriggerRatesMonitor() override = default;
109 
110  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
111 
112 private:
113  void dqmBeginRun(edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override;
115  edm::Run const &,
116  edm::EventSetup const &,
117  RunBasedHistograms &) const override;
118  void dqmAnalyze(edm::Event const &, edm::EventSetup const &, RunBasedHistograms const &) const override;
119 
120  // TCDS trigger types
121  // see https://twiki.cern.ch/twiki/bin/viewauth/CMS/TcdsEventRecord
122  static constexpr const char *const s_tcds_trigger_types[] = {
123  "Empty", // 0 - No trigger
124  "Physics", // 1 - GT trigger
125  "Calibration", // 2 - Sequence trigger (calibration)
126  "Random", // 3 - Random trigger
127  "Auxiliary", // 4 - Auxiliary (CPM front panel NIM input) trigger
128  nullptr, // 5 - reserved
129  nullptr, // 6 - reserved
130  nullptr, // 7 - reserved
131  "Cyclic", // 8 - Cyclic trigger
132  "Bunch-pattern", // 9 - Bunch-pattern trigger
133  "Software", // 10 - Software trigger
134  "TTS", // 11 - TTS-sourced trigger
135  nullptr, // 12 - reserved
136  nullptr, // 13 - reserved
137  nullptr, // 14 - reserved
138  nullptr // 15 - reserved
139  };
140 
141  // module configuration
145  const uint32_t m_lumisections_range;
146 };
147 
148 // definition
149 constexpr const char *const TriggerRatesMonitor::s_tcds_trigger_types[];
150 
153  desc.addUntracked<edm::InputTag>("l1tResults", edm::InputTag("gtStage2Digis"));
154  desc.addUntracked<edm::InputTag>("hltResults", edm::InputTag("TriggerResults"));
155  desc.addUntracked<std::string>("dqmPath", "HLT/TriggerRates");
156  desc.addUntracked<uint32_t>("lumisectionRange", 2500); // ~16 hours
157  descriptions.add("triggerRatesMonitor", desc);
158 }
159 
161  : // module configuration
162  m_l1t_results(consumes<GlobalAlgBlkBxCollection>(config.getUntrackedParameter<edm::InputTag>("l1tResults"))),
163  m_hlt_results(consumes<edm::TriggerResults>(config.getUntrackedParameter<edm::InputTag>("hltResults"))),
164  m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
165  m_lumisections_range(config.getUntrackedParameter<uint32_t>("lumisectionRange")) {}
166 
168  edm::EventSetup const &setup,
169  RunBasedHistograms &histograms) const {
170  histograms.tcds_counts.clear();
171  histograms.tcds_counts.resize(sizeof(s_tcds_trigger_types) / sizeof(const char *));
172 
173  // cache the L1 trigger menu
174  histograms.l1t_counts.clear();
175  histograms.l1t_counts.resize(GlobalAlgBlk::maxPhysicsTriggers);
176 
177  // initialise the HLTConfigProvider
178  bool changed = true;
181  if (histograms.hltConfig.init(run, setup, labels.process, changed)) {
182  histograms.hltIndices.resize(histograms.hltConfig.size());
183 
184  unsigned int datasets = histograms.hltConfig.datasetNames().size();
185  histograms.hlt_by_dataset_counts.clear();
186  histograms.hlt_by_dataset_counts.resize(datasets);
187 
188  histograms.datasets.clear();
189  histograms.datasets.resize(datasets);
190  for (unsigned int i = 0; i < datasets; ++i) {
191  auto const &paths = histograms.hltConfig.datasetContent(i);
192  histograms.hlt_by_dataset_counts[i].resize(paths.size());
193  histograms.datasets[i].reserve(paths.size());
194  for (auto const &path : paths) {
195  histograms.datasets[i].push_back(histograms.hltConfig.triggerIndex(path));
196  }
197  }
198  histograms.dataset_counts.clear();
199  histograms.dataset_counts.resize(datasets);
200 
201  unsigned int streams = histograms.hltConfig.streamNames().size();
202  histograms.streams.clear();
203  histograms.streams.resize(streams);
204  for (unsigned int i = 0; i < streams; ++i) {
205  for (auto const &dataset : histograms.hltConfig.streamContent(i)) {
206  for (auto const &path : histograms.hltConfig.datasetContent(dataset))
207  histograms.streams[i].push_back(histograms.hltConfig.triggerIndex(path));
208  }
209  std::sort(histograms.streams[i].begin(), histograms.streams[i].end());
210  auto unique_end = std::unique(histograms.streams[i].begin(), histograms.streams[i].end());
211  histograms.streams[i].resize(unique_end - histograms.streams[i].begin());
212  histograms.streams[i].shrink_to_fit();
213  }
214  histograms.stream_counts.clear();
215  histograms.stream_counts.resize(streams);
216  } else {
217  // HLTConfigProvider not initialised, skip the the HLT monitoring
218  edm::LogError("TriggerRatesMonitor")
219  << "failed to initialise HLTConfigProvider, the HLT trigger and datasets rates will not be monitored";
220  }
221 }
222 
224  edm::Run const &run,
225  edm::EventSetup const &setup,
226  RunBasedHistograms &histograms) const {
227  // book the overall event count and event types histograms
229  histograms.events_processed = booker.book1D(
230  "events", "Processed events vs. lumisection", m_lumisections_range + 1, -0.5, m_lumisections_range + 0.5);
231  booker.setCurrentFolder(m_dqm_path + "/TCDS");
232  for (unsigned int i = 0; i < sizeof(s_tcds_trigger_types) / sizeof(const char *); ++i)
233  if (s_tcds_trigger_types[i]) {
234  std::string const &title = fmt::sprintf("%s events vs. lumisection", s_tcds_trigger_types[i]);
235  histograms.tcds_counts[i] =
237  }
238 
239  // book the rate histograms for the L1 triggers that are included in the L1 menu
240  booker.setCurrentFolder(m_dqm_path + "/L1T");
241  auto const &l1tMenu = edm::get<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>(setup);
242  for (auto const &keyval : l1tMenu.getAlgorithmMap()) {
243  unsigned int bit = keyval.second.getIndex();
244  bool masked = false; // FIXME read L1 masks once they will be avaiable in the EventSetup
245  std::string const &name = fmt::sprintf("%s (bit %d)", keyval.first, bit);
246  std::string const &title =
247  fmt::sprintf("%s (bit %d)%s vs. lumisection", keyval.first, bit, (masked ? " (masked)" : ""));
248  histograms.l1t_counts.at(bit) =
249  booker.book1D(name, title, m_lumisections_range + 1, -0.5, m_lumisections_range + 0.5);
250  }
251 
252  if (histograms.hltConfig.inited()) {
253  auto const &datasets = histograms.hltConfig.datasetNames();
254 
255  // book the rate histograms for the HLT triggers
256  for (unsigned int d = 0; d < datasets.size(); ++d) {
257  booker.setCurrentFolder(m_dqm_path + "/HLT/" + datasets[d]);
258  for (unsigned int i = 0; i < histograms.datasets[d].size(); ++i) {
259  unsigned int index = histograms.datasets[d][i];
260  std::string const &name = histograms.hltConfig.triggerName(index);
261  histograms.hlt_by_dataset_counts[d][i].pass_l1_seed = booker.book1D(name + "_pass_L1_seed",
262  name + " pass L1 seed, vs. lumisection",
264  -0.5,
265  m_lumisections_range + 0.5);
266  histograms.hlt_by_dataset_counts[d][i].pass_prescale = booker.book1D(name + "_pass_prescaler",
267  name + " pass prescaler, vs. lumisection",
269  -0.5,
270  m_lumisections_range + 0.5);
271  histograms.hlt_by_dataset_counts[d][i].accept = booker.book1D(name + "_accept",
272  name + " accept, vs. lumisection",
274  -0.5,
275  m_lumisections_range + 0.5);
276  histograms.hlt_by_dataset_counts[d][i].reject = booker.book1D(name + "_reject",
277  name + " reject, vs. lumisection",
279  -0.5,
280  m_lumisections_range + 0.5);
281  histograms.hlt_by_dataset_counts[d][i].error = booker.book1D(name + "_error",
282  name + " error, vs. lumisection",
284  -0.5,
285  m_lumisections_range + 0.5);
286  }
287 
288  // booker.setCurrentFolder( m_dqm_path + "/HLT/" + datasets[d]);
289  for (unsigned int i : histograms.datasets[d]) {
290  // look for the index of the (last) L1 seed and prescale module in each path
291  histograms.hltIndices[i].index_l1_seed = histograms.hltConfig.size(i);
292  histograms.hltIndices[i].index_prescale = histograms.hltConfig.size(i);
293  for (unsigned int j = 0; j < histograms.hltConfig.size(i); ++j) {
294  std::string const &label = histograms.hltConfig.moduleLabel(i, j);
295  std::string const &type = histograms.hltConfig.moduleType(label);
296  if (type == "HLTL1TSeed" or type == "HLTLevel1GTSeed" or type == "HLTLevel1Activity" or
297  type == "HLTLevel1Pattern") {
298  // there might be more L1 seed filters in sequence
299  // keep looking and store the index of the last one
300  histograms.hltIndices[i].index_l1_seed = j;
301  } else if (type == "HLTPrescaler") {
302  // there should be only one prescaler in a path, and it should follow all L1 seed filters
303  histograms.hltIndices[i].index_prescale = j;
304  break;
305  }
306  }
307  }
308  }
309 
310  // book the HLT datasets rate histograms
311  booker.setCurrentFolder(m_dqm_path + "/Datasets");
312  for (unsigned int i = 0; i < datasets.size(); ++i)
313  histograms.dataset_counts[i] =
314  booker.book1D(datasets[i], datasets[i], m_lumisections_range + 1, -0.5, m_lumisections_range + 0.5);
315 
316  // book the HLT streams rate histograms
317  booker.setCurrentFolder(m_dqm_path + "/Streams");
318  auto const &streams = histograms.hltConfig.streamNames();
319  for (unsigned int i = 0; i < streams.size(); ++i)
320  histograms.stream_counts[i] =
321  booker.book1D(streams[i], streams[i], m_lumisections_range + 1, -0.5, m_lumisections_range + 0.5);
322  }
323 }
324 
326  edm::EventSetup const &setup,
327  RunBasedHistograms const &histograms) const {
328  unsigned int lumisection = event.luminosityBlock();
329 
330  // monitor the overall event count and event types rates
331  histograms.events_processed->Fill(lumisection);
332  if (histograms.tcds_counts[event.experimentType()])
333  histograms.tcds_counts[event.experimentType()]->Fill(lumisection);
334 
335  // monitor the L1 triggers rates
336  auto const &bxvector = edm::get(event, m_l1t_results);
337  if (not bxvector.isEmpty(0)) {
338  auto const &results = bxvector.at(0, 0);
339  for (unsigned int i = 0; i < GlobalAlgBlk::maxPhysicsTriggers; ++i)
340  if (results.getAlgoDecisionFinal(i))
341  if (histograms.l1t_counts[i])
342  histograms.l1t_counts[i]->Fill(lumisection);
343  }
344 
345  // monitor the HLT triggers and datsets rates
346  if (histograms.hltConfig.inited()) {
348  if (hltResults.size() == histograms.hltIndices.size()) {
349  } else {
350  edm::LogWarning("TriggerRatesMonitor")
351  << "This should never happen: the number of HLT paths has changed since the beginning of the run";
352  }
353 
354  for (unsigned int d = 0; d < histograms.datasets.size(); ++d) {
355  for (unsigned int i : histograms.datasets[d])
356  if (hltResults.at(i).accept()) {
357  histograms.dataset_counts[d]->Fill(lumisection);
358  // ensure each dataset is incremented only once per event
359  break;
360  }
361  for (unsigned int i = 0; i < histograms.datasets[d].size(); ++i) {
362  unsigned int index = histograms.datasets[d][i];
364 
365  if (path.index() > histograms.hltIndices[index].index_l1_seed)
366  histograms.hlt_by_dataset_counts[d][i].pass_l1_seed->Fill(lumisection);
367  if (path.index() > histograms.hltIndices[index].index_prescale)
368  histograms.hlt_by_dataset_counts[d][i].pass_prescale->Fill(lumisection);
369  if (path.accept())
370  histograms.hlt_by_dataset_counts[d][i].accept->Fill(lumisection);
371  else if (path.error())
372  histograms.hlt_by_dataset_counts[d][i].error->Fill(lumisection);
373  else
374  histograms.hlt_by_dataset_counts[d][i].reject->Fill(lumisection);
375  }
376  }
377 
378  for (unsigned int i = 0; i < histograms.streams.size(); ++i)
379  for (unsigned int j : histograms.streams[i])
380  if (hltResults.at(j).accept()) {
381  histograms.stream_counts[i]->Fill(lumisection);
382  // ensure each stream is incremented only once per event
383  break;
384  }
385  }
386 }
387 
388 //define this as a plug-in
ConfigurationDescriptions.h
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
TriggerRatesMonitor::dqmAnalyze
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, RunBasedHistograms const &) const override
Definition: TriggerRatesMonitor.cc:325
dqm::impl::MonitorElement
Definition: MonitorElement.h:99
Handle.h
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
ESHandle.h
TriggerResults.h
TriggerRatesMonitor::TriggerRatesMonitor
TriggerRatesMonitor(edm::ParameterSet const &)
Definition: TriggerRatesMonitor.cc:160
PDWG_DiJetAODSkim_cff.hltResults
hltResults
Definition: PDWG_DiJetAODSkim_cff.py:7
TriggerRatesMonitor::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TriggerRatesMonitor.cc:151
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
TriggerRatesMonitor::dqmBeginRun
void dqmBeginRun(edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override
Definition: TriggerRatesMonitor.cc:167
TriggerRatesMonitor::m_lumisections_range
const uint32_t m_lumisections_range
Definition: TriggerRatesMonitor.cc:145
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
TriggerRatesMonitor
Definition: TriggerRatesMonitor.cc:105
bookConverter.results
results
Definition: bookConverter.py:144
DQMStore.h
TriggerRatesMonitor::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override
Definition: TriggerRatesMonitor.cc:223
relativeConstraints.error
error
Definition: relativeConstraints.py:53
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
BXVector
Definition: BXVector.h:15
config
Definition: config.py:1
accept
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ProcessHistory.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
TriggerRatesMonitor::~TriggerRatesMonitor
~TriggerRatesMonitor() override=default
contentValuesFiles.datasets
datasets
Definition: contentValuesFiles.py:49
Service.h
Run.h
ParameterSetDescription.h
HLT_Fake1_cff.streams
streams
Definition: HLT_Fake1_cff.py:13
TriggerRatesMonitor::m_hlt_results
const edm::EDGetTokenT< edm::TriggerResults > m_hlt_results
Definition: TriggerRatesMonitor.cc:143
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
L1TUtmTriggerMenu.h
L1TUtmTriggerMenuRcd.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:679
edm::HLTPathStatus
Definition: HLTPathStatus.h:33
createfilelist.int
int
Definition: createfilelist.py:10
GlobalAlgBlk.h
edm::EventSetup
Definition: EventSetup.h:58
histograms
Definition: histograms.py:1
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HLTConfigProvider.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::EDConsumerBase::labelsForToken
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
Definition: EDConsumerBase.cc:338
Registry.h
TriggerRatesMonitor::m_dqm_path
const std::string m_dqm_path
Definition: TriggerRatesMonitor.cc:144
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HLTConfigProvider
Definition: HLTConfigProvider.h:29
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
Frameworkfwd.h
reject
const auto reject
Definition: CAHitNtupletGeneratorKernelsImpl.h:619
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
or
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
HltComparatorCreateWorkflow.hltConfig
hltConfig
Definition: HltComparatorCreateWorkflow.py:161
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: SiPixelSCurveCalibrationAnalysis.h:55
dqm::implementation::IBooker
Definition: DQMStore.h:43
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
dataset
Definition: dataset.py:1
ztail.d
d
Definition: ztail.py:151
DQMGlobalEDAnalyzer
Definition: DQMGlobalEDAnalyzer.h:76
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
TriggerRatesMonitor::s_tcds_trigger_types
static constexpr const char *const s_tcds_trigger_types[]
Definition: TriggerRatesMonitor.cc:122
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
GlobalAlgBlk::maxPhysicsTriggers
static constexpr unsigned int maxPhysicsTriggers
Definition: GlobalAlgBlk.h:52
event
Definition: event.py:1
HLTObjectsMonitor_cfi.TriggerResults
TriggerResults
Definition: HLTObjectsMonitor_cfi.py:9
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::TriggerResults
Definition: TriggerResults.h:35
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::ProductLabels
Definition: ProductLabels.h:4
TriggerRatesMonitor::m_l1t_results
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > m_l1t_results
Definition: TriggerRatesMonitor.cc:142
DQMGlobalEDAnalyzer.h