CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalBarrelMonitorModule.cc
Go to the documentation of this file.
1 /*
2  * \file EcalBarrelMonitorModule.cc
3  *
4  * $Date: 2010/08/08 08:46:04 $
5  * $Revision: 1.201 $
6  * \author G. Della Ricca
7  * \author G. Franzoni
8  *
9 */
10 
16 
18 
21 
23 
25 
26 #include <memory>
27 #include <iostream>
28 #include <fstream>
29 
31 
33 
34  // verbose switch
35  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
36 
37  if ( verbose_ ) {
38  std::cout << std::endl;
39  std::cout << " *** Ecal Barrel Generic Monitor ***" << std::endl;
40  std::cout << std::endl;
41  }
42 
43  init_ = false;
44 
45  EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
46  EBDigiCollection_ = ps.getParameter<edm::InputTag>("EBDigiCollection");
47  EcalRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalRecHitCollection");
48  EcalTrigPrimDigiCollection_ = ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollection");
49 
50  // this should come from the event header
51  runNumber_ = ps.getUntrackedParameter<int>("runNumber", 0);
52 
53  fixedRunNumber_ = false;
54  if ( runNumber_ != 0 ) fixedRunNumber_ = true;
55 
56  if ( fixedRunNumber_ ) {
57  if ( verbose_ ) {
58  std::cout << " fixed Run Number = " << runNumber_ << std::endl;
59  }
60  }
61 
62  // this should come from the event header
63  evtNumber_ = 0;
64 
65  // this should come from the EcalBarrel event header
66  runType_ = ps.getUntrackedParameter<int>("runType", -1);
68 
69  fixedRunType_ = false;
70  if ( runType_ != -1 ) fixedRunType_ = true;
71 
72  if ( fixedRunType_) {
73  if ( verbose_ ) {
74  std::cout << " fixed Run Type = " << runType_ << std::endl;
75  }
76  }
77 
78  // debug switch
79  debug_ = ps.getUntrackedParameter<bool>("debug", false);
80 
81  if ( debug_ ) {
82  if ( verbose_ ) {
83  std::cout << " debug switch is ON" << std::endl;
84  }
85  } else {
86  if ( verbose_ ) {
87  std::cout << " debug switch is OFF" << std::endl;
88  }
89  }
90 
91  // prefixME path
92  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
93 
94  // enableCleanup switch
95  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
96 
97  // mergeRuns switch
98  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
99 
100  if ( enableCleanup_ ) {
101  if ( verbose_ ) {
102  std::cout << " enableCleanup switch is ON" << std::endl;
103  }
104  } else {
105  if ( verbose_ ) {
106  std::cout << " enableCleanup switch is OFF" << std::endl;
107  }
108  }
109 
110  // EventDisplay switch
111  enableEventDisplay_ = ps.getUntrackedParameter<bool>("enableEventDisplay", false);
112 
113  meStatus_ = 0;
114  meRun_ = 0;
115  meEvt_ = 0;
116  meRunType_ = 0;
117  meEvtType_ = 0;
118 
119  meEBDCC_ = 0;
120 
121  for (int i = 0; i < 2; i++) {
122  meEBdigis_[i] = 0;
123  meEBhits_[i] = 0;
124  meEBtpdigis_[i] = 0;
125  }
126 
127  for (int i = 0; i < 36; i++) {
128  meEvent_[i] = 0;
129  }
130 
131 }
132 
134 
135 }
136 
138 
139  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: beginJob" << std::endl;
140 
141  ievt_ = 0;
142 
144 
145  if ( dqmStore_ ) {
146  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
147  dqmStore_->rmdir(prefixME_ + "/EcalInfo");
148  if ( enableEventDisplay_ ) {
149  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
150  dqmStore_->rmdir(prefixME_ + "/EcalEvent");
151  }
152  }
153 
154 }
155 
157 
158  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: beginRun" << std::endl;
159 
160  if ( ! mergeRuns_ ) this->reset();
161 
162 }
163 
165 
166  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: endRun" << std::endl;
167 
168  // end-of-run
169  if ( meStatus_ ) meStatus_->Fill(2);
170 
171  if ( meRun_ ) meRun_->Fill(runNumber_);
172  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
173 
174 }
175 
177 
178  if ( meEvtType_ ) meEvtType_->Reset();
179 
180  if ( meEBDCC_ ) meEBDCC_->Reset();
181 
182  for (int i = 0; i < 2; i++) {
183  if ( meEBdigis_[i] ) meEBdigis_[i]->Reset();
184 
185  if ( meEBhits_[i] ) meEBdigis_[i]->Reset();
186 
187  if ( meEBtpdigis_[i] ) meEBtpdigis_[i]->Reset();
188  }
189 
190  if ( enableEventDisplay_ ) {
191  for (int i = 0; i < 18; i++) {
192  if ( meEvent_[i] ) meEvent_[i]->Reset();
193  }
194  }
195 
196 }
197 
199 
200  init_ = true;
201 
202  if ( dqmStore_ ) {
203  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
204 
205  meStatus_ = dqmStore_->bookInt("STATUS");
206 
207  meRun_ = dqmStore_->bookInt("RUN");
208  meEvt_ = dqmStore_->bookInt("EVT");
209 
210  meRunType_ = dqmStore_->bookInt("RUNTYPE");
211  meEvtType_ = dqmStore_->book1D("EVTTYPE", "EVTTYPE", 31, -1., 30.);
212  meEvtType_->setAxisTitle("number of events", 2);
213  meEvtType_->setBinLabel(1, "UNKNOWN", 1);
224  meEvtType_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
237  }
238 
239  // unknown
240  if ( meStatus_ ) meStatus_->Fill(-1);
241 
242  if ( meRun_ ) meRun_->Fill(-1);
243  if ( meEvt_ ) meEvt_->Fill(-1);
244 
245  if ( meRunType_ ) meRunType_->Fill(-1);
246 
247  char histo[20];
248 
249  if ( dqmStore_ ) {
250  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
251 
252  meEBDCC_ = dqmStore_->book1D("EBMM DCC", "EBMM DCC", 36, 1, 37.);
253  for (int i = 0; i < 36; i++) {
254  meEBDCC_->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
255  }
256 
257  meEBdigis_[0] = dqmStore_->book1D("EBMM digi number", "EBMM digi number", 100, 0., 3000.);
258 
259  meEBdigis_[1] = dqmStore_->bookProfile("EBMM digi number profile", "EBMM digi number profile", 36, 1, 37., 1700, 0., 1701., "s");
260  for (int i = 0; i < 36; i++) {
261  meEBdigis_[1]->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
262  }
263 
264  meEBhits_[0] = dqmStore_->book1D("EBMM hit number", "EBMM hit number", 100, 0., 3000.);
265 
266  meEBhits_[1] = dqmStore_->bookProfile("EBMM hit number profile", "EBMM hit number profile", 36, 1, 37., 1700, 0., 1701., "s");
267  for (int i = 0; i < 36; i++) {
268  meEBhits_[1]->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
269  }
270 
271  meEBtpdigis_[0] = dqmStore_->book1D("EBMM TP digi number", "EBMM TP digi number", 100, 0., 2449.);
272 
273  meEBtpdigis_[1] = dqmStore_->bookProfile("EBMM TP digi number profile", "EBMM TP digi number profile", 36, 1, 37., 68, 0., 69., "s");
274  for (int i = 0; i < 36; i++) {
275  meEBtpdigis_[1]->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
276  }
277 
278  if ( enableEventDisplay_ ) {
279  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
280  for (int i = 0; i < 36; i++) {
281  sprintf(histo, "EBMM event %s", Numbers::sEB(i+1).c_str());
282  meEvent_[i] = dqmStore_->book2D(histo, histo, 85, 0., 85., 20, 0., 20.);
283  meEvent_[i]->setAxisTitle("ieta", 1);
284  meEvent_[i]->setAxisTitle("iphi", 2);
285  dqmStore_->tag(meEvent_[i], i+1);
286  if ( meEvent_[i] ) meEvent_[i]->setResetMe(true);
287  }
288  }
289 
290  }
291 
292 }
293 
295 
296  if ( ! enableCleanup_ ) return;
297 
298  if ( dqmStore_ ) {
299 
300  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
301 
303  meStatus_ = 0;
304 
306  meRun_ = 0;
307 
309  meEvt_ = 0;
310 
312  meRunType_ = 0;
313 
315  meEvtType_ = 0;
316 
318  meEBDCC_ = 0;
319 
320  for (int i = 0; i < 2; i++) {
321 
323  meEBdigis_[i] = 0;
324 
325  if ( meEBhits_[i] ) dqmStore_->removeElement( meEBhits_[i]->getName() );
326  meEBhits_[i] = 0;
327 
329  meEBtpdigis_[i] = 0;
330 
331  }
332 
333  if ( enableEventDisplay_ ) {
334 
335  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
336 
337  for (int i = 0; i < 36; i++) {
338 
339  if ( meEvent_[i] ) dqmStore_->removeElement( meEvent_[i]->getName() );
340  meEvent_[i] = 0;
341 
342  }
343 
344  }
345 
346  }
347 
348  init_ = false;
349 
350 }
351 
353 
354  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: endJob, ievt = " << ievt_ << std::endl;
355 
356  if ( dqmStore_ ) {
357  meStatus_ = dqmStore_->get(prefixME_ + "/EventInfo/STATUS");
358  meRun_ = dqmStore_->get(prefixME_ + "/EventInfo/RUN");
359  meEvt_ = dqmStore_->get(prefixME_ + "/EventInfo/EVT");
360  }
361 
362  // end-of-run
363  if ( meStatus_ ) meStatus_->Fill(2);
364 
365  if ( meRun_ ) meRun_->Fill(runNumber_);
366  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
367 
368  if ( init_ ) this->cleanup();
369 
370 }
371 
373 
375 
376  if ( ! init_ ) this->setup();
377 
378  ievt_++;
379 
380  LogDebug("EcalBarrelMonitorModule") << "processing event " << ievt_;
381 
382  if ( ! fixedRunNumber_ ) runNumber_ = e.id().run();
383 
384  evtNumber_ = e.id().event();
385 
387 
388  if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
389 
390  if ( dcchs->size() == 0 ) {
391  LogDebug("EcalBarrelMonitorModule") << EcalRawDataCollection_ << " is empty";
392  return;
393  }
394 
395  int nebc = 0;
396 
397  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
398 
399  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
400 
401  nebc++;
402 
403  }
404 
405  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
406 
407  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
408 
409  if ( meEBDCC_ ) meEBDCC_->Fill(Numbers::iSM( *dcchItr, EcalBarrel )+0.5);
410 
411  if ( ! fixedRunNumber_ ) {
412  runNumber_ = dcchItr->getRunNumber();
413  }
414 
415  evtNumber_ = dcchItr->getLV1();
416 
417  if ( ! fixedRunType_ ) {
418  runType_ = dcchItr->getRunType();
419  evtType_ = runType_;
420  }
421 
422  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
423  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./nebc);
424 
425  }
426 
427  LogDebug("EcalBarrelMonitorModule") << "event: " << ievt_ << " DCC headers collection size: " << nebc;
428 
429  } else {
430 
431  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
432  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./36.);
433 
434  edm::LogWarning("EcalBarrelMonitorModule") << EcalRawDataCollection_ << " not available";
435 
436  }
437 
438  isPhysics_ = false;
445 
447 
448  if ( ievt_ == 1 ) {
449  LogDebug("EcalBarrelMonitorModule") << "processing run " << runNumber_;
450  // begin-of-run
451  if ( meStatus_ ) meStatus_->Fill(0);
452  } else {
453  // running
454  if ( meStatus_ ) meStatus_->Fill(1);
455  }
456 
457  if ( meRun_ ) meRun_->Fill(runNumber_);
458  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
459 
461 
462  if ( e.getByLabel(EBDigiCollection_, digis) ) {
463 
464  int nebd = digis->size();
465  LogDebug("EcalBarrelMonitorModule") << "event " << ievt_ << " digi collection size " << nebd;
466 
467  int counter[36] = { 0 };
468 
469  if ( meEBdigis_[0] ) {
470  if ( isPhysics_ ) meEBdigis_[0]->Fill(float(nebd));
471  }
472 
473  for ( EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
474 
475  EBDetId id = digiItr->id();
476 
477  int ism = Numbers::iSM( id );
478 
479  counter[ism-1]++;
480 
481  }
482 
483  for (int i = 0; i < 36; i++) {
484 
485  if ( meEBdigis_[1] ) {
486  if ( isPhysics_ ) meEBdigis_[1]->Fill(i+1+0.5, counter[i]);
487  }
488 
489  }
490 
491  } else {
492 
493  edm::LogWarning("EcalBarrelMonitorModule") << EBDigiCollection_ << " not available";
494 
495  }
496 
498 
499  if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
500 
501  int nebh = hits->size();
502  LogDebug("EcalBarrelMonitorModule") << "event " << ievt_ << " hits collection size " << nebh;
503 
504  if ( meEBhits_[0] ) {
505  if ( isPhysics_ ) meEBhits_[0]->Fill(float(nebh));
506  }
507 
508  int counter[36] = { 0 };
509 
510  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
511 
512  EBDetId id = hitItr->id();
513 
514  int ic = id.ic();
515  int ie = (ic-1)/20 + 1;
516  int ip = (ic-1)%20 + 1;
517 
518  int ism = Numbers::iSM( id );
519 
520  counter[ism-1]++;
521 
522  float xie = ie - 0.5;
523  float xip = ip - 0.5;
524 
525  float xval = hitItr->energy();
526 
527  if ( enableEventDisplay_ ) {
528 
529  if ( xval >= 10 ) {
530  if ( meEvent_[ism-1] ) meEvent_[ism-1]->Fill(xie, xip, xval);
531  }
532 
533  }
534 
535  }
536 
537  for (int i = 0; i < 36; i++) {
538 
539  if ( meEBhits_[1] ) {
540  if ( isPhysics_ ) meEBhits_[1]->Fill(i+1+0.5, counter[i]);
541  }
542 
543  }
544 
545  } else {
546 
547  edm::LogWarning("EcalBarrelMonitorModule") << EcalRecHitCollection_ << " not available";
548 
549  }
550 
552 
553  if ( e.getByLabel(EcalTrigPrimDigiCollection_, tpdigis) ) {
554 
555  int nebtpd = 0;
556  int counter[36] = { 0 };
557 
558  for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = tpdigis->begin(); tpdigiItr != tpdigis->end(); ++tpdigiItr ) {
559 
560  EcalTrigTowerDetId idt = tpdigiItr->id();
561 
562  if ( Numbers::subDet( idt ) != EcalBarrel ) continue;
563 
564  int ismt = Numbers::iSM( idt );
565 
566  nebtpd++;
567  counter[ismt-1]++;
568 
569  }
570 
571  LogDebug("EcalBarrelMonitorModule") << "event " << ievt_ << " TP digi collection size " << nebtpd;
572  if ( meEBtpdigis_[0] ) {
573  if ( isPhysics_ ) meEBtpdigis_[0]->Fill(float(nebtpd));
574  }
575 
576  for (int i = 0; i < 36; i++) {
577 
578  if ( meEBtpdigis_[1] ) {
579  if ( isPhysics_ ) meEBtpdigis_[1]->Fill(i+1+0.5, counter[i]);
580  }
581 
582  }
583 
584  } else {
585 
586  edm::LogWarning("EcalBarrelMonitorModule") << EcalTrigPrimDigiCollection_ << " not available";
587 
588  }
589 
590 }
591 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
int i
Definition: DBlmapReader.cc:9
static std::string sEB(const int ism)
Definition: Numbers.cc:81
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2296
Some &quot;id&quot; conversions.
std::vector< T >::const_iterator const_iterator
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
tuple histo
Definition: trackerHits.py:12
void Fill(long long x)
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1156
static int iSM(const int ism, const EcalSubdetector subdet)
Definition: Numbers.cc:216
void removeElement(const std::string &name)
Definition: DQMStore.cc:2338
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
MonitorElement * meEBtpdigis_[2]
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:833
std::string getName(Reflex::Type &cc)
Definition: ClassFiller.cc:18
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1270
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
virtual ~EcalBarrelMonitorModule()
Destructor.
EcalBarrelMonitorModule(const edm::ParameterSet &ps)
Constructor.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:43
edm::EventID id() const
Definition: EventBase.h:56
void setResetMe(bool flag)
tuple cout
Definition: gather_cfg.py:41
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:130
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:426
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:647
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:47
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
Definition: Run.h:31