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  * \author G. Della Ricca
5  * \author G. Franzoni
6  *
7 */
8 
11 
13 
16 
18 
20 
21 #include <memory>
22 #include <iostream>
23 #include <fstream>
24 
26 
28 
29  // verbose switch
30  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
31 
32  if ( verbose_ ) {
33  std::cout << std::endl;
34  std::cout << " *** Ecal Endcap Generic Monitor ***" << std::endl;
35  std::cout << std::endl;
36  }
37 
38  init_ = false;
39 
40  EcalRawDataCollection_ = consumes<EcalRawDataCollection>(ps.getParameter<edm::InputTag>("EcalRawDataCollection"));
41  EEDigiCollection_ = consumes<EEDigiCollection>(ps.getParameter<edm::InputTag>("EEDigiCollection"));
42  EcalRecHitCollection_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalRecHitCollection"));
43  EcalTrigPrimDigiCollection_ = consumes<EcalTrigPrimDigiCollection>(ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollection"));
44 
45  // this should come from the event header
46  runNumber_ = ps.getUntrackedParameter<int>("runNumber", 0);
47 
48  fixedRunNumber_ = false;
49  if ( runNumber_ != 0 ) fixedRunNumber_ = true;
50 
51  if ( fixedRunNumber_ ) {
52  if ( verbose_ ) {
53  std::cout << " fixed Run Number = " << runNumber_ << std::endl;
54  }
55  }
56 
57  // this should come from the event header
58  evtNumber_ = 0;
59 
60  // this should come from the EcalEndcap event header
61  runType_ = ps.getUntrackedParameter<int>("runType", -1);
63 
64  fixedRunType_ = false;
65  if ( runType_ != -1 ) fixedRunType_ = true;
66 
67  if ( fixedRunType_) {
68  if ( verbose_ ) {
69  std::cout << " fixed Run Type = " << runType_ << std::endl;
70  }
71  }
72 
73  // debug switch
74  debug_ = ps.getUntrackedParameter<bool>("debug", false);
75 
76  if ( debug_ ) {
77  if ( verbose_ ) {
78  std::cout << " debug switch is ON" << std::endl;
79  }
80  } else {
81  if ( verbose_ ) {
82  std::cout << " debug switch is OFF" << std::endl;
83  }
84  }
85 
86  // prefixME path
87  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
88 
89  // enableCleanup switch
90  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
91 
92  // mergeRuns switch
93  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
94 
95  if ( enableCleanup_ ) {
96  if ( verbose_ ) {
97  std::cout << " enableCleanup switch is ON" << std::endl;
98  }
99  } else {
100  if ( verbose_ ) {
101  std::cout << " enableCleanup switch is OFF" << std::endl;
102  }
103  }
104 
105  // EventDisplay switch
106  enableEventDisplay_ = ps.getUntrackedParameter<bool>("enableEventDisplay", false);
107 
108  meStatus_ = 0;
109  meRun_ = 0;
110  meEvt_ = 0;
111  meRunType_ = 0;
112  meEvtType_ = 0;
113 
114  meEEDCC_ = 0;
115 
116  for (int i = 0; i < 2; i++) {
117  meEEdigis_[i] = 0;
118  meEEhits_[i] = 0;
119  meEEtpdigis_[i] = 0;
120  }
121 
122  for (int i = 0; i < 18; i++) {
123  meEvent_[i] = 0;
124  }
125 
126 }
127 
129 
130 }
131 
133 
134  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: beginJob" << std::endl;
135 
136  ievt_ = 0;
137 
139 
140  if ( dqmStore_ ) {
141  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
142  dqmStore_->rmdir(prefixME_ + "/EcalInfo");
143  if ( enableEventDisplay_ ) {
144  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
145  dqmStore_->rmdir(prefixME_ + "/EcalEvent");
146  }
147  }
148 
149 }
150 
152 
153  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: beginRun" << std::endl;
154 
155  if ( ! mergeRuns_ ) this->reset();
156 
157 }
158 
160 
161  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: endRun" << std::endl;
162 
163  // end-of-run
164  if ( meStatus_ ) meStatus_->Fill(2);
165 
166  if ( meRun_ ) meRun_->Fill(runNumber_);
167  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
168 
169 }
170 
172 
173  if ( meEvtType_ ) meEvtType_->Reset();
174 
175  if ( meEEDCC_ ) meEEDCC_->Reset();
176 
177  for (int i = 0; i < 2; i++) {
178  if ( meEEdigis_[i] ) meEEdigis_[i]->Reset();
179 
180  if ( meEEhits_[i] ) meEEhits_[i]->Reset();
181 
182  if ( meEEtpdigis_[i] ) meEEtpdigis_[i]->Reset();
183  }
184 
185  if ( enableEventDisplay_ ) {
186  for (int i = 0; i < 18; i++) {
187  if ( meEvent_[i] ) meEvent_[i]->Reset();
188  }
189  }
190 
191 }
192 
194 
195  init_ = true;
196 
197  if ( dqmStore_ ) {
198  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
199 
200  meStatus_ = dqmStore_->bookInt("STATUS");
201 
202  meRun_ = dqmStore_->bookInt("RUN");
203  meEvt_ = dqmStore_->bookInt("EVT");
204 
205  meRunType_ = dqmStore_->bookInt("RUNTYPE");
206  meEvtType_ = dqmStore_->book1D("EVTTYPE", "EVTTYPE", 31, -1., 30.);
207  meEvtType_->setAxisTitle("number of events", 2);
208  meEvtType_->setBinLabel(1, "UNKNOWN", 1);
219  meEvtType_->setBinLabel(2+EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN, "PEDESTAL_OFFSET_SCAN", 1);
232  }
233 
234  // unknown
235  if ( meStatus_ ) meStatus_->Fill(-1);
236 
237  if ( meRun_ ) meRun_->Fill(-1);
238  if ( meEvt_ ) meEvt_->Fill(-1);
239 
240  if ( meRunType_ ) meRunType_->Fill(-1);
241 
243 
244  if ( dqmStore_ ) {
245  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
246 
247  meEEDCC_ = dqmStore_->book1D("EEMM DCC", "EEMM DCC", 18, 1, 19.);
248  for (int i = 0; i < 18; i++) {
249  meEEDCC_->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
250  }
251 
252  meEEdigis_[0] = dqmStore_->book1D("EEMM digi number", "EEMM digi number", 100, 0., 3000.);
253 
254  meEEdigis_[1] = dqmStore_->bookProfile("EEMM digi number profile", "EEMM digi number profile", 18, 1, 19., 850, 0., 851., "s");
255  for (int i = 0; i < 18; i++) {
256  meEEdigis_[1]->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
257  }
258 
259  meEEhits_[0] = dqmStore_->book1D("EEMM hit number", "EEMM hit number", 100, 0., 3000.);
260 
261  meEEhits_[1] = dqmStore_->bookProfile("EEMM hit number profile", "EEMM hit number profile", 18, 1, 19., 850, 0., 851., "s");
262  for (int i = 0; i < 18; i++) {
263  meEEhits_[1]->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
264  }
265 
266  meEEtpdigis_[0] = dqmStore_->book1D("EEMM TP digi number", "EEMM TP digi number", 100, 0., 1585.);
267 
268  meEEtpdigis_[1] = dqmStore_->bookProfile("EEMM TP digi number profile", "EEMM TP digi number profile", 18, 1, 19., 34, 0., 35., "s");
269  for (int i = 0; i < 18; i++) {
270  meEEtpdigis_[1]->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
271  }
272 
273  if ( enableEventDisplay_ ) {
274  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
275  for (int i = 0; i < 18; i++) {
276  name = "EEMM event " + Numbers::sEE(i+1);
277  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.);
278  meEvent_[i]->setAxisTitle("ix", 1);
279  if ( i+1 >= 1 && i+1 <= 9 ) meEvent_[i]->setAxisTitle("101-ix", 1);
280  meEvent_[i]->setAxisTitle("iy", 2);
281  dqmStore_->tag(meEvent_[i], i+1);
282  if ( meEvent_[i] ) meEvent_[i]->setResetMe(true);
283  }
284  }
285 
286  }
287 
288 }
289 
291 
292  if ( ! enableCleanup_ ) return;
293 
294  if ( dqmStore_ ) {
295 
296  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
297 
299  meStatus_ = 0;
300 
302  meRun_ = 0;
303 
305  meEvt_ = 0;
306 
308  meRunType_ = 0;
309 
311  meEvtType_ = 0;
312 
314  meEEDCC_ = 0;
315 
316  for (int i = 0; i < 2; i++) {
317 
318  if ( meEEdigis_[i] ) dqmStore_->removeElement( meEEdigis_[i]->getName() );
319  meEEdigis_[i] = 0;
320 
321  if ( meEEhits_[i] ) dqmStore_->removeElement( meEEhits_[i]->getName() );
322  meEEhits_[i] = 0;
323 
324  if ( meEEtpdigis_[i] ) dqmStore_->removeElement( meEEtpdigis_[i]->getName() );
325  meEEtpdigis_[i] = 0;
326 
327  }
328 
329  if ( enableEventDisplay_ ) {
330 
331  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
332 
333  for (int i = 0; i < 18; i++) {
334 
335  if ( meEvent_[i] ) dqmStore_->removeElement( meEvent_[i]->getName() );
336  meEvent_[i] = 0;
337 
338  }
339 
340  }
341 
342  }
343 
344  init_ = false;
345 
346 }
347 
349 
350  if ( debug_ ) std::cout << "EcalEndcapMonitorModule: endJob, ievt = " << ievt_ << std::endl;
351 
352  if ( dqmStore_ ) {
353  meStatus_ = dqmStore_->get(prefixME_ + "/EcalInfo/STATUS");
354  meRun_ = dqmStore_->get(prefixME_ + "/EcalInfo/RUN");
355  meEvt_ = dqmStore_->get(prefixME_ + "/EcalInfo/EVT");
356  }
357 
358  // end-of-run
359  if ( meStatus_ ) meStatus_->Fill(2);
360 
361  if ( meRun_ ) meRun_->Fill(runNumber_);
362  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
363 
364  if ( init_ ) this->cleanup();
365 
366 }
367 
369 
371 
372  if ( ! init_ ) this->setup();
373 
374  ievt_++;
375 
376  LogDebug("EcalEndcapMonitorModule") << "processing event " << ievt_;
377 
378  if ( ! fixedRunNumber_ ) runNumber_ = e.id().run();
379 
380  evtNumber_ = e.id().event();
381 
383 
384  if ( e.getByToken(EcalRawDataCollection_, dcchs) ) {
385 
386  if ( dcchs->size() == 0 ) {
387  LogDebug("EcalEndcapMonitorModule") << "EcalRawDataCollection is empty";
388  return;
389  }
390 
391  int neec = 0;
392 
393  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
394 
395  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
396 
397  neec++;
398 
399  }
400 
401  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
402 
403  if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
404 
405  if ( meEEDCC_ ) meEEDCC_->Fill(Numbers::iSM( *dcchItr, EcalEndcap )+0.5);
406 
407  if ( ! fixedRunNumber_ ) {
408  runNumber_ = dcchItr->getRunNumber();
409  }
410 
411  evtNumber_ = dcchItr->getLV1();
412 
413  if ( ! fixedRunType_ ) {
414  runType_ = dcchItr->getRunType();
415  evtType_ = runType_;
416  }
417 
418  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
419  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./neec);
420 
421  }
422 
423  LogDebug("EcalEndcapMonitorModule") << "event: " << ievt_ << " DCC headers collection size: " << neec;
424 
425  } else {
426 
427  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
428  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./18.);
429 
430  edm::LogWarning("EcalEndcapMonitorModule") << "EcalRawDataCollection not available";
431 
432  }
433 
434  isPhysics_ = false;
441 
443 
444  if ( ievt_ == 1 ) {
445  LogDebug("EcalEndcapMonitorModule") << "processing run " << runNumber_;
446  // begin-of-run
447  if ( meStatus_ ) meStatus_->Fill(0);
448  } else {
449  // running
450  if ( meStatus_ ) meStatus_->Fill(1);
451  }
452 
453  if ( meRun_ ) meRun_->Fill(runNumber_);
454  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
455 
457 
458  if ( e.getByToken(EEDigiCollection_, digis) ) {
459 
460  int need = digis->size();
461  LogDebug("EcalEndcapMonitorModule") << "event " << ievt_ << " digi collection size " << need;
462 
463  int counter[18] = { 0 };
464 
465  if ( meEEdigis_[0] ) {
466  if ( isPhysics_ ) meEEdigis_[0]->Fill(float(need));
467  }
468 
469  for ( EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
470 
471  EEDetId id = digiItr->id();
472 
473  int ism = Numbers::iSM( id );
474 
475  counter[ism-1]++;
476 
477  }
478 
479  for (int i = 0; i < 18; i++) {
480 
481  if ( meEEdigis_[1] ) {
482  if ( isPhysics_ ) meEEdigis_[1]->Fill(i+1+0.5, counter[i]);
483  }
484 
485  }
486 
487  } else {
488 
489  edm::LogWarning("EcalEndcapMonitorModule") << "EEDigiCollection not available";
490 
491  }
492 
494 
495  if ( e.getByToken(EcalRecHitCollection_, hits) ) {
496 
497  int neeh = hits->size();
498  LogDebug("EcalEndcapMonitorModule") << "event " << ievt_ << " hits collection size " << neeh;
499 
500  if ( meEEhits_[0] ) {
501  if ( isPhysics_ ) meEEhits_[0]->Fill(float(neeh));
502  }
503 
504  int counter[18] = { 0 };
505 
506  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
507 
508  EEDetId id = hitItr->id();
509 
510  int ix = id.ix();
511  int iy = id.iy();
512 
513  int ism = Numbers::iSM( id );
514 
515  counter[ism-1]++;
516 
517  if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
518 
519  float xix = ix - 0.5;
520  float xiy = iy - 0.5;
521 
522  float xval = hitItr->energy();
523 
524  if ( enableEventDisplay_ ) {
525 
526  if ( xval >= 10 ) {
527  if ( meEvent_[ism-1] ) meEvent_[ism-1]->Fill(xix, xiy, xval);
528  }
529 
530  }
531 
532  }
533 
534  for (int i = 0; i < 18; i++) {
535 
536  if ( meEEhits_[1] ) {
537  if ( isPhysics_ ) meEEhits_[1]->Fill(i+1+0.5, counter[i]);
538  }
539 
540  }
541 
542  } else {
543 
544  edm::LogWarning("EcalEndcapMonitorModule") << "EcalRecHitCollection not available";
545 
546  }
547 
549 
550  if ( e.getByToken(EcalTrigPrimDigiCollection_, tpdigis) ) {
551 
552  int neetpd = 0;
553  int counter[18] = { 0 };
554 
555  for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = tpdigis->begin(); tpdigiItr != tpdigis->end(); ++tpdigiItr ) {
556 
557  EcalTrigTowerDetId idt = tpdigiItr->id();
558 
559  if ( Numbers::subDet( idt ) != EcalEndcap ) continue;
560 
561  int ismt = Numbers::iSM( idt );
562 
563  neetpd++;
564  counter[ismt-1]++;
565 
566  }
567 
568  LogDebug("EcalEndcapMonitorModule") << "event " << ievt_ << " TP digi collection size " << neetpd;
569  if ( meEEtpdigis_[0] ) {
570  if ( isPhysics_ ) meEEtpdigis_[0]->Fill(float(neetpd));
571  }
572 
573  for (int i = 0; i < 18; i++) {
574 
575  if ( meEEtpdigis_[1] ) {
576  if ( isPhysics_ ) meEEtpdigis_[1]->Fill(i+1+0.5, counter[i]);
577  }
578 
579  }
580 
581  } else {
582 
583  edm::LogWarning("EcalEndcapMonitorModule") << "EcalTrigPrimDigiCollection not available";
584 
585  }
586 
587 }
588 
#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:223
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:76
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:872
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2730
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Some &quot;id&quot; conversions.
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
edm::EDGetTokenT< EcalTrigPrimDigiCollection > EcalTrigPrimDigiCollection_
std::vector< EcalDCCHeaderBlock >::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:770
static int iy0EE(const unsigned ism)
Definition: Numbers.cc:809
void Fill(long long x)
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1509
void removeElement(const std::string &name)
Definition: DQMStore.cc:2772
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:1186
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1623
edm::EDGetTokenT< EcalRecHitCollection > EcalRecHitCollection_
EcalEndcapMonitorModule(const edm::ParameterSet &ps)
Constructor.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
edm::EDGetTokenT< EcalRawDataCollection > EcalRawDataCollection_
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
void setResetMe(bool)
edm::EventID id() const
Definition: EventBase.h:56
static std::atomic< unsigned int > counter
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
tuple cout
Definition: gather_cfg.py:121
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:142
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:779
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:1000
edm::EDGetTokenT< EEDigiCollection > EEDigiCollection_
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:584
Definition: Run.h:41
virtual ~EcalEndcapMonitorModule()
Destructor.