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  * \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 Barrel 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  EBDigiCollection_ = consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EBDigiCollection"));
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 EcalBarrel 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  meEBDCC_ = 0;
115 
116  for (int i = 0; i < 2; i++) {
117  meEBdigis_[i] = 0;
118  meEBhits_[i] = 0;
119  meEBtpdigis_[i] = 0;
120  }
121 
122  for (int i = 0; i < 36; i++) {
123  meEvent_[i] = 0;
124  }
125 
126 }
127 
129 
130 }
131 
133 
134  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: 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 << "EcalBarrelMonitorModule: beginRun" << std::endl;
154 
155  if ( ! mergeRuns_ ) this->reset();
156 
157 }
158 
160 
161  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: 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 ( meEBDCC_ ) meEBDCC_->Reset();
176 
177  for (int i = 0; i < 2; i++) {
178  if ( meEBdigis_[i] ) meEBdigis_[i]->Reset();
179 
180  if ( meEBhits_[i] ) meEBdigis_[i]->Reset();
181 
182  if ( meEBtpdigis_[i] ) meEBtpdigis_[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  meEBDCC_ = dqmStore_->book1D("EBMM DCC", "EBMM DCC", 36, 1, 37.);
248  for (int i = 0; i < 36; i++) {
249  meEBDCC_->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
250  }
251 
252  meEBdigis_[0] = dqmStore_->book1D("EBMM digi number", "EBMM digi number", 100, 0., 3000.);
253 
254  meEBdigis_[1] = dqmStore_->bookProfile("EBMM digi number profile", "EBMM digi number profile", 36, 1, 37., 1700, 0., 1701., "s");
255  for (int i = 0; i < 36; i++) {
256  meEBdigis_[1]->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
257  }
258 
259  meEBhits_[0] = dqmStore_->book1D("EBMM hit number", "EBMM hit number", 100, 0., 3000.);
260 
261  meEBhits_[1] = dqmStore_->bookProfile("EBMM hit number profile", "EBMM hit number profile", 36, 1, 37., 1700, 0., 1701., "s");
262  for (int i = 0; i < 36; i++) {
263  meEBhits_[1]->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
264  }
265 
266  meEBtpdigis_[0] = dqmStore_->book1D("EBMM TP digi number", "EBMM TP digi number", 100, 0., 2449.);
267 
268  meEBtpdigis_[1] = dqmStore_->bookProfile("EBMM TP digi number profile", "EBMM TP digi number profile", 36, 1, 37., 68, 0., 69., "s");
269  for (int i = 0; i < 36; i++) {
270  meEBtpdigis_[1]->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
271  }
272 
273  if ( enableEventDisplay_ ) {
274  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
275  for (int i = 0; i < 36; i++) {
276  name = "EBMM event " + Numbers::sEB(i+1);
277  meEvent_[i] = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
278  meEvent_[i]->setAxisTitle("ieta", 1);
279  meEvent_[i]->setAxisTitle("iphi", 2);
280  dqmStore_->tag(meEvent_[i], i+1);
281  if ( meEvent_[i] ) meEvent_[i]->setResetMe(true);
282  }
283  }
284 
285  }
286 
287 }
288 
290 
291  if ( ! enableCleanup_ ) return;
292 
293  if ( dqmStore_ ) {
294 
295  dqmStore_->setCurrentFolder(prefixME_ + "/EcalInfo");
296 
298  meStatus_ = 0;
299 
301  meRun_ = 0;
302 
304  meEvt_ = 0;
305 
307  meRunType_ = 0;
308 
310  meEvtType_ = 0;
311 
313  meEBDCC_ = 0;
314 
315  for (int i = 0; i < 2; i++) {
316 
317  if ( meEBdigis_[i] ) dqmStore_->removeElement( meEBdigis_[i]->getName() );
318  meEBdigis_[i] = 0;
319 
320  if ( meEBhits_[i] ) dqmStore_->removeElement( meEBhits_[i]->getName() );
321  meEBhits_[i] = 0;
322 
323  if ( meEBtpdigis_[i] ) dqmStore_->removeElement( meEBtpdigis_[i]->getName() );
324  meEBtpdigis_[i] = 0;
325 
326  }
327 
328  if ( enableEventDisplay_ ) {
329 
330  dqmStore_->setCurrentFolder(prefixME_ + "/EcalEvent");
331 
332  for (int i = 0; i < 36; i++) {
333 
334  if ( meEvent_[i] ) dqmStore_->removeElement( meEvent_[i]->getName() );
335  meEvent_[i] = 0;
336 
337  }
338 
339  }
340 
341  }
342 
343  init_ = false;
344 
345 }
346 
348 
349  if ( debug_ ) std::cout << "EcalBarrelMonitorModule: endJob, ievt = " << ievt_ << std::endl;
350 
351  if ( dqmStore_ ) {
352  meStatus_ = dqmStore_->get(prefixME_ + "/EcalInfo/STATUS");
353  meRun_ = dqmStore_->get(prefixME_ + "/EcalInfo/RUN");
354  meEvt_ = dqmStore_->get(prefixME_ + "/EcalInfo/EVT");
355  }
356 
357  // end-of-run
358  if ( meStatus_ ) meStatus_->Fill(2);
359 
360  if ( meRun_ ) meRun_->Fill(runNumber_);
361  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
362 
363  if ( init_ ) this->cleanup();
364 
365 }
366 
368 
370 
371  if ( ! init_ ) this->setup();
372 
373  ievt_++;
374 
375  LogDebug("EcalBarrelMonitorModule") << "processing event " << ievt_;
376 
377  if ( ! fixedRunNumber_ ) runNumber_ = e.id().run();
378 
379  evtNumber_ = e.id().event();
380 
382 
383  if ( e.getByToken(EcalRawDataCollection_, dcchs) ) {
384 
385  if ( dcchs->size() == 0 ) {
386  LogDebug("EcalBarrelMonitorModule") << "EcalRawDataCollection is empty";
387  return;
388  }
389 
390  int nebc = 0;
391 
392  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
393 
394  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
395 
396  nebc++;
397 
398  }
399 
400  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
401 
402  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
403 
404  if ( meEBDCC_ ) meEBDCC_->Fill(Numbers::iSM( *dcchItr, EcalBarrel )+0.5);
405 
406  if ( ! fixedRunNumber_ ) {
407  runNumber_ = dcchItr->getRunNumber();
408  }
409 
410  evtNumber_ = dcchItr->getLV1();
411 
412  if ( ! fixedRunType_ ) {
413  runType_ = dcchItr->getRunType();
414  evtType_ = runType_;
415  }
416 
417  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
418  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./nebc);
419 
420  }
421 
422  LogDebug("EcalBarrelMonitorModule") << "event: " << ievt_ << " DCC headers collection size: " << nebc;
423 
424  } else {
425 
426  if ( evtType_ < 0 || evtType_ > 22 ) evtType_ = -1;
427  if ( meEvtType_ ) meEvtType_->Fill(evtType_+0.5, 1./36.);
428 
429  edm::LogWarning("EcalBarrelMonitorModule") << "EcalRawDataCollection not available";
430 
431  }
432 
433  isPhysics_ = false;
440 
442 
443  if ( ievt_ == 1 ) {
444  LogDebug("EcalBarrelMonitorModule") << "processing run " << runNumber_;
445  // begin-of-run
446  if ( meStatus_ ) meStatus_->Fill(0);
447  } else {
448  // running
449  if ( meStatus_ ) meStatus_->Fill(1);
450  }
451 
452  if ( meRun_ ) meRun_->Fill(runNumber_);
453  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
454 
456 
457  if ( e.getByToken(EBDigiCollection_, digis) ) {
458 
459  int nebd = digis->size();
460  LogDebug("EcalBarrelMonitorModule") << "event " << ievt_ << " digi collection size " << nebd;
461 
462  int counter[36] = { 0 };
463 
464  if ( meEBdigis_[0] ) {
465  if ( isPhysics_ ) meEBdigis_[0]->Fill(float(nebd));
466  }
467 
468  for ( EBDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
469 
470  EBDetId id = digiItr->id();
471 
472  int ism = Numbers::iSM( id );
473 
474  counter[ism-1]++;
475 
476  }
477 
478  for (int i = 0; i < 36; i++) {
479 
480  if ( meEBdigis_[1] ) {
481  if ( isPhysics_ ) meEBdigis_[1]->Fill(i+1+0.5, counter[i]);
482  }
483 
484  }
485 
486  } else {
487 
488  edm::LogWarning("EcalBarrelMonitorModule") << "EBDigiCollection not available";
489 
490  }
491 
493 
494  if ( e.getByToken(EcalRecHitCollection_, hits) ) {
495 
496  int nebh = hits->size();
497  LogDebug("EcalBarrelMonitorModule") << "event " << ievt_ << " hits collection size " << nebh;
498 
499  if ( meEBhits_[0] ) {
500  if ( isPhysics_ ) meEBhits_[0]->Fill(float(nebh));
501  }
502 
503  int counter[36] = { 0 };
504 
505  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
506 
507  EBDetId id = hitItr->id();
508 
509  int ic = id.ic();
510  int ie = (ic-1)/20 + 1;
511  int ip = (ic-1)%20 + 1;
512 
513  int ism = Numbers::iSM( id );
514 
515  counter[ism-1]++;
516 
517  float xie = ie - 0.5;
518  float xip = ip - 0.5;
519 
520  float xval = hitItr->energy();
521 
522  if ( enableEventDisplay_ ) {
523 
524  if ( xval >= 10 ) {
525  if ( meEvent_[ism-1] ) meEvent_[ism-1]->Fill(xie, xip, xval);
526  }
527 
528  }
529 
530  }
531 
532  for (int i = 0; i < 36; i++) {
533 
534  if ( meEBhits_[1] ) {
535  if ( isPhysics_ ) meEBhits_[1]->Fill(i+1+0.5, counter[i]);
536  }
537 
538  }
539 
540  } else {
541 
542  edm::LogWarning("EcalBarrelMonitorModule") << "EcalRecHitCollection not available";
543 
544  }
545 
547 
548  if ( e.getByToken(EcalTrigPrimDigiCollection_, tpdigis) ) {
549 
550  int nebtpd = 0;
551  int counter[36] = { 0 };
552 
553  for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = tpdigis->begin(); tpdigiItr != tpdigis->end(); ++tpdigiItr ) {
554 
555  EcalTrigTowerDetId idt = tpdigiItr->id();
556 
557  if ( Numbers::subDet( idt ) != EcalBarrel ) continue;
558 
559  int ismt = Numbers::iSM( idt );
560 
561  nebtpd++;
562  counter[ismt-1]++;
563 
564  }
565 
566  LogDebug("EcalBarrelMonitorModule") << "event " << ievt_ << " TP digi collection size " << nebtpd;
567  if ( meEBtpdigis_[0] ) {
568  if ( isPhysics_ ) meEBtpdigis_[0]->Fill(float(nebtpd));
569  }
570 
571  for (int i = 0; i < 36; i++) {
572 
573  if ( meEBtpdigis_[1] ) {
574  if ( isPhysics_ ) meEBtpdigis_[1]->Fill(i+1+0.5, counter[i]);
575  }
576 
577  }
578 
579  } else {
580 
581  edm::LogWarning("EcalBarrelMonitorModule") << "EcalTrigPrimDigiCollection not available";
582 
583  }
584 
585 }
586 
#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
edm::EDGetTokenT< EBDigiCollection > EBDigiCollection_
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
edm::EDGetTokenT< EcalRawDataCollection > EcalRawDataCollection_
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
edm::EDGetTokenT< EcalTrigPrimDigiCollection > EcalTrigPrimDigiCollection_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Some &quot;id&quot; conversions.
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:91
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)
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
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: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
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
virtual ~EcalBarrelMonitorModule()
Destructor.
EcalBarrelMonitorModule(const edm::ParameterSet &ps)
Constructor.
edm::EDGetTokenT< EcalRecHitCollection > EcalRecHitCollection_
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
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
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 endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
Definition: Run.h:41