CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTScalers.cc
Go to the documentation of this file.
1 //
2 // Revision 1.30 2011/03/30 21:44:03 fwyzard
3 // make sure HLTConfigProvider is used only if succesfully initialized
4 //
5 // Revision 1.29 2011/03/30 21:35:40 fwyzard
6 // make sure all members are initialized
7 //
8 // Revision 1.28 2011/03/29 09:46:03 rekovic
9 // clean vector pairPDPaths in beginRun and tidy up
10 //
11 // Revision 1.27 2011/03/24 18:35:38 rekovic
12 // Change name for pd histo
13 //
14 // Revision 1.26 2011/03/24 18:25:45 rekovic
15 // Add single 1D plot of streamA content
16 //
17 // Revision 1.25 2010/07/20 02:58:27 wmtan
18 // Add missing #include files
19 //
20 // Revision 1.24 2010/03/17 20:54:51 wittich
21 // add scalers that I manually reset on beginLumi
22 //
23 // Revision 1.23 2010/02/25 17:34:01 wdd
24 // Central migration of TriggerNames class interface
25 //
26 // Revision 1.22 2010/02/24 17:43:47 wittich
27 // - keep trying to get path names if it doesn't work first time
28 // - move the Bx histograms out of raw to the toplevel directory.
29 //
30 // Revision 1.21 2010/02/11 23:54:28 wittich
31 // modify how the monitoring histo is filled
32 //
33 // Revision 1.20 2010/02/11 00:11:08 wmtan
34 // Adapt to moved framework header
35 //
36 // Revision 1.19 2010/02/02 13:53:05 wittich
37 // fix duplicate histogram name
38 //
39 // Revision 1.18 2010/02/02 11:42:53 wittich
40 // new diagnostic histograms
41 //
42 // Revision 1.17 2009/11/20 00:39:12 lorenzo
43 // fixes
44 //
45 // Revision 1.16 2008/09/03 13:59:06 wittich
46 // make HLT DQM path configurable via python parameter,
47 // which defaults to HLT/HLTScalers_EvF
48 //
49 // Revision 1.15 2008/09/03 02:13:47 wittich
50 // - bug fix in L1Scalers
51 // - configurable dqm directory in L1SCalers
52 // - other minor tweaks in HLTScalers
53 //
54 
55 #include <iostream>
56 
57 
58 // FW
61 
64 
67 
68 // HLT
72 
73 
78 
79 using namespace edm;
80 
81 
82 
84  folderName_(ps.getUntrackedParameter<std::string>("dqmFolder", "HLT/HLTScalers_EvF")),
85  processname_(ps.getParameter<std::string>("processname")),
86  pairPDPaths_(),
87  trigResultsSource_(consumes<TriggerResults>(ps.getParameter<edm::InputTag>("triggerResults"))),
88  dbe_(0),
89  scalersN_(0),
90  scalersException_(0),
91  hltCorrelations_(0),
92  detailedScalers_(0),
93  nProc_(0),
94  nLumiBlock_(0),
95  hltBx_(0),
96  hltBxVsPath_(0),
97  hltOverallScaler_(0),
98  hltOverallScalerN_(0),
99  diagnostic_(0),
100  resetMe_(true),
101  sentPaths_(false),
102  monitorDaemon_(ps.getUntrackedParameter<bool>("MonitorDaemon", false)),
103  nev_(0),
104  nLumi_(0),
105  currentRun_(-1)
106 {
107  LogDebug("HLTScalers") << "HLTScalers: constructor...." ;
108 
110  if (dbe_ ) {
111  dbe_->setVerbose(0);
112  dbe_->setCurrentFolder(folderName_);
113  }
114 }
115 
116 
118 {
119  LogDebug("HLTScalers") << "HLTScalers::beginJob()..." << std::endl;
120 
121  if (dbe_) {
122  std::string rawdir(folderName_ + "/raw");
123  dbe_->setCurrentFolder(rawdir);
124 
125  nProc_ = dbe_->bookInt("nProcessed");
126  nLumiBlock_ = dbe_->bookInt("nLumiBlock");
127  diagnostic_ = dbe_->book1D("hltMerge", "HLT merging diagnostic",
128  1, 0.5, 1.5);
129 
130  // fill for ever accepted event
131  hltOverallScaler_ = dbe_->book1D("hltOverallScaler", "HLT Overall Scaler",
132  1, 0.5, 1.5);
133  hltOverallScalerN_ = dbe_->book1D("hltOverallScalerN",
134  "Reset HLT Overall Scaler", 1, 0.5, 1.5);
135 
136  // other ME's are now found on the first event of the new run,
137  // when we know more about the HLT configuration.
138  }
139 }
140 
142 {
143  nProc_->Fill(++nev_);
144  diagnostic_->setBinContent(1,1); // this ME is never touched -
145  // it just tells you how the merging is doing.
146 
148  bool b = e.getByToken(trigResultsSource_, hltResults);
149  if ( !b ) {
150  Labels l;
152 
153  edm::LogInfo("HLTScalers") << "getByLabel for TriggerResults failed"
154  << " with label " << l.module;
155  return;
156  }
157 
158 
159  int npath = hltResults->size();
160  unsigned int nPD = pairPDPaths_.size();
161 
162  // on the first event of a new run we book new ME's
163  if (resetMe_ ) {
164  LogInfo("HLTScalers") << "analyze(): new run. dump path for this evt "
165  << e.id() << ", \n"
166  << *hltResults ;
167 
168  if (not dbe_)
169  return;
170 
171  // need to get maxModules dynamically
172  int maxModules = 200;
173 
174  std::string rawdir(folderName_ + "/raw");
175  dbe_->setCurrentFolder(rawdir);
176 
177  scalersPD_ = dbe_->book1D("pdScalers", "PD scalers (stream A)",
178  nPD, -0.5, nPD-0.5);
179  detailedScalers_ = dbe_->book2D("detailedHltScalers", "HLT Scalers",
180  npath, -0.5, npath-0.5,
181  maxModules, 0, maxModules-1);
182  scalers_ = dbe_->book1D("hltScalers", "HLT scalers",
183  npath, -0.5, npath-0.5);
184  scalersN_ = dbe_->book1D("hltScalersN", "Reset HLT scalers",
185  npath, -0.5, npath-0.5);
186  scalersException_ = dbe_->book1D("hltExceptions", "HLT Exception scalers",
187  npath, -0.5, npath-0.5);
188  hltCorrelations_ = dbe_->book2D("hltCorrelations", "HLT Scalers",
189  npath, -0.5, npath-0.5,
190  npath, -0.5, npath-0.5);
191 
192  // these two belong in top-level
193  dbe_->setCurrentFolder(folderName_);
194  hltBxVsPath_ = dbe_->book2D("hltBxVsPath", "HLT Accept vs Bunch Number",
195  3600, -0.5, 3599.5,
196  npath, -0.5, npath-0.5);
197  hltBx_ = dbe_->book1D("hltBx", "Bx of HLT Accepted Events ",
198  3600, -0.5, 3599.5);
199 
200  resetMe_ = false;
201  } // end resetMe_ - pseudo-end-run record
202 
203  const edm::TriggerNames & trigNames = e.triggerNames(*hltResults);
204  // for some reason this doesn't appear to work on the first event sometimes
205  if ( ! sentPaths_ ) {
206  const edm::TriggerNames & names = e.triggerNames(*hltResults);
207 
208  // save path names in DQM-accessible format
209  int q = 0;
210  for ( TriggerNames::Strings::const_iterator
211  j = names.triggerNames().begin();
212  j !=names.triggerNames().end(); ++j ) {
213 
214  LogDebug("HLTScalers") << q << ": " << *j ;
215  ++q;
216  scalers_->getTH1()->GetXaxis()->SetBinLabel(q, j->c_str());
217  }
218 
219  for (unsigned int i = 0; i < nPD; i++) {
220  LogDebug("HLTScalers") << i << ": " << pairPDPaths_[i].first << std::endl ;
221  scalersPD_->getTH1()->GetXaxis()->SetBinLabel(i+1, pairPDPaths_[i].first.c_str());
222  }
223 
224  sentPaths_ = true;
225  }
226 
227  bool accept = false;
228  int bx = e.bunchCrossing();
229  for ( int i = 0; i < npath; ++i ) {
230  // state returns 0 on ready, 1 on accept, 2 on fail, 3 on exception.
231  // these are defined in HLTEnums.h
232  for ( unsigned int j = 0; j < hltResults->index(i); ++j ) {
234  }
235  if ( hltResults->state(i) == hlt::Pass) {
236  scalers_->Fill(i);
237  scalersN_->Fill(i);
238  hltBxVsPath_->Fill(bx, i);
239  accept = true;
240  for ( int j = i + 1; j < npath; ++j ) {
241  if ( hltResults->state(j) == hlt::Pass) {
242  hltCorrelations_->Fill(i,j); // fill
244  }
245  }
246  }
247  else if ( hltResults->state(i) == hlt::Exception) {
249  }
250  }
251  if ( accept ) {
252  hltOverallScaler_->Fill(1.0);
253  hltOverallScalerN_->Fill(1.0);
254  hltBx_->Fill(int(bx));
255  }
256 
257  bool anyGroupPassed = false;
258  for (unsigned int mi = 0; mi < pairPDPaths_.size(); mi++) {
259 
260  bool groupPassed = false;
261 
262  for (unsigned int i = 0; i < pairPDPaths_[mi].second.size(); i++)
263  {
264 
265  //string hltPathName = hist_2d->GetXaxis()->GetBinLabel(i);
266  std::string hltPathName = pairPDPaths_[mi].second[i];
267 
268  // check if this is hlt path name
269  //unsigned int pathByIndex = triggerNames.triggerIndex(hltPathName);
270  unsigned int pathByIndex = trigNames.triggerIndex(pairPDPaths_[mi].second[i]);
271  if(pathByIndex >= hltResults->size() ) continue;
272 
273  // check if its L1 passed
274  // comment out below but set groupL1Passed to true always
275  //if(hasL1Passed(hltPathName,triggerNames)) groupL1Passed = true;
276  //groupL1Passed = true;
277 
278  // Fill HLTPassed Matrix and HLTPassFail Matrix
279  // --------------------------------------------------------
280 
281  if(hltResults->accept(pathByIndex)) {
282  groupPassed = true;
283  break;
284  }
285 
286  }
287 
288  if(groupPassed) {
289  scalersPD_->Fill(mi);
290  anyGroupPassed = true;
291  }
292 
293  }
294 
295  if(anyGroupPassed) scalersPD_->Fill(pairPDPaths_.size()-1);
296 }
297 
299  const edm::EventSetup& c)
300 {
301  LogDebug("HLTScalers") << "Start of luminosity block." ;
302  // reset the N guys
303  if ( scalersN_ )
304  scalersN_->Reset();
305  if ( hltOverallScalerN_ )
307 }
308 
309 
311  const edm::EventSetup& c)
312 {
313  // put this in as a first-pass for figuring out the rate
314  // each lumi block is 23 seconds in length
315  nLumiBlock_->Fill(lumiSeg.id().luminosityBlock());
316 
317  LogDebug("HLTScalers") << "End of luminosity block." ;
318 
319 }
320 
321 
324 {
325  LogDebug("HLTScalers") << "HLTScalers::beginRun, run "
326  << run.id();
327  if ( currentRun_ != int(run.id().run()) ) {
328  resetMe_ = true;
329  currentRun_ = run.id().run();
330  }
331 
332  // HLT config does not change within runs!
333  bool changed=false;
334 
335  // clear vector pairPDPaths_
336  pairPDPaths_.clear();
337 
338  if (not hltConfig_.init(run, c, processname_, changed)) {
339  edm::LogError("TrigXMonitor") << "HLTConfigProvider failed to initialize.";
340  } else {
341 
342  // check if trigger name in (new) config
343  // cout << "Available TriggerNames are: " << endl;
344  // hltConfig_.dump("Triggers");
345 
346  if (hltConfig_.streamIndex("A")<hltConfig_.streamNames().size()) {
347 
348  // get hold of PD names and constituent path names
349  const std::vector<std::string> & PD = hltConfig_.streamContent("A") ;
350 
351  for (unsigned int i = 0; i < PD.size(); i++) {
352 
353  const std::vector<std::string> & datasetPaths = hltConfig_.datasetContent(PD[i]);
354  pairPDPaths_.push_back(make_pair(PD[i], datasetPaths));
355 
356  }
357 
358  // push stream A and its PDs
359  pairPDPaths_.push_back(make_pair("A", PD));
360 
361  } else {
362 
363  LogDebug("HLTScalers") << "HLTScalers::beginRun, steamm A not in the HLT menu ";
364 
365  }
366 
367  }
368 }
369 
372 {
373  LogDebug("HLTScalers") << "HLTScalers::endRun , run "
374  << run.id();
375  if ( currentRun_ != int(run.id().run()) ) {
376  resetMe_ = true;
377  currentRun_ = run.id().run();
378  }
379 }
#define LogDebug(id)
LuminosityBlockID id() const
std::vector< std::pair< std::string, std::vector< std::string > > > pairPDPaths_
Definition: HLTScalers.h:108
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:199
void setBinContent(int binx, double content)
set content of bin (1-D)
RunID const & id() const
Definition: RunBase.h:41
static const HistoName names[]
RunNumber_t run() const
Definition: RunID.h:39
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
HLTScalers(const edm::ParameterSet &ps)
Constructors.
Definition: HLTScalers.cc:83
MonitorElement * scalersN_
Definition: HLTScalers.h:114
MonitorElement * detailedScalers_
Definition: HLTScalers.h:117
std::string processname_
Definition: HLTScalers.h:107
DQMStore * dbe_
Definition: HLTScalers.h:111
int bunchCrossing() const
Definition: EventBase.h:62
MonitorElement * hltOverallScaler_
Definition: HLTScalers.h:121
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
Definition: HLTScalers.cc:310
MonitorElement * scalers_
Definition: HLTScalers.h:113
unsigned int streamIndex(const std::string &stream) const
index of stream with name
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:25
MonitorElement * diagnostic_
Definition: HLTScalers.h:123
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
void Fill(long long x)
U second(std::pair< T, U > const &p)
void beginRun(const edm::Run &run, const edm::EventSetup &c)
BeginRun.
Definition: HLTScalers.cc:323
MonitorElement * hltBxVsPath_
Definition: HLTScalers.h:120
void endRun(const edm::Run &run, const edm::EventSetup &c)
EndRun.
Definition: HLTScalers.cc:371
const std::vector< std::string > & streamNames() const
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
accept
Definition: HLTenums.h:19
void beginJob(void)
BeginJob.
Definition: HLTScalers.cc:117
const std::vector< std::string > & streamContent(unsigned int stream) const
names of datasets in stream with index i
int j
Definition: DBlmapReader.cc:9
TH1 * getTH1(void) const
MonitorElement * hltCorrelations_
Definition: HLTScalers.h:116
int currentRun_
Definition: HLTScalers.h:129
HLTConfigProvider hltConfig_
Definition: HLTScalers.h:105
bool first
Definition: L1TdeRCT.cc:75
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
Begin LumiBlock.
Definition: HLTScalers.cc:298
DQMStore * dbe_
const std::vector< std::string > & datasetContent(unsigned int dataset) const
names of trigger paths in dataset with index i
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
MonitorElement * scalersException_
Definition: HLTScalers.h:115
MonitorElement * nLumiBlock_
Definition: HLTScalers.h:119
bool resetMe_
Definition: HLTScalers.h:125
MonitorElement * hltOverallScalerN_
Definition: HLTScalers.h:122
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
bool sentPaths_
Definition: HLTScalers.h:125
edm::EventID id() const
Definition: EventBase.h:56
std::string folderName_
Definition: HLTScalers.h:106
MonitorElement * hltBx_
Definition: HLTScalers.h:120
MonitorElement * nProc_
Definition: HLTScalers.h:118
volatile std::atomic< bool > shutdown_flag false
MonitorElement * scalersPD_
Definition: HLTScalers.h:112
void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: HLTScalers.cc:141
void Reset(void)
reset ME (ie. contents, errors, etc)
Definition: Run.h:41
edm::EDGetTokenT< edm::TriggerResults > trigResultsSource_
Definition: HLTScalers.h:109