CMS 3D CMS Logo

TriggerBxMonitor.cc
Go to the documentation of this file.
1 // C++ headers
2 #include <string>
3 #include <cstring>
4 
5 // boost headers
6 #include <boost/regex.hpp>
7 #include <boost/format.hpp>
8 
9 // Root headers
10 #include <TH1F.h>
11 
12 // CMSSW headers
35 
36 // helper functions
37 template <typename T>
38 static
39 const T & get(const edm::Event & event, const edm::EDGetTokenT<T> & token) {
41  event.getByToken(token, handle);
42  if (not handle.isValid())
43  throw * handle.whyFailed();
44  return * handle.product();
45 }
46 
47 template <typename R, typename T>
48 static
49 const T & get(const edm::EventSetup & setup) {
51  setup.get<R>().get(handle);
52  return * handle.product();
53 }
54 
55 
57 public:
58  explicit TriggerBxMonitor(edm::ParameterSet const &);
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
62 
63 private:
64  virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
65  virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
66  virtual void analyze(edm::Event const &, edm::EventSetup const &) override;
67 
68  // number of bunch crossings
69  static const unsigned int s_bx_range = 3564;
70 
71  // TCDS trigger types
72  // see https://twiki.cern.ch/twiki/bin/viewauth/CMS/TcdsEventRecord
73  static constexpr const char * const s_tcds_trigger_types[] = {
74  "Empty", // 0 - No trigger
75  "Physics", // 1 - GT trigger
76  "Calibration", // 2 - Sequence trigger (calibration)
77  "Random", // 3 - Random trigger
78  "Auxiliary", // 4 - Auxiliary (CPM front panel NIM input) trigger
79  nullptr, // 5 - reserved
80  nullptr, // 6 - reserved
81  nullptr, // 7 - reserved
82  "Cyclic", // 8 - Cyclic trigger
83  "Bunch-pattern", // 9 - Bunch-pattern trigger
84  "Software", // 10 - Software trigger
85  "TTS", // 11 - TTS-sourced trigger
86  nullptr, // 12 - reserved
87  nullptr, // 13 - reserved
88  nullptr, // 14 - reserved
89  nullptr // 15 - reserved
90  };
91 
92  // module configuration
96 
97  // L1T and HLT configuration
100 
101  // L1T and HLT results
103  TH2F * m_l1t_bx_all;
104  TH2F * m_hlt_bx_all;
105  std::vector<TH1F *> m_tcds_bx;
106  std::vector<TH1F *> m_l1t_bx;
107  std::vector<TH1F *> m_hlt_bx;
108 };
109 
110 // definition
112 
113 
115 {
117  desc.addUntracked<edm::InputTag>( "l1tResults", edm::InputTag("gtStage2Digis"));
118  desc.addUntracked<edm::InputTag>( "hltResults", edm::InputTag("TriggerResults"));
119  desc.addUntracked<std::string>( "dqmPath", "HLT/TriggerBx" );
120  descriptions.add("triggerBxMonitor", desc);
121 }
122 
123 
125  // module configuration
126  m_l1t_results( consumes<GlobalAlgBlkBxCollection>( config.getUntrackedParameter<edm::InputTag>( "l1tResults" ) ) ),
127  m_hlt_results( consumes<edm::TriggerResults>( config.getUntrackedParameter<edm::InputTag>( "hltResults" ) ) ),
128  m_dqm_path( config.getUntrackedParameter<std::string>( "dqmPath" ) ),
129  // L1T and HLT configuration
131  m_hltConfig(),
132  // L1T and HLT results
136  m_tcds_bx(),
137  m_l1t_bx(),
138  m_hlt_bx()
139 {
140 }
141 
143 {
144 }
145 
147 {
148  // initialise the TCDS vector
149  m_tcds_bx.clear();
150  m_tcds_bx.resize(sizeof(s_tcds_trigger_types) / sizeof(const char *), nullptr);
151 
152  // cache the L1 trigger menu
153  m_l1tMenu = & get<L1TUtmTriggerMenuRcd, L1TUtmTriggerMenu>(setup);
154  if (m_l1tMenu) {
155  m_l1t_bx.clear();
157  } else {
158  edm::LogError("TriggerBxMonitor") << "failed to read the L1 menu from the EventSetup, the L1 trigger bx distribution will not be monitored";
159  }
160 
161  // initialise the HLTConfigProvider
162  bool changed = true;
164  labelsForToken(m_hlt_results, labels);
165  if (m_hltConfig.init(run, setup, labels.process, changed)) {
166  m_hlt_bx.clear();
167  m_hlt_bx.resize( m_hltConfig.size(), nullptr );
168  } else {
169  // HLTConfigProvider not initialised, skip the the HLT monitoring
170  edm::LogError("TriggerBxMonitor") << "failed to initialise HLTConfigProvider, the HLT bx distribution will not be monitored";
171  }
172 }
173 
175 {
176  // TCDS trigger type plots
177  {
178  size_t size = sizeof(s_tcds_trigger_types) / sizeof(const char *);
179 
180  // book 2D histogram to monitor all TCDS trigger types in a single plot
181  booker.setCurrentFolder( m_dqm_path );
182  m_tcds_bx_all = booker.book2D("TCDS Trigger Types", "TCDS Trigger Types vs. bunch crossing", s_bx_range + 1, -0.5, s_bx_range + 0.5, size, -0.5, size - 0.5)->getTH2F();
183 
184  // book the individual histograms for the known TCDS trigger types
185  booker.setCurrentFolder( m_dqm_path + "/TCDS" );
186  for (unsigned int i = 0; i < size; ++i) {
187  if (s_tcds_trigger_types[i]) {
188  m_tcds_bx.at(i) = booker.book1D(s_tcds_trigger_types[i], s_tcds_trigger_types[i], s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
189  m_tcds_bx_all->GetYaxis()->SetBinLabel(i+1, s_tcds_trigger_types[i]);
190  }
191  }
192  }
193 
194  // L1T plots
195  if (m_l1tMenu) {
196  // book 2D histogram to monitor all L1 triggers in a single plot
197  booker.setCurrentFolder( m_dqm_path );
198  m_l1t_bx_all = booker.book2D("Level 1 Triggers", "Level 1 Triggers vs. bunch crossing", s_bx_range + 1, -0.5, s_bx_range + 0.5, m_l1t_bx.size(), -0.5, m_l1t_bx.size() - 0.5)->getTH2F();
199 
200  // book the individual histograms for the L1 triggers that are included in the L1 menu
201  booker.setCurrentFolder( m_dqm_path + "/L1T" );
202  for (auto const & keyval: m_l1tMenu->getAlgorithmMap()) {
203  unsigned int bit = keyval.second.getIndex();
204  std::string const & name = (boost::format("%s (bit %d)") % keyval.first % bit).str();
205  m_l1t_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
206  m_l1t_bx_all->GetYaxis()->SetBinLabel(bit+1, keyval.first.c_str());
207  }
208  }
209 
210  // HLT plots
211  if (m_hltConfig.inited()) {
212  // book 2D histogram to monitor all HLT paths in a single plot
213  booker.setCurrentFolder( m_dqm_path );
214  m_hlt_bx_all = booker.book2D("High Level Triggers", "High Level Triggers vs. bunch crossing", s_bx_range + 1, -0.5, s_bx_range + 0.5, m_hltConfig.size(), -0.5, m_hltConfig.size() - 0.5)->getTH2F();
215 
216  // book the individual HLT triggers histograms
217  booker.setCurrentFolder( m_dqm_path + "/HLT" );
218  for (unsigned int i = 0; i < m_hltConfig.size(); ++i) {
220  m_hlt_bx[i] = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
221  m_hlt_bx_all->GetYaxis()->SetBinLabel(i+1, name.c_str());
222  }
223  }
224 }
225 
226 
228 {
229  unsigned int bx = event.bunchCrossing();
230 
231  // monitor the bx distribution for the TCDS trigger types
232  {
233  size_t size = sizeof(s_tcds_trigger_types) / sizeof(const char *);
234  unsigned int type = event.experimentType();
235  if (type < size and m_tcds_bx[type])
236  m_tcds_bx[type]->Fill(bx);
237  m_tcds_bx_all->Fill(bx, type);
238  }
239 
240  // monitor the bx distribution for the L1 triggers
241  if (m_l1tMenu) {
242  auto const & bxvector = get<GlobalAlgBlkBxCollection>(event, m_l1t_results);
243  if (not bxvector.isEmpty(0)) {
244  auto const & results = bxvector.at(0, 0);
245  for (unsigned int i = 0; i < GlobalAlgBlk::maxPhysicsTriggers; ++i)
246  if (results.getAlgoDecisionFinal(i)) {
247  if (m_l1t_bx[i])
248  m_l1t_bx[i]->Fill(bx);
249  m_l1t_bx_all->Fill(bx, i);
250  }
251  }
252  }
253 
254  // monitor the bx distribution for the HLT triggers
255  if (m_hltConfig.inited()) {
256  auto const & hltResults = get<edm::TriggerResults>(event, m_hlt_results);
257  if (hltResults.size() == m_hlt_bx.size()) {
258  for (unsigned int i = 0; i < m_hlt_bx.size(); ++i) {
259  if (hltResults.at(i).accept()) {
260  m_hlt_bx[i]->Fill(bx);
261  m_hlt_bx_all->Fill(bx, i);
262  }
263  }
264  } else {
265  edm::LogWarning("TriggerBxMonitor") << "This should never happen: the number of HLT paths has changed since the beginning of the run";
266  }
267  }
268 }
269 
270 
271 //define this as a plug-in
unsigned int size() const
number of trigger paths in trigger table
size
Write out results.
static const char *const s_tcds_trigger_types[]
HLTConfigProvider m_hltConfig
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
type
Definition: HCALResponse.h:21
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
const std::string & triggerName(unsigned int triggerIndex) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > m_l1t_results
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
Definition: config.py:1
const edm::EDGetTokenT< edm::TriggerResults > m_hlt_results
#define nullptr
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
#define constexpr
static const unsigned int maxPhysicsTriggers
Definition: GlobalAlgBlk.h:52
bool inited() const
Accessors (const methods)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
char const * process
Definition: ProductLabels.h:7
std::vector< TH1F * > m_tcds_bx
std::vector< TH1F * > m_l1t_bx
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
format
Some error handling for the usage.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:74
const std::string m_dqm_path
TriggerBxMonitor(edm::ParameterSet const &)
virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
L1TUtmTriggerMenu const * m_l1tMenu
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
T const * product() const
Definition: Handle.h:81
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
static const unsigned int s_bx_range
TH1F * getTH1F(void) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< TH1F * > m_hlt_bx
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
HLT enums.
std::shared_ptr< cms::Exception > whyFailed() const
Definition: HandleBase.h:106
TH2F * getTH2F(void) const
long double T
virtual void analyze(edm::Event const &, edm::EventSetup const &) override
T const * product() const
Definition: ESHandle.h:86
Definition: event.py:1
Definition: Run.h:42