CMS 3D CMS Logo

TriggerBxMonitor.cc
Go to the documentation of this file.
1 // C++ headers
2 #include <cstring>
3 #include <iterator>
4 #include <string>
5 
6 // boost headers
7 #include <boost/format.hpp>
8 
9 // CMSSW headers
31 
32 namespace {
33 
34  struct RunBasedHistograms {
35  public:
37  RunBasedHistograms()
38  : // L1T and HLT configuration
39  hltConfig(),
40  // L1T and HLT results
41  tcds_bx_all(nullptr),
42  l1t_bx_all(nullptr),
43  hlt_bx_all(nullptr),
44  tcds_bx(),
45  l1t_bx(),
46  hlt_bx(),
47  tcds_bx_2d(),
48  l1t_bx_2d(),
49  hlt_bx_2d() {}
50 
51  public:
52  // HLT configuration
54 
55  // L1T and HLT results
56  dqm::reco::MonitorElement* tcds_bx_all;
57  dqm::reco::MonitorElement* l1t_bx_all;
58  dqm::reco::MonitorElement* hlt_bx_all;
59  std::vector<dqm::reco::MonitorElement*> tcds_bx;
60  std::vector<dqm::reco::MonitorElement*> l1t_bx;
61  std::vector<dqm::reco::MonitorElement*> hlt_bx;
62  std::vector<dqm::reco::MonitorElement*> tcds_bx_2d;
63  std::vector<dqm::reco::MonitorElement*> l1t_bx_2d;
64  std::vector<dqm::reco::MonitorElement*> hlt_bx_2d;
65  };
66 
67 } // namespace
68 
69 class TriggerBxMonitor : public DQMGlobalEDAnalyzer<RunBasedHistograms> {
70 public:
71  explicit TriggerBxMonitor(edm::ParameterSet const&);
72  ~TriggerBxMonitor() override = default;
73 
74  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
75 
76 private:
77  void dqmBeginRun(edm::Run const&, edm::EventSetup const&, RunBasedHistograms&) const override;
78  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&, RunBasedHistograms&) const override;
79  void dqmAnalyze(edm::Event const&, edm::EventSetup const&, RunBasedHistograms const&) const override;
80 
81  // number of bunch crossings
82  static const unsigned int s_bx_range = 3564;
83 
84  // TCDS trigger types
85  // see https://twiki.cern.ch/twiki/bin/viewauth/CMS/TcdsEventRecord
86  static constexpr const char* s_tcds_trigger_types[] = {
87  "Empty", // 0 - No trigger
88  "Physics", // 1 - GT trigger
89  "Calibration", // 2 - Sequence trigger (calibration)
90  "Random", // 3 - Random trigger
91  "Auxiliary", // 4 - Auxiliary (CPM front panel NIM input) trigger
92  nullptr, // 5 - reserved
93  nullptr, // 6 - reserved
94  nullptr, // 7 - reserved
95  "Cyclic", // 8 - Cyclic trigger
96  "Bunch-pattern", // 9 - Bunch-pattern trigger
97  "Software", // 10 - Software trigger
98  "TTS", // 11 - TTS-sourced trigger
99  nullptr, // 12 - reserved
100  nullptr, // 13 - reserved
101  nullptr, // 14 - reserved
102  nullptr // 15 - reserved
103  };
104 
105  // module configuration
109  const bool m_make_1d_plots;
110  const bool m_make_2d_plots;
111  const uint32_t m_ls_range;
112 };
113 
114 // definition
116 
119  desc.addUntracked<edm::InputTag>("l1tResults", edm::InputTag("gtStage2Digis"));
120  desc.addUntracked<edm::InputTag>("hltResults", edm::InputTag("TriggerResults"));
121  desc.addUntracked<std::string>("dqmPath", "HLT/TriggerBx");
122  desc.addUntracked<bool>("make1DPlots", true);
123  desc.addUntracked<bool>("make2DPlots", false);
124  desc.addUntracked<uint32_t>("lsRange", 4000);
125  descriptions.add("triggerBxMonitor", desc);
126 }
127 
129  : // module configuration
130  m_l1t_results(consumes<GlobalAlgBlkBxCollection>(config.getUntrackedParameter<edm::InputTag>("l1tResults"))),
131  m_hlt_results(consumes<edm::TriggerResults>(config.getUntrackedParameter<edm::InputTag>("hltResults"))),
132  m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
133  m_make_1d_plots(config.getUntrackedParameter<bool>("make1DPlots")),
134  m_make_2d_plots(config.getUntrackedParameter<bool>("make2DPlots")),
135  m_ls_range(config.getUntrackedParameter<uint32_t>("lsRange")) {}
136 
138  edm::EventSetup const& setup,
139  RunBasedHistograms& histograms) const {
140  // initialise the TCDS vector
141  if (m_make_1d_plots) {
142  histograms.tcds_bx.clear();
143  histograms.tcds_bx.resize(std::size(s_tcds_trigger_types));
144  }
145  if (m_make_2d_plots) {
146  histograms.tcds_bx_2d.clear();
147  histograms.tcds_bx_2d.resize(std::size(s_tcds_trigger_types));
148  }
149 
150  // cache the L1 trigger menu
151  if (m_make_1d_plots) {
152  histograms.l1t_bx.clear();
153  histograms.l1t_bx.resize(GlobalAlgBlk::maxPhysicsTriggers);
154  }
155  if (m_make_2d_plots) {
156  histograms.l1t_bx_2d.clear();
157  histograms.l1t_bx_2d.resize(GlobalAlgBlk::maxPhysicsTriggers);
158  }
159 
160  // initialise the HLTConfigProvider
161  bool changed = true;
163  labelsForToken(m_hlt_results, labels);
164  if (histograms.hltConfig.init(run, setup, labels.process, changed)) {
165  if (m_make_1d_plots) {
166  histograms.hlt_bx.clear();
167  histograms.hlt_bx.resize(histograms.hltConfig.size());
168  }
169  if (m_make_2d_plots) {
170  histograms.hlt_bx_2d.clear();
171  histograms.hlt_bx_2d.resize(histograms.hltConfig.size());
172  }
173  } else {
174  // HLTConfigProvider not initialised, skip the the HLT monitoring
175  edm::LogError("TriggerBxMonitor")
176  << "failed to initialise HLTConfigProvider, the HLT bx distribution will not be monitored";
177  }
178 }
179 
181  edm::Run const& run,
182  edm::EventSetup const& setup,
183  RunBasedHistograms& histograms) const {
184  // TCDS trigger type plots
185  {
187 
188  // book 2D histogram to monitor all TCDS trigger types in a single plot
190  histograms.tcds_bx_all = booker.book2D("TCDS Trigger Types",
191  "TCDS Trigger Types vs. bunch crossing",
192  s_bx_range + 1,
193  -0.5,
194  s_bx_range + 0.5,
195  size,
196  -0.5,
197  size - 0.5);
198 
199  // book the individual histograms for the known TCDS trigger types
200  booker.setCurrentFolder(m_dqm_path + "/TCDS");
201  for (unsigned int i = 0; i < size; ++i) {
202  if (s_tcds_trigger_types[i]) {
203  if (m_make_1d_plots) {
204  histograms.tcds_bx.at(i) =
205  booker.book1D(s_tcds_trigger_types[i], s_tcds_trigger_types[i], s_bx_range + 1, -0.5, s_bx_range + 0.5);
206  }
207  if (m_make_2d_plots) {
208  std::string const& name_ls = std::string(s_tcds_trigger_types[i]) + " vs LS";
209  histograms.tcds_bx_2d.at(i) = booker.book2D(
210  name_ls, name_ls, s_bx_range + 1, -0.5, s_bx_range + 0.5, m_ls_range, 0.5, m_ls_range + 0.5);
211  }
212  histograms.tcds_bx_all->setBinLabel(i + 1, s_tcds_trigger_types[i], 2); // Y axis
213  }
214  }
215  }
216 
217  // L1T plots
218  {
219  // book 2D histogram to monitor all L1 triggers in a single plot
221  histograms.l1t_bx_all = booker.book2D("Level 1 Triggers",
222  "Level 1 Triggers vs. bunch crossing",
223  s_bx_range + 1,
224  -0.5,
225  s_bx_range + 0.5,
227  -0.5,
229 
230  // book the individual histograms for the L1 triggers that are included in the L1 menu
231  booker.setCurrentFolder(m_dqm_path + "/L1T");
232  auto const& l1tMenu = edm::get<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>(setup);
233  for (auto const& keyval : l1tMenu.getAlgorithmMap()) {
234  unsigned int bit = keyval.second.getIndex();
235  std::string const& name = (boost::format("%s (bit %d)") % keyval.first % bit).str();
236  if (m_make_1d_plots) {
237  histograms.l1t_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5);
238  }
239  if (m_make_2d_plots) {
240  std::string const& name_ls = name + " vs LS";
241  histograms.l1t_bx_2d.at(bit) =
242  booker.book2D(name_ls, name_ls, s_bx_range + 1, -0.5, s_bx_range + 0.5, m_ls_range, 0.5, m_ls_range + 0.5);
243  }
244  histograms.l1t_bx_all->setBinLabel(bit + 1, keyval.first, 2); // Y axis
245  }
246  }
247 
248  // HLT plots
249  if (histograms.hltConfig.inited()) {
250  // book 2D histogram to monitor all HLT paths in a single plot
252  histograms.hlt_bx_all = booker.book2D("High Level Triggers",
253  "High Level Triggers vs. bunch crossing",
254  s_bx_range + 1,
255  -0.5,
256  s_bx_range + 0.5,
257  histograms.hltConfig.size(),
258  -0.5,
259  histograms.hltConfig.size() - 0.5);
260 
261  // book the individual HLT triggers histograms
262  booker.setCurrentFolder(m_dqm_path + "/HLT");
263  for (unsigned int i = 0; i < histograms.hltConfig.size(); ++i) {
264  std::string const& name = histograms.hltConfig.triggerName(i);
265  if (m_make_1d_plots) {
266  histograms.hlt_bx[i] = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5);
267  }
268  if (m_make_2d_plots) {
269  std::string const& name_ls = name + " vs LS";
270  histograms.hlt_bx_2d[i] =
271  booker.book2D(name_ls, name_ls, s_bx_range + 1, -0.5, s_bx_range + 0.5, m_ls_range, 0.5, m_ls_range + 0.5);
272  }
273  histograms.hlt_bx_all->setBinLabel(i + 1, name, 2); // Y axis
274  }
275  }
276 }
277 
279  edm::EventSetup const& setup,
280  RunBasedHistograms const& histograms) const {
281  unsigned int bx = event.bunchCrossing();
282  unsigned int ls = event.luminosityBlock();
283 
284  // monitor the bx distribution for the TCDS trigger types
285  {
287  unsigned int type = event.experimentType();
288  if (type < size) {
289  if (m_make_1d_plots and histograms.tcds_bx.at(type))
290  histograms.tcds_bx[type]->Fill(bx);
291  if (m_make_2d_plots and histograms.tcds_bx_2d.at(type))
292  histograms.tcds_bx_2d[type]->Fill(bx, ls);
293  }
294  histograms.tcds_bx_all->Fill(bx, type);
295  }
296 
297  // monitor the bx distribution for the L1 triggers
298  {
299  auto const& bxvector = edm::get(event, m_l1t_results);
300  if (not bxvector.isEmpty(0)) {
301  auto const& results = bxvector.at(0, 0);
302  for (unsigned int i = 0; i < GlobalAlgBlk::maxPhysicsTriggers; ++i)
303  if (results.getAlgoDecisionFinal(i)) {
304  if (m_make_1d_plots and histograms.l1t_bx.at(i))
305  histograms.l1t_bx[i]->Fill(bx);
306  if (m_make_2d_plots and histograms.l1t_bx_2d.at(i))
307  histograms.l1t_bx_2d[i]->Fill(bx, ls);
308  histograms.l1t_bx_all->Fill(bx, i);
309  }
310  }
311  }
312 
313  // monitor the bx distribution for the HLT triggers
314  if (histograms.hltConfig.inited()) {
315  auto const& hltResults = edm::get(event, m_hlt_results);
316  for (unsigned int i = 0; i < hltResults.size(); ++i) {
317  if (hltResults.at(i).accept()) {
318  if (m_make_1d_plots and histograms.hlt_bx.at(i))
319  histograms.hlt_bx[i]->Fill(bx);
320  if (m_make_2d_plots and histograms.hlt_bx_2d.at(i))
321  histograms.hlt_bx_2d[i]->Fill(bx, ls);
322  histograms.hlt_bx_all->Fill(bx, i);
323  }
324  }
325  }
326 }
327 
328 //define this as a plug-in
size
Write out results.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
type
Definition: HCALResponse.h:21
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void dqmBeginRun(edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > m_l1t_results
#define nullptr
Definition: config.py:1
const edm::EDGetTokenT< edm::TriggerResults > m_hlt_results
char const * process
Definition: ProductLabels.h:7
static const char * s_tcds_trigger_types[]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
example_global void dqmAnalyze(edm::Event const &,@example_global edm::EventSetup const &,@example_global Histograms___class__ const &) const override
const uint32_t m_ls_range
const std::string m_dqm_path
TriggerBxMonitor(edm::ParameterSet const &)
def ls(path, rec=False)
Definition: eostools.py:349
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static unsigned int maxPhysicsTriggers
Definition: GlobalAlgBlk.h:52
dqm::legacy::MonitorElement MonitorElement
T const & get(Event const &event, InputTag const &tag)(false)
Definition: Event.h:666
const bool m_make_1d_plots
example_stream void bookHistograms(DQMStore::IBooker &,@example_stream edm::Run const &,@example_stream edm::EventSetup const &) override
static const unsigned int s_bx_range
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
#define str(s)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override
const bool m_make_2d_plots
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, RunBasedHistograms const &) const override
#define constexpr
Definition: event.py:1
Definition: Run.h:45