CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
37 
38 // helper functions
39 template <typename T>
40 static
41 const T * get(const edm::Event & event, const edm::EDGetTokenT<T> & token) {
43  event.getByToken(token, handle);
44  if (not handle.isValid())
45  throw * handle.whyFailed();
46  return handle.product();
47 }
48 
49 template <typename R, typename T>
50 static
51 const T * get(const edm::EventSetup & setup) {
53  setup.get<R>().get(handle);
54  return handle.product();
55 }
56 
57 
59 public:
60  explicit TriggerBxMonitor(edm::ParameterSet const &);
62 
63  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
64 
65 private:
66  virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
67  virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
68  virtual void analyze(edm::Event const &, edm::EventSetup const &) override;
69 
70  // number of bunch crossings
71  static const unsigned int s_bx_range = 4000;
72 
73  // module configuration
77 
82 
83  // L1T triggers
84  std::vector<TH1F *> m_l1t_algo_bx;
85  std::vector<TH1F *> m_l1t_tech_bx;
86 
87  // HLT triggers
88  std::vector<TH1F *> m_hlt_bx;
89 };
90 
91 
92 
94 {
96  desc.addUntracked<edm::InputTag>( "l1tResults", edm::InputTag("gtDigis"));
97  desc.addUntracked<edm::InputTag>( "hltResults", edm::InputTag("TriggerResults"));
98  desc.addUntracked<std::string>( "dqmPath", "HLT/TriggerBx" );
99  descriptions.add("triggerBxMonitor", desc);
100 }
101 
102 
104  // module configuration
105  m_l1t_results( consumes<L1GlobalTriggerReadoutRecord>( config.getUntrackedParameter<edm::InputTag>( "l1tResults" ) ) ),
106  m_hlt_results( consumes<edm::TriggerResults>( config.getUntrackedParameter<edm::InputTag>( "hltResults" ) ) ),
107  m_dqm_path( config.getUntrackedParameter<std::string>( "dqmPath" ) ),
108  // L1T and HLT configuration
109  m_l1tMenu( nullptr ),
110  m_l1tAlgoMask( nullptr ),
111  m_l1tTechMask( nullptr),
112  m_hltConfig(),
113  // L1T triggers
114  m_l1t_algo_bx(),
115  m_l1t_tech_bx(),
116  // HLT triggers
117  m_hlt_bx()
118 {
119 }
120 
122 {
123 }
124 
126 {
127  // cache the L1 trigger menu
128  m_l1tMenu = get<L1GtTriggerMenuRcd, L1GtTriggerMenu>(setup);
129  m_l1tAlgoMask = get<L1GtTriggerMaskAlgoTrigRcd, L1GtTriggerMask>(setup);
130  m_l1tTechMask = get<L1GtTriggerMaskTechTrigRcd, L1GtTriggerMask>(setup);
131  if (m_l1tMenu and m_l1tAlgoMask and m_l1tTechMask) {
132  m_l1t_algo_bx.clear();
133  m_l1t_algo_bx.resize( m_l1tAlgoMask->gtTriggerMask().size(), nullptr );
134  m_l1t_tech_bx.clear();
135  m_l1t_tech_bx.resize( m_l1tTechMask->gtTriggerMask().size(), nullptr );
136  } else {
137  // L1GtUtils not initialised, skip the the L1T monitoring
138  edm::LogError("TriggerBxMonitor") << "failed to read the L1 menu or masks from the EventSetup, the L1 trigger bx distribution will not be monitored";
139  }
140 
141  // initialise the HLTConfigProvider
142  bool changed = true;
144  labelsForToken(m_hlt_results, labels);
145  if (m_hltConfig.init(run, setup, labels.process, changed)) {
146  m_hlt_bx.clear();
147  m_hlt_bx.resize( m_hltConfig.size(), nullptr );
148  } else {
149  // HLTConfigProvider not initialised, skip the the HLT monitoring
150  edm::LogError("TriggerBxMonitor") << "failed to initialise HLTConfigProvider, the HLT bx distribution will not be monitored";
151  }
152 }
153 
155 {
156  // book the overall event count and event types histograms
157  booker.setCurrentFolder( m_dqm_path );
158 
159  if (m_l1tMenu and m_l1tAlgoMask) {
160  // book the rate histograms for the L1 Algorithm triggers
161  booker.setCurrentFolder( m_dqm_path + "/L1 Algo" );
162 
163  // book the histograms for L1 algo triggers that are included in the L1 menu
164  for (auto const & keyval: m_l1tMenu->gtAlgorithmAliasMap()) {
165  int bit = keyval.second.algoBitNumber();
166  std::string const & name = (boost::format("%s (bit %d)") % keyval.first.substr(0, keyval.first.find_first_of(".")) % bit).str();
167  m_l1t_algo_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
168  }
169  // book the histograms for L1 algo triggers that are not included in the L1 menu
170  for (unsigned int bit = 0; bit < m_l1tAlgoMask->gtTriggerMask().size(); ++bit) if (not m_l1t_algo_bx.at(bit)) {
171  std::string const & name = (boost::format("L1 Algo (bit %d)") % bit).str();
172  m_l1t_algo_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
173  }
174  }
175 
176  if (m_l1tMenu and m_l1tTechMask) {
177  // book the rate histograms for the L1 Technical triggers
178  booker.setCurrentFolder( m_dqm_path + "/L1 Tech" );
179 
180  // book the histograms for L1 tech triggers that are included in the L1 menu
181  for (auto const & keyval: m_l1tMenu->gtTechnicalTriggerMap()) {
182  int bit = keyval.second.algoBitNumber();
183  std::string const & name = (boost::format("%s (bit %d)") % keyval.first.substr(0, keyval.first.find_first_of(".")) % bit).str();
184  m_l1t_tech_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
185  }
186  // book the histograms for L1 tech triggers that are not included in the L1 menu
187  for (unsigned int bit = 0; bit < m_l1tTechMask->gtTriggerMask().size(); ++bit) if (not m_l1t_tech_bx.at(bit)) {
188  std::string const & name = (boost::format("L1 Tech (bit %d)") % bit).str();
189  m_l1t_tech_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
190  }
191 
192  }
193 
194  if (m_hltConfig.inited()) {
195  // book the HLT triggers rate histograms
196  booker.setCurrentFolder( m_dqm_path + "/HLT" );
197  for (unsigned int i = 0; i < m_hltConfig.size(); ++i) {
199  m_hlt_bx[i] = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5)->getTH1F();
200  }
201  }
202 }
203 
204 
206 {
207  L1GlobalTriggerReadoutRecord const & l1tResults = * get<L1GlobalTriggerReadoutRecord>(event, m_l1t_results);
208  unsigned int bx = l1tResults.gtfeWord().bxNr();
209 
210  // monitor the bx distribution for the L1 triggers
211  if (m_l1tMenu) {
212  const std::vector<bool> & algoword = l1tResults.decisionWord();
213  if (algoword.size() == m_l1t_algo_bx.size()) {
214  for (unsigned int i = 0; i < m_l1t_algo_bx.size(); ++i)
215  if (algoword[i])
216  m_l1t_algo_bx[i]->Fill(bx);
217  } else {
218  edm::LogWarning("TriggerBxMonitor") << "This should never happen: the size of the L1 Algo Trigger mask does not match the number of L1 Algo Triggers";
219  }
220 
221  const std::vector<bool> & techword = l1tResults.technicalTriggerWord();
222  if (techword.size() == m_l1t_tech_bx.size()) {
223  for (unsigned int i = 0; i < m_l1t_tech_bx.size(); ++i)
224  if (techword[i])
225  m_l1t_tech_bx[i]->Fill(bx);
226  } else {
227  edm::LogWarning("TriggerBxMonitor") << "This should never happen: the size of the L1 Tech Trigger mask does not match the number of L1 Tech Triggers";
228  }
229  }
230 
231  // monitor the bx distribution for the HLT triggers
232  if (m_hltConfig.inited()) {
233  edm::TriggerResults const & hltResults = * get<edm::TriggerResults>(event, m_hlt_results);
234  if (hltResults.size() == m_hlt_bx.size()) {
235  for (unsigned int i = 0; i < m_hlt_bx.size(); ++i) {
236  if (hltResults.at(i).accept())
237  m_hlt_bx[i]->Fill(bx);
238  }
239  } else {
240  edm::LogWarning("TriggerBxMonitor") << "This should never happen: the number of HLT paths has changed since the beginning of the run";
241  }
242  }
243 }
244 
245 
246 //define this as a plug-in
unsigned int size() const
number of trigger paths in trigger table
HLTConfigProvider m_hltConfig
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int i
Definition: DBlmapReader.cc:9
const TechnicalTriggerWord & technicalTriggerWord(int bxInEventValue) const
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 L1GtfeWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
string format
Some error handling for the usage.
std::vector< TH1F * > m_l1t_tech_bx
#define nullptr
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::string m_dqm_path
L1GtTriggerMask const * m_l1tAlgoMask
bool inited() const
Accessors (const methods)
char const * process
Definition: ProductLabels.h:7
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
unsigned int size() const
Get number of paths stored.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
tuple handle
Definition: patZpeak.py:22
edm::EDGetTokenT< edm::TriggerResults > m_hlt_results
L1GtTriggerMask const * m_l1tTechMask
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > m_l1t_results
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:75
const DecisionWord & decisionWord(int bxInEventValue) const
TriggerBxMonitor(edm::ParameterSet const &)
const cms_uint16_t bxNr() const
get/set bunch cross number as counted in the GTFE board
Definition: L1GtfeWord.h:122
const HLTPathStatus & at(const unsigned int i) const
virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:273
T const * product() const
Definition: Handle.h:81
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
T const * product() const
Definition: ESHandle.h:86
static const unsigned int s_bx_range
TH1F * getTH1F(void) const
std::vector< TH1F * > m_l1t_algo_bx
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< TH1F * > m_hlt_bx
bool accept() const
has this path accepted the event?
Definition: HLTPathStatus.h:62
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
const AlgorithmMap & gtTechnicalTriggerMap() const
get / set the technical trigger map
std::shared_ptr< cms::Exception > whyFailed() const
Definition: HandleBase.h:110
L1GtTriggerMenu const * m_l1tMenu
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
long double T
virtual void analyze(edm::Event const &, edm::EventSetup const &) override
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43