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_(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);
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.getByLabel(trigResultsSource_, hltResults);
149  if ( !b ) {
150  edm::LogInfo("HLTScalers") << "getByLabel for TriggerResults failed"
151  << " with label " << trigResultsSource_;
152  return;
153  }
154 
155 
156  int npath = hltResults->size();
157  unsigned int nPD = pairPDPaths_.size();
158 
159  // on the first event of a new run we book new ME's
160  if (resetMe_ ) {
161  LogInfo("HLTScalers") << "analyze(): new run. dump path for this evt "
162  << e.id() << ", \n"
163  << *hltResults ;
164 
165  if (not dbe_)
166  return;
167 
168  // need to get maxModules dynamically
169  int maxModules = 200;
170 
171  std::string rawdir(folderName_ + "/raw");
172  dbe_->setCurrentFolder(rawdir);
173 
174  scalersPD_ = dbe_->book1D("pdScalers", "PD scalers (stream A)",
175  nPD, -0.5, nPD-0.5);
176  detailedScalers_ = dbe_->book2D("detailedHltScalers", "HLT Scalers",
177  npath, -0.5, npath-0.5,
178  maxModules, 0, maxModules-1);
179  scalers_ = dbe_->book1D("hltScalers", "HLT scalers",
180  npath, -0.5, npath-0.5);
181  scalersN_ = dbe_->book1D("hltScalersN", "Reset HLT scalers",
182  npath, -0.5, npath-0.5);
183  scalersException_ = dbe_->book1D("hltExceptions", "HLT Exception scalers",
184  npath, -0.5, npath-0.5);
185  hltCorrelations_ = dbe_->book2D("hltCorrelations", "HLT Scalers",
186  npath, -0.5, npath-0.5,
187  npath, -0.5, npath-0.5);
188 
189  // these two belong in top-level
190  dbe_->setCurrentFolder(folderName_);
191  hltBxVsPath_ = dbe_->book2D("hltBxVsPath", "HLT Accept vs Bunch Number",
192  3600, -0.5, 3599.5,
193  npath, -0.5, npath-0.5);
194  hltBx_ = dbe_->book1D("hltBx", "Bx of HLT Accepted Events ",
195  3600, -0.5, 3599.5);
196 
197  resetMe_ = false;
198  } // end resetMe_ - pseudo-end-run record
199 
200  const edm::TriggerNames & trigNames = e.triggerNames(*hltResults);
201  // for some reason this doesn't appear to work on the first event sometimes
202  if ( ! sentPaths_ ) {
203  const edm::TriggerNames & names = e.triggerNames(*hltResults);
204 
205  // save path names in DQM-accessible format
206  int q = 0;
207  for ( TriggerNames::Strings::const_iterator
208  j = names.triggerNames().begin();
209  j !=names.triggerNames().end(); ++j ) {
210 
211  LogDebug("HLTScalers") << q << ": " << *j ;
212  ++q;
213  scalers_->getTH1()->GetXaxis()->SetBinLabel(q, j->c_str());
214  }
215 
216  for (unsigned int i = 0; i < nPD; i++) {
217  LogDebug("HLTScalers") << i << ": " << pairPDPaths_[i].first << std::endl ;
218  scalersPD_->getTH1()->GetXaxis()->SetBinLabel(i+1, pairPDPaths_[i].first.c_str());
219  }
220 
221  sentPaths_ = true;
222  }
223 
224  bool accept = false;
225  int bx = e.bunchCrossing();
226  for ( int i = 0; i < npath; ++i ) {
227  // state returns 0 on ready, 1 on accept, 2 on fail, 3 on exception.
228  // these are defined in HLTEnums.h
229  for ( unsigned int j = 0; j < hltResults->index(i); ++j ) {
231  }
232  if ( hltResults->state(i) == hlt::Pass) {
233  scalers_->Fill(i);
234  scalersN_->Fill(i);
235  hltBxVsPath_->Fill(bx, i);
236  accept = true;
237  for ( int j = i + 1; j < npath; ++j ) {
238  if ( hltResults->state(j) == hlt::Pass) {
239  hltCorrelations_->Fill(i,j); // fill
241  }
242  }
243  }
244  else if ( hltResults->state(i) == hlt::Exception) {
246  }
247  }
248  if ( accept ) {
249  hltOverallScaler_->Fill(1.0);
250  hltOverallScalerN_->Fill(1.0);
251  hltBx_->Fill(int(bx));
252  }
253 
254  bool anyGroupPassed = false;
255  for (unsigned int mi = 0; mi < pairPDPaths_.size(); mi++) {
256 
257  bool groupPassed = false;
258 
259  for (unsigned int i = 0; i < pairPDPaths_[mi].second.size(); i++)
260  {
261 
262  //string hltPathName = hist_2d->GetXaxis()->GetBinLabel(i);
263  std::string hltPathName = pairPDPaths_[mi].second[i];
264 
265  // check if this is hlt path name
266  //unsigned int pathByIndex = triggerNames.triggerIndex(hltPathName);
267  unsigned int pathByIndex = trigNames.triggerIndex(pairPDPaths_[mi].second[i]);
268  if(pathByIndex >= hltResults->size() ) continue;
269 
270  // check if its L1 passed
271  // comment out below but set groupL1Passed to true always
272  //if(hasL1Passed(hltPathName,triggerNames)) groupL1Passed = true;
273  //groupL1Passed = true;
274 
275  // Fill HLTPassed Matrix and HLTPassFail Matrix
276  // --------------------------------------------------------
277 
278  if(hltResults->accept(pathByIndex)) {
279  groupPassed = true;
280  break;
281  }
282 
283  }
284 
285  if(groupPassed) {
286  scalersPD_->Fill(mi);
287  anyGroupPassed = true;
288  }
289 
290  }
291 
292  if(anyGroupPassed) scalersPD_->Fill(pairPDPaths_.size()-1);
293 }
294 
296  const edm::EventSetup& c)
297 {
298  LogDebug("HLTScalers") << "Start of luminosity block." ;
299  // reset the N guys
300  if ( scalersN_ )
301  scalersN_->Reset();
302  if ( hltOverallScalerN_ )
304 }
305 
306 
308  const edm::EventSetup& c)
309 {
310  // put this in as a first-pass for figuring out the rate
311  // each lumi block is 23 seconds in length
312  nLumiBlock_->Fill(lumiSeg.id().luminosityBlock());
313 
314  LogDebug("HLTScalers") << "End of luminosity block." ;
315 
316 }
317 
318 
321 {
322  LogDebug("HLTScalers") << "HLTScalers::beginRun, run "
323  << run.id();
324  if ( currentRun_ != int(run.id().run()) ) {
325  resetMe_ = true;
326  currentRun_ = run.id().run();
327  }
328 
329  // HLT config does not change within runs!
330  bool changed=false;
331 
332  // clear vector pairPDPaths_
333  pairPDPaths_.clear();
334 
335  if (not hltConfig_.init(run, c, processname_, changed)) {
336  edm::LogError("TrigXMonitor") << "HLTConfigProvider failed to initialize.";
337  } else {
338 
339  // check if trigger name in (new) config
340  // cout << "Available TriggerNames are: " << endl;
341  // hltConfig_.dump("Triggers");
342 
343  if (hltConfig_.streamIndex("A")<hltConfig_.streamNames().size()) {
344 
345  // get hold of PD names and constituent path names
346  const std::vector<std::string> & PD = hltConfig_.streamContent("A") ;
347 
348  for (unsigned int i = 0; i < PD.size(); i++) {
349 
350  const std::vector<std::string> & datasetPaths = hltConfig_.datasetContent(PD[i]);
351  pairPDPaths_.push_back(make_pair(PD[i], datasetPaths));
352 
353  }
354 
355  // push stream A and its PDs
356  pairPDPaths_.push_back(make_pair("A", PD));
357 
358  } else {
359 
360  LogDebug("HLTScalers") << "HLTScalers::beginRun, steamm A not in the HLT menu ";
361 
362  }
363 
364  }
365 }
366 
369 {
370  LogDebug("HLTScalers") << "HLTScalers::endRun , run "
371  << run.id();
372  if ( currentRun_ != int(run.id().run()) ) {
373  resetMe_ = true;
374  currentRun_ = run.id().run();
375  }
376 }
#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:204
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:43
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
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:307
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:26
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:320
MonitorElement * hltBxVsPath_
Definition: HLTScalers.h:120
void endRun(const edm::Run &run, const edm::EventSetup &c)
EndRun.
Definition: HLTScalers.cc:368
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
void setVerbose(unsigned level)
Definition: DQMStore.cc:548
int currentRun_
Definition: HLTScalers.h:129
HLTConfigProvider hltConfig_
Definition: HLTScalers.h:105
bool first
Definition: L1TdeRCT.cc:79
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
Begin LumiBlock.
Definition: HLTScalers.cc:295
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
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
bool sentPaths_
Definition: HLTScalers.h:125
edm::EventID id() const
Definition: EventBase.h:56
edm::InputTag trigResultsSource_
Definition: HLTScalers.h:109
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 * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:779
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)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
Definition: Run.h:41