CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalEndcapMonitorModule.cc
Go to the documentation of this file.
1 /*
2  * \file EcalEndcapMonitorModule.cc
3  *
4  * $Date: 2012/04/26 07:45:15 $
5  * $Revision: 1.88 $
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 Endcap Generic Monitor ***" << std::endl;
40  std::cout << std::endl;
41  }
42 
43  init_ = false;
44 
45  EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
46  EEDigiCollection_ = ps.getParameter<edm::InputTag>("EEDigiCollection");
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 EcalEndcap 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  meEEDCC_ = 0;
120 
121  for (int i = 0; i < 2; i++) {
122  meEEdigis_[i] = 0;
123  meEEhits_[i] = 0;
124  meEEtpdigis_[i] = 0;
125  }
126 
127  for (int i = 0; i < 18; i++) {
128  meEvent_[i] = 0;
129  }
130 
131 }
132 
134 
135 }
136 
138 
139  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: 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 << "EcalEndcapMonitorModule: beginRun" << std::endl;
159 
160  if ( ! mergeRuns_ ) this->reset();
161 
162 }
163 
165 
166  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: 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 ( meEEDCC_ ) meEEDCC_->Reset();
181 
182  for (int i = 0; i < 2; i++) {
183  if ( meEEdigis_[i] ) meEEdigis_[i]->Reset();
184 
185  if ( meEEhits_[i] ) meEEdigis_[i]->Reset();
186 
187  if ( meEEtpdigis_[i] ) meEEtpdigis_[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  std::string name;
248 
249  if ( dqmStore_ ) {
250  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
251 
252  meEEDCC_ = dqmStore_->book1D("EEMM DCC", "EEMM DCC", 18, 1, 19.);
253  for (int i = 0; i < 18; i++) {
254  meEEDCC_->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
255  }
256 
257  meEEdigis_[0] = dqmStore_->book1D("EEMM digi number", "EEMM digi number", 100, 0., 3000.);
258 
259  meEEdigis_[1] = dqmStore_->bookProfile("EEMM digi number profile", "EEMM digi number profile", 18, 1, 19., 850, 0., 851., "s");
260  for (int i = 0; i < 18; i++) {
261  meEEdigis_[1]->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
262  }
263 
264  meEEhits_[0] = dqmStore_->book1D("EEMM hit number", "EEMM hit number", 100, 0., 3000.);
265 
266  meEEhits_[1] = dqmStore_->bookProfile("EEMM hit number profile", "EEMM hit number profile", 18, 1, 19., 850, 0., 851., "s");
267  for (int i = 0; i < 18; i++) {
268  meEEhits_[1]->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
269  }
270 
271  meEEtpdigis_[0] = dqmStore_->book1D("EEMM TP digi number", "EEMM TP digi number", 100, 0., 1585.);
272 
273  meEEtpdigis_[1] = dqmStore_->bookProfile("EEMM TP digi number profile", "EEMM TP digi number profile", 18, 1, 19., 34, 0., 35., "s");
274  for (int i = 0; i < 18; i++) {
275  meEEtpdigis_[1]->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
276  }
277 
278  if ( enableEventDisplay_ ) {
279  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
280  for (int i = 0; i < 18; i++) {
281  name = "EEMM event " + Numbers::sEE(i+1);
282  meEvent_[i] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.);
283  meEvent_[i]->setAxisTitle("ix", 1);
284  if ( i+1 >= 1 && i+1 <= 9 ) meEvent_[i]->setAxisTitle("101-ix", 1);
285  meEvent_[i]->setAxisTitle("iy", 2);
286  dqmStore_->tag(meEvent_[i], i+1);
287  if ( meEvent_[i] ) meEvent_[i]->setResetMe(true);
288  }
289  }
290 
291  }
292 
293 }
294 
296 
297  if ( ! enableCleanup_ ) return;
298 
299  if ( dqmStore_ ) {
300 
301  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
302 
304  meStatus_ = 0;
305 
307  meRun_ = 0;
308 
310  meEvt_ = 0;
311 
313  meRunType_ = 0;
314 
316  meEvtType_ = 0;
317 
319  meEEDCC_ = 0;
320 
321  for (int i = 0; i < 2; i++) {
322 
324  meEEdigis_[i] = 0;
325 
326  if ( meEEhits_[i] ) dqmStore_->removeElement( meEEhits_[i]->getName() );
327  meEEhits_[i] = 0;
328 
330  meEEtpdigis_[i] = 0;
331 
332  }
333 
334  if ( enableEventDisplay_ ) {
335 
336  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
337 
338  for (int i = 0; i < 18; i++) {
339 
340  if ( meEvent_[i] ) dqmStore_->removeElement( meEvent_[i]->getName() );
341  meEvent_[i] = 0;
342 
343  }
344 
345  }
346 
347  }
348 
349  init_ = false;
350 
351 }
352 
354 
355  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: endJob, ievt = " << ievt_ << std::endl;
356 
357  if ( dqmStore_ ) {
358  meStatus_ = dqmStore_->get(prefixME_ + "/EcalInfo/STATUS");
359  meRun_ = dqmStore_->get(prefixME_ + "/EcalInfo/RUN");
360  meEvt_ = dqmStore_->get(prefixME_ + "/EcalInfo/EVT");
361  }
362 
363  // end-of-run
364  if ( meStatus_ ) meStatus_->Fill(2);
365 
366  if ( meRun_ ) meRun_->Fill(runNumber_);
367  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
368 
369  if ( init_ ) this->cleanup();
370 
371 }
372 
374 
376 
377  if ( ! init_ ) this->setup();
378 
379  ievt_++;
380 
381  LogDebug("EcalEndcapMonitorModule") << "processing event " << ievt_;
382 
383  if ( ! fixedRunNumber_ ) runNumber_ = e.id().run();
384 
385  evtNumber_ = e.id().event();
386 
388 
389  if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
390 
391  if ( dcchs->size() == 0 ) {
392  LogDebug("EcalEndcapMonitorModule") << EcalRawDataCollection_ << " is empty";
393  return;
394  }
395 
396  int neec = 0;
397 
398  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
399 
400  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
401 
402  neec++;
403 
404  }
405 
406  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
407 
408  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
409 
410  if ( meEEDCC_ ) meEEDCC_->Fill(Numbers::iSM( *dcchItr, EcalEndcap )+0.5);
411 
412  if ( ! fixedRunNumber_ ) {
413  runNumber_ = dcchItr->getRunNumber();
414  }
415 
416  evtNumber_ = dcchItr->getLV1();
417 
418  if ( ! fixedRunType_ ) {
419  runType_ = dcchItr->getRunType();
420  evtType_ = runType_;
421  }
422 
423  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
424  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./neec);
425 
426  }
427 
428  LogDebug("EcalEndcapMonitorModule") << "event: " << ievt_ << " DCC headers collection size: " << neec;
429 
430  } else {
431 
432  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
433  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./18.);
434 
435  edm::LogWarning("EcalEndcapMonitorModule") << EcalRawDataCollection_ << " not available";
436 
437  }
438 
439  isPhysics_ = false;
446 
448 
449  if ( ievt_ == 1 ) {
450  LogDebug("EcalEndcapMonitorModule") << "processing run " << runNumber_;
451  // begin-of-run
452  if ( meStatus_ ) meStatus_->Fill(0);
453  } else {
454  // running
455  if ( meStatus_ ) meStatus_->Fill(1);
456  }
457 
458  if ( meRun_ ) meRun_->Fill(runNumber_);
459  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
460 
462 
463  if ( e.getByLabel(EEDigiCollection_, digis) ) {
464 
465  int need = digis->size();
466  LogDebug("EcalEndcapMonitorModule") << "event " << ievt_ << " digi collection size " << need;
467 
468  int counter[18] = { 0 };
469 
470  if ( meEEdigis_[0] ) {
471  if ( isPhysics_ ) meEEdigis_[0]->Fill(float(need));
472  }
473 
474  for ( EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
475 
476  EEDetId id = digiItr->id();
477 
478  int ism = Numbers::iSM( id );
479 
480  counter[ism-1]++;
481 
482  }
483 
484  for (int i = 0; i < 18; i++) {
485 
486  if ( meEEdigis_[1] ) {
487  if ( isPhysics_ ) meEEdigis_[1]->Fill(i+1+0.5, counter[i]);
488  }
489 
490  }
491 
492  } else {
493 
494  edm::LogWarning("EcalEndcapMonitorModule") << EEDigiCollection_ << " not available";
495 
496  }
497 
499 
500  if ( e.getByLabel(EcalRecHitCollection_, hits) ) {
501 
502  int neeh = hits->size();
503  LogDebug("EcalEndcapMonitorModule") << "event " << ievt_ << " hits collection size " << neeh;
504 
505  if ( meEEhits_[0] ) {
506  if ( isPhysics_ ) meEEhits_[0]->Fill(float(neeh));
507  }
508 
509  int counter[18] = { 0 };
510 
511  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
512 
513  EEDetId id = hitItr->id();
514 
515  int ix = id.ix();
516  int iy = id.iy();
517 
518  int ism = Numbers::iSM( id );
519 
520  counter[ism-1]++;
521 
522  if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
523 
524  float xix = ix - 0.5;
525  float xiy = iy - 0.5;
526 
527  float xval = hitItr->energy();
528 
529  if ( enableEventDisplay_ ) {
530 
531  if ( xval >= 10 ) {
532  if ( meEvent_[ism-1] ) meEvent_[ism-1]->Fill(xix, xiy, xval);
533  }
534 
535  }
536 
537  }
538 
539  for (int i = 0; i < 18; i++) {
540 
541  if ( meEEhits_[1] ) {
542  if ( isPhysics_ ) meEEhits_[1]->Fill(i+1+0.5, counter[i]);
543  }
544 
545  }
546 
547  } else {
548 
549  edm::LogWarning("EcalEndcapMonitorModule") << EcalRecHitCollection_ << " not available";
550 
551  }
552 
554 
555  if ( e.getByLabel(EcalTrigPrimDigiCollection_, tpdigis) ) {
556 
557  int neetpd = 0;
558  int counter[18] = { 0 };
559 
560  for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = tpdigis->begin(); tpdigiItr != tpdigis->end(); ++tpdigiItr ) {
561 
562  EcalTrigTowerDetId idt = tpdigiItr->id();
563 
564  if ( Numbers::subDet( idt ) != EcalEndcap ) continue;
565 
566  int ismt = Numbers::iSM( idt );
567 
568  neetpd++;
569  counter[ismt-1]++;
570 
571  }
572 
573  LogDebug("EcalEndcapMonitorModule") << "event " << ievt_ << " TP digi collection size " << neetpd;
574  if ( meEEtpdigis_[0] ) {
575  if ( isPhysics_ ) meEEtpdigis_[0]->Fill(float(neetpd));
576  }
577 
578  for (int i = 0; i < 18; i++) {
579 
580  if ( meEEtpdigis_[1] ) {
581  if ( isPhysics_ ) meEEtpdigis_[1]->Fill(i+1+0.5, counter[i]);
582  }
583 
584  }
585 
586  } else {
587 
588  edm::LogWarning("EcalEndcapMonitorModule") << EcalTrigPrimDigiCollection_ << " not available";
589 
590  }
591 
592 }
593 
#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
static std::string sEE(const unsigned ism)
Definition: Numbers.cc:226
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:71
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2530
Some &quot;id&quot; conversions.
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
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)
MonitorElement * meEEtpdigis_[2]
static int ix0EE(const unsigned ism)
Definition: Numbers.cc:773
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:812
void Fill(long long x)
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1354
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
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:1031
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:1468
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
EcalEndcapMonitorModule(const edm::ParameterSet &ps)
Constructor.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:50
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
void setResetMe(bool)
edm::EventID id() const
Definition: EventBase.h:56
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:246
tuple cout
Definition: gather_cfg.py:121
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:145
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:624
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:845
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
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 setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33
virtual ~EcalEndcapMonitorModule()
Destructor.