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