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 // {fmt} headers
7 #include <fmt/printf.h>
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
115 constexpr const char* TriggerBxMonitor::s_tcds_trigger_types[];
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();
154  }
155  if (m_make_2d_plots) {
156  histograms.l1t_bx_2d.clear();
158  }
159 
160  // initialise the HLTConfigProvider
161  bool changed = true;
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) =
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 = fmt::sprintf("%s (bit %d)", keyval.first, bit);
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
ConfigurationDescriptions.h
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
TriggerBxMonitor::TriggerBxMonitor
TriggerBxMonitor(edm::ParameterSet const &)
Definition: TriggerBxMonitor.cc:128
L1TUtmTriggerMenuRcd.h
TriggerBxMonitor::m_make_1d_plots
const bool m_make_1d_plots
Definition: TriggerBxMonitor.cc:109
MessageLogger.h
ESHandle.h
TriggerResults.h
PDWG_DiJetAODSkim_cff.hltResults
hltResults
Definition: PDWG_DiJetAODSkim_cff.py:7
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
TriggerBxMonitor::m_dqm_path
const std::string m_dqm_path
Definition: TriggerBxMonitor.cc:108
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
bookConverter.results
results
Definition: bookConverter.py:144
DQMStore.h
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
BXVector
Definition: BXVector.h:15
config
Definition: config.py:1
MakerMacros.h
TriggerBxMonitor::s_bx_range
static const unsigned int s_bx_range
Definition: TriggerBxMonitor.cc:82
TriggerBxMonitor::m_make_2d_plots
const bool m_make_2d_plots
Definition: TriggerBxMonitor.cc:110
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
TriggerBxMonitor::dqmAnalyze
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, RunBasedHistograms const &) const override
Definition: TriggerBxMonitor.cc:278
Service.h
Run.h
ParameterSetDescription.h
TriggerBxMonitor::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TriggerBxMonitor.cc:117
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TriggerBxMonitor::~TriggerBxMonitor
~TriggerBxMonitor() override=default
L1TUtmTriggerMenu.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
TriggerBxMonitor
Definition: TriggerBxMonitor.cc:69
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:675
TriggerBxMonitor::m_hlt_results
const edm::EDGetTokenT< edm::TriggerResults > m_hlt_results
Definition: TriggerBxMonitor.cc:107
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
edm::EDConsumerBase::labelsForToken
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
Definition: EDConsumerBase.cc:338
Registry.h
TriggerBxMonitor::m_l1t_results
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > m_l1t_results
Definition: TriggerBxMonitor.cc:106
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
TriggerBxMonitor::dqmBeginRun
void dqmBeginRun(edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override
Definition: TriggerBxMonitor.cc:137
Frameworkfwd.h
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
HltComparatorCreateWorkflow.hltConfig
hltConfig
Definition: HltComparatorCreateWorkflow.py:161
MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: SiPixelSCurveCalibrationAnalysis.h:55
dqm::implementation::IBooker
Definition: DQMStore.h:43
DQMGlobalEDAnalyzer
Definition: DQMGlobalEDAnalyzer.h:76
ParameterSet.h
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
TriggerBxMonitor::s_tcds_trigger_types
static constexpr const char * s_tcds_trigger_types[]
Definition: TriggerBxMonitor.cc:86
TriggerBxMonitor::m_ls_range
const uint32_t m_ls_range
Definition: TriggerBxMonitor.cc:111
edm::InputTag
Definition: InputTag.h:15
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
TriggerBxMonitor::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, RunBasedHistograms &) const override
Definition: TriggerBxMonitor.cc:180
edm::ProductLabels
Definition: ProductLabels.h:4
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
DQMGlobalEDAnalyzer.h