CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalMonitorModule.cc
Go to the documentation of this file.
2 
10 
16 
19 
23 
26 
29 
32 
33 #include <memory>
34 #include <iostream>
35 #include <fstream>
36 #include <vector>
37 #include <string>
38 
39 /*
40  * \file HcalMonitorModule.cc
41  *
42  * \author J Temple
43  *
44  * New version of HcalMonitorModule stores only a few necessary variables that other tasks need to grab
45  * (Online_ boolean, subsystem folder name, subdetector presence check, etc.)
46  * Modeled heavily on EcalBarrelMonitorModule code.
47 
48  * Its only function during its analyze function is to determine the event type (normal, pedestal, laser, etc.) and to perform checks to see which subdetectors are present. Heavy lifting will be done by individual tasks.
49 
50 */
51 
52 
53 //Constructor
54 
56 { // Set initial values
57  init_=false; // first event sets up Monitor Elements and sets init_ to true
58 
59  // get ps objects
60  Online_ = ps.getUntrackedParameter<bool>("online",false);
61  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
62  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
63  debug_ = ps.getUntrackedParameter<int>("debug",0);
64 
65  FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection");
66  tok_raw_ = consumes<FEDRawDataCollection>(FEDRawDataCollection_);
67 
69  tok_report_ = consumes<HcalUnpackerReport>(inputLabelReport_);
70 
71  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
72  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
73  prefixME_.append("/");
74 
75  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
76 
77 } // HcalMonitorModule::HcalMonitorModule
78 
79 
80 //Destructor
82 {
83 
84 } //HcalMonitorModule::~HcalMonitorModule()
85 
86 
87 
89 {
90  if (debug_>0) std::cout <<"HcalMonitorModule::beginJob()"<<std::endl;
91  // Get DQM service
93  // set default values
94  ievt_=0;
95  fedsListed_=false;
96  HBpresent_=0;
97  HEpresent_=0;
98  HOpresent_=0;
99  HFpresent_=0;
100  // Set pointers to null
101  meCalibType_=0;
102  meFEDS_=0;
103  meIevt_=0;
104  meIevtHist_=0;
105  meEvtsVsLS_=0;
107  meHB_=0;
108  meHE_=0;
109  meHO_=0;
110  meHF_=0;
111  eMap_=0;
112 }
113 
115 {
116  if ( debug_>0 ) std::cout << "HcalMonitorModule: beginRun" << std::endl;
117  // reset histograms & counters on a new run, unless merging allowed
118 
119  if (eMap_==0) //eMap_ not created yet
120  {
121  if (debug_>1) std::cout <<"\t<HcalMonitorModule::beginRun> Getting Emap!"<<std::endl;
123  c.get<HcalDbRecord>().get( pSetup );
124  eMap_=pSetup->getHcalMapping();
125  }
126  if (mergeRuns_) return;
127  this->setup();
128  this->reset();
129 
130 } //HcalMonitorModule::beginRun(....)
131 
132 
134 
135  if ( debug_>0 ) std::cout << "HcalMonitorModule: endRun" << std::endl;
136 
137  // end-of-run
138  if ( meStatus_ ) meStatus_->Fill(2);
139 
140  if ( meRun_ ) meRun_->Fill(runNumber_);
141  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
142 }
143 
145 {
146  if (debug_>0) std::cout <<"HcalMonitorModule::reset"<<std::endl;
147  // Call Reset() on all MonitorElement histograms
149  if (meFEDS_) meFEDS_->Reset();
150  if (meIevt_) meIevt_->Fill(0);
151  if (meIevtHist_) meIevtHist_->Reset();
152  if (meEvtsVsLS_) meEvtsVsLS_->Reset();
153  ievt_=0;
155  if (meHB_) meHB_->Fill(-1);
156  if (meHE_) meHE_->Fill(-1);
157  if (meHO_) meHO_->Fill(-1);
158  if (meHF_) meHF_->Fill(-1);
159  HBpresent_=0;
160  HEpresent_=0;
161  HOpresent_=0;
162  HFpresent_=0;
163  fedsListed_=false;
164 } // void HcalMonitorModule::reset(void)
165 
167 {
168  // Run this on first event in run; set up all necessary monitor elements
169  if (debug_>0) std::cout <<"HcalMonitorModule::setup"<<std::endl;
170  init_=true;
171  if (dbe_)
172  {
173  dbe_->setCurrentFolder(prefixME_+"HcalInfo");
174  meStatus_ = dbe_->bookInt("STATUS");
175  if (meStatus_) meStatus_->Fill(-1);
176  meRun_ = dbe_->bookInt("RUN");
177  if (meRun_) meRun_->Fill(-1);
178  meEvt_ = dbe_->bookInt("EVT");
179  if (meEvt_) meEvt_->Fill(-1);
180  meIevt_ = dbe_->bookInt("EventsProcessed");
181  if (meIevt_) meIevt_->Fill(-1);
182  meIevtHist_ = dbe_->book1D("EventsInHcalMonitorModule","Events Seen by HcalMonitorModule",1,0.5,1.5);
183  meIevtHist_->setBinLabel(1,"Nevents",1);
184  meEvtsVsLS_ = dbe_->book1D("EventsVsLS","Events vs. Luminosity Section;LS;# events",NLumiBlocks_,0.5,NLumiBlocks_+0.5);
185  meOnline_ = dbe_->bookInt("Online");
186  meOnline_->Fill((int)Online_);
187  meProcessedEndLumi_ = dbe_->bookInt("EndLumiBlock_MonitorModule");
189  meCurrentCalibType_= dbe_->bookInt("CURRENT_EVENT_TYPE");
191 
192  meHB_ = dbe_->bookInt("HBpresent");
193  meHE_ = dbe_->bookInt("HEpresent");
194  meHO_ = dbe_->bookInt("HOpresent");
195  meHF_ = dbe_->bookInt("HFpresent");
196  if (meHB_) meHB_->Fill(-1);
197  if (meHE_) meHE_->Fill(-1);
198  if (meHO_) meHO_->Fill(-1);
199  if (meHF_) meHF_->Fill(-1);
200 
201  meFEDS_ = dbe_->book1D("FEDs Unpacked","FEDs Unpacked; Hcal FEDs 700-731",1+(FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID),FEDNumbering::MINHCALFEDID-0.5,FEDNumbering::MAXHCALFEDID+0.5);
202 
203  meCalibType_ = dbe_->book1D("CalibrationType","Calibration Type",9,-0.5,8.5);
204  meCalibType_->setBinLabel(1,"Normal",1);
205  meCalibType_->setBinLabel(2,"Ped",1);
206  meCalibType_->setBinLabel(3,"RADDAM",1);
207  meCalibType_->setBinLabel(4,"HBHEHPD",1);
208  meCalibType_->setBinLabel(5,"HOHPD",1);
209  meCalibType_->setBinLabel(6,"HFPMT",1);
210  meCalibType_->setBinLabel(7,"ZDC",1);
211  meCalibType_->setBinLabel(8,"CASTOR",1);
212 
213  } // if (dbe_)
214  return;
215 } // void HcalMonitorModule::setup(void)
216 
217 
219 {
220  if (debug_>0) std::cout <<"HcalMonitorModule::cleanup"<<std::endl;
221  if (!enableCleanup_) return;
222  if (dbe_)
223  {
224  dbe_->setCurrentFolder(prefixME_+"HcalInfo");
225  if ( meStatus_ )
227  meStatus_ = 0;
228  if ( meRun_ )
230  meRun_ = 0;
231  if ( meEvt_ )
233  meEvt_ = 0;
234  if (meIevt_)
236  meIevt_=0;
237  if (meIevtHist_)
239  meIevtHist_=0;
240  if (meFEDS_)
242  meFEDS_ = 0;
243  if (meCalibType_)
245  meCalibType_ = 0;
246  if (meCurrentCalibType_)
249  if (meProcessedEndLumi_)
252  if (meHB_)
254  meHB_=0;
255 
256  if (meHE_)
258  meHE_=0;
259  if (meHO_)
261  meHO_=0;
262  if (meHF_)
264  meHF_=0;
265  } // if (dbe_)
266 
267  fedsListed_=false;
268  HBpresent_=0;
269  HEpresent_=0;
270  HOpresent_=0;
271  HFpresent_=0;
272  init_=false;
273 
274 } // void HcalMonitorModule::cleanup(void)
275 
276 
277 
279  const edm::EventSetup& c)
280 {
281  if (debug_>0) std::cout <<"HcalMonitorModule::beginLuminosityBlock"<<std::endl;
282 }// void HcalMonitorModule::beginLuminosityBlock(...)
283 
284 
285 
286 
288  const edm::EventSetup& c)
289 {
290  if (debug_>0) std::cout <<"HcalMonitorModule::endLuminosityBlock"<<std::endl;
292 }// void HcalMonitorModule::endLuminosityBlock(...)
293 
294 
295 
297 {
298  if (debug_>0) std::cout <<"HcalMonitorModule::endJob()"<<std::endl;
299  if (dbe_)
300  {
301  meStatus_ = dbe_->get(prefixME_ + "/EventInfo/STATUS");
302  meRun_ = dbe_->get(prefixME_ + "/EventInfo/RUN");
303  meEvt_ = dbe_->get(prefixME_ + "/EventInfo/EVT");
304  }
305  if (meStatus_) meStatus_->Fill(2);
306  if (meRun_) meRun_->Fill(runNumber_);
307  if (meEvt_) meEvt_->Fill(evtNumber_);
308  if (init_) this->cleanup();
309 } // void HcalMonitorModule::endJob(void)
310 
311 
312 
314 {
315  if (!init_) this->setup();
316 
317  LogDebug("HcalMonitorModule")<<"processing event "<<ievt_;
318 
319  // Fill Monitor Elements with run, evt, processed event info
320  ++ievt_;
321  runNumber_=e.id().run();
322  evtNumber_=e.id().event();
323  if (meRun_) meRun_->Fill(runNumber_);
324  if (meEvt_) meEvt_->Fill(evtNumber_);
325  if (meIevt_) meIevt_->Fill(ievt_);
326  if (meIevtHist_) meIevtHist_->Fill(1);
328  if (ievt_==1)
329  {
330  LogDebug("HcalMonitorModule") << "processing run " << runNumber_;
331  // begin-of-run
332  if ( meStatus_ ) meStatus_->Fill(0);
333  }
334  else
335  {
336  // running
337  if ( meStatus_ ) meStatus_->Fill(1);
338  }
339 
340  // Try to get raw data
342  if (!(e.getByToken(tok_raw_,rawraw)))
343  {
344  edm::LogWarning("HcalMonitorModule")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
345  return;
346  }
347 
348  // Get Event Calibration Type -- copy of Bryan Dahmes' filter
349  int calibType=-1;
350  int numEmptyFEDs = 0 ;
351  std::vector<int> calibTypeCounter(8,0) ;
353  {
354  const FEDRawData& fedData = rawraw->FEDData(i) ;
355 
356  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
357  if ( fedData.size() < 24 ) continue;
358 
359  int value = (int)((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
360  if(value>7)
361  {
362  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<<i<<" (should be 0-7). I am bailing out...";
363  return;
364  }
365 
366  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
367  } // for (int i = FEDNumbering::MINHCALFEDID; ...)
368 
369  int maxCount = 0;
370  int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
371  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
372  if ( calibTypeCounter.at(i) > maxCount )
373  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
374  if ( maxCount == numberOfFEDIds ) break ;
375  }
376 
377  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
378  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Conflicting calibration types found. Assigning type "
379  << calibType ;
380  LogDebug("HcalMonitorModule::CalibTypeFilter") << "Calibration type is: " << calibType ;
381  // Fill histogram of calibration types, as well as integer to keep track of current value
382  if (meCalibType_) meCalibType_->Fill(calibType);
385 
386  if (debug_>2) std::cout <<"\t<HcalMonitorModule> ievt = "<<ievt_<<" calibration type = "<<calibType<<std::endl;
387 
388  // Check to see which subdetectors are present.
389  // May only need to do this on first event? Subdets don't appear during a run?
390  if (HBpresent_==0)
392  if (HEpresent_==0)
394  if (HOpresent_==0)
396  if (HFpresent_==0)
398 
399  // Here, we do need this information each event
401  if (!(e.getByToken(tok_report_,report)))
402  {
403  edm::LogWarning("HcalMonitorModule")<<" Unpacker Report "<<inputLabelReport_<<" not available";
404  return;
405  }
406 
407  if (!fedsListed_)
408  {
409  const std::vector<int> feds = (*report).getFedsUnpacked();
410  for(unsigned int f=0; f<feds.size(); ++f)
411  meFEDS_->Fill(feds[f]);
412  fedsListed_ = true;
413  } // if (!fedsListed_)
414 
415 } // void HcalMonitorModule::analyze(...)
416 
417 
418 
420  HcalSubdetector subdet,
421  const HcalElectronicsMap& emap)
422 {
423 
424  std::vector<int> fedUnpackList;
425  for (int i=FEDNumbering::MINHCALFEDID;
427  i++)
428  fedUnpackList.push_back(i);
429 
430  if (debug_>1) std::cout <<"<HcalMonitorModule::CheckSubdetectorStatus> Checking subdetector "<<subdet<<std::endl;
431  for (std::vector<int>::const_iterator i=fedUnpackList.begin();
432  i!=fedUnpackList.end();
433  ++i)
434  {
435  if (debug_>2) std::cout <<"\t<HcalMonitorModule::CheckSubdetectorStatus> FED = "<<*i<<std::endl;
436  const FEDRawData& fed =(*rawraw).FEDData(*i);
437  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
438 
439  // get the DCC header
440  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fed.data());
441  if (!dccHeader) return;
442  int dccid=dccHeader->getSourceId();
443  // check for HF
444  if (subdet == HcalForward && dccid>717 && dccid<724)
445  {
446  HFpresent_=1;
448  return;
449  }
450  else if (subdet==HcalOuter && dccid>723)
451  {
452  HOpresent_=1;
454  return;
455  }
456  else if (dccid<718 && (subdet==HcalBarrel || subdet==HcalEndcap))
457  {
458  HcalHTRData htr;
459  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
460  {
461  if (!dccHeader->getSpigotPresent(spigot)) continue;
462 
463  // Load the given decoder with the pointer and length from this spigot.
464  dccHeader->getSpigotData(spigot,htr, fed.size());
465 
466  // check min length, correct wordcount, empty event, or total length if histo event.
467  if (!htr.check()) continue;
468  if (htr.isHistogramEvent()) continue;
469 
470  int firstFED = FEDNumbering::MINHCALFEDID;
471 
472  // Tease out HB and HE, which share HTRs in HBHE
473  for(int fchan=0; fchan<3; ++fchan) //0,1,2 are valid
474  {
475  for(int fib=1; fib<9; ++fib) //1...8 are valid
476  {
477  HcalElectronicsId eid(fchan,fib,spigot,dccid-firstFED);
478  eid.setHTR(htr.readoutVMECrateId(),
479  htr.htrSlot(),htr.htrTopBottom());
480 
481  DetId did=emap.lookup(eid);
482  if (!did.null())
483  {
484 
485  if ((HcalSubdetector)did.subdetId()==subdet)
486  {
487  if (subdet==HcalBarrel)
488  {
489  HBpresent_=1;
491  return;
492  }
493  else if (subdet==HcalEndcap)
494  {
495  HEpresent_=1;
497  return;
498  }
499  } // if ((HcalSubdetector)did.subdetId()==subdet)
500  } // if (!did.null())
501  } // for (int fib=1;fib<9;...)
502  } // for (int fchan=0; fchan<3;...)
503  } // for (int spigot=0;spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
504  } //else if (dcc<718 && (subdet...))
505  } // loop over fedUnpackList
506 
507 
508 } // void HcalMonitorModule::CheckSubdetectorStatus(...)
509 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
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
MonitorElement * meStatus_
edm::InputTag inputLabelReport_
MonitorElement * meHB_
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:62
edm::InputTag FEDRawDataCollection_
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
Definition: HcalHTRData.cc:342
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
tuple calibType
Definition: diJetCalib.py:20
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)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
MonitorElement * meHO_
MonitorElement * meEvt_
MonitorElement * meProcessedEndLumi_
void CheckSubdetectorStatus(const edm::Handle< FEDRawDataCollection > &rawraw, HcalSubdetector subdet, const HcalElectronicsMap &emap)
void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * meCurrentCalibType_
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
const HcalElectronicsMap * eMap_
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
MonitorElement * meCalibType_
tuple report
Definition: zeeHLT_cff.py:9
MonitorElement * meFEDS_
void beginRun(const edm::Run &run, const edm::EventSetup &c)
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
Definition: HcalHTRData.cc:338
void removeElement(const std::string &name)
Definition: DQMStore.cc:3093
HcalSubdetector
Definition: HcalAssistant.h:31
double f[11][100]
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1696
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
MonitorElement * meHE_
int getSourceId() const
Definition: HcalDCCHeader.h:32
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
MonitorElement * meIevt_
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
MonitorElement * meRun_
HcalMonitorModule(const edm::ParameterSet &ps)
const T & get() const
Definition: EventSetup.h:55
bool null() const
is this a null id ?
Definition: DetId.h:45
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
Definition: HcalHTRData.cc:346
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
edm::EventID id() const
Definition: EventBase.h:56
void endRun(const edm::Run &run, const edm::EventSetup &c)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
MonitorElement * meIevtHist_
tuple cout
Definition: gather_cfg.py:121
MonitorElement * meHF_
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:849
MonitorElement * meOnline_
void Reset(void)
reset ME (ie. contents, errors, etc)
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385
Definition: Run.h:41
edm::EDGetTokenT< HcalUnpackerReport > tok_report_
MonitorElement * meEvtsVsLS_