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