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