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 
12 
18 
21 
25 
28 
31 
34 
35 #include <memory>
36 #include <iostream>
37 #include <fstream>
38 #include <vector>
39 #include <string>
40 
41 /*
42  * \file HcalMonitorModule.cc
43  *
44  * $Date: 2012/05/27 11:31:22 $
45  * $Revision: 1.166 $
46  * \author J Temple
47  *
48  * New version of HcalMonitorModule stores only a few necessary variables that other tasks need to grab
49  * (Online_ boolean, subsystem folder name, subdetector presence check, etc.)
50  * Modeled heavily on EcalBarrelMonitorModule code.
51 
52  * 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.
53 
54 */
55 
56 
57 //Constructor
58 
60 { // Set initial values
61  init_=false; // first event sets up Monitor Elements and sets init_ to true
62 
63  // get ps objects
64  Online_ = ps.getUntrackedParameter<bool>("online",false);
65  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
66  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
67  debug_ = ps.getUntrackedParameter<int>("debug",0);
68 
69  FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection");
71 
72  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
73  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
74  prefixME_.append("/");
75 
76  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
77 
78 } // HcalMonitorModule::HcalMonitorModule
79 
80 
81 //Destructor
83 {
84 
85 } //HcalMonitorModule::~HcalMonitorModule()
86 
87 
88 
90 {
91  if (debug_>0) std::cout <<"HcalMonitorModule::beginJob()"<<std::endl;
92  // Get DQM service
94  // set default values
95  ievt_=0;
96  fedsListed_=false;
97  HBpresent_=0;
98  HEpresent_=0;
99  HOpresent_=0;
100  HFpresent_=0;
101  // Set pointers to null
102  meCalibType_=0;
103  meFEDS_=0;
104  meIevt_=0;
105  meIevtHist_=0;
106  meEvtsVsLS_=0;
108  meHB_=0;
109  meHE_=0;
110  meHO_=0;
111  meHF_=0;
112  eMap_=0;
113 }
114 
116 {
117  if ( debug_>0 ) std::cout << "HcalMonitorModule: beginRun" << std::endl;
118  // reset histograms & counters on a new run, unless merging allowed
119 
120  if (eMap_==0) //eMap_ not created yet
121  {
122  if (debug_>1) std::cout <<"\t<HcalMonitorModule::beginRun> Getting Emap!"<<std::endl;
124  c.get<HcalDbRecord>().get( pSetup );
125  eMap_=pSetup->getHcalMapping();
126  }
127  if (mergeRuns_) return;
128  this->setup();
129  this->reset();
130 
131 } //HcalMonitorModule::beginRun(....)
132 
133 
135 
136  if ( debug_>0 ) std::cout << "HcalMonitorModule: endRun" << std::endl;
137 
138  // end-of-run
139  if ( meStatus_ ) meStatus_->Fill(2);
140 
141  if ( meRun_ ) meRun_->Fill(runNumber_);
142  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
143 }
144 
146 {
147  if (debug_>0) std::cout <<"HcalMonitorModule::reset"<<std::endl;
148  // Call Reset() on all MonitorElement histograms
150  if (meFEDS_) meFEDS_->Reset();
151  if (meIevt_) meIevt_->Fill(0);
152  if (meIevtHist_) meIevtHist_->Reset();
153  if (meEvtsVsLS_) meEvtsVsLS_->Reset();
154  ievt_=0;
156  if (meHB_) meHB_->Fill(-1);
157  if (meHE_) meHE_->Fill(-1);
158  if (meHO_) meHO_->Fill(-1);
159  if (meHF_) meHF_->Fill(-1);
160  HBpresent_=0;
161  HEpresent_=0;
162  HOpresent_=0;
163  HFpresent_=0;
164  fedsListed_=false;
165 } // void HcalMonitorModule::reset(void)
166 
168 {
169  // Run this on first event in run; set up all necessary monitor elements
170  if (debug_>0) std::cout <<"HcalMonitorModule::setup"<<std::endl;
171  init_=true;
172  if (dbe_)
173  {
174  dbe_->setCurrentFolder(prefixME_+"HcalInfo");
175  meStatus_ = dbe_->bookInt("STATUS");
176  if (meStatus_) meStatus_->Fill(-1);
177  meRun_ = dbe_->bookInt("RUN");
178  if (meRun_) meRun_->Fill(-1);
179  meEvt_ = dbe_->bookInt("EVT");
180  if (meEvt_) meEvt_->Fill(-1);
181  meIevt_ = dbe_->bookInt("EventsProcessed");
182  if (meIevt_) meIevt_->Fill(-1);
183  meIevtHist_ = dbe_->book1D("EventsInHcalMonitorModule","Events Seen by HcalMonitorModule",1,0.5,1.5);
184  meIevtHist_->setBinLabel(1,"Nevents",1);
185  meEvtsVsLS_ = dbe_->book1D("EventsVsLS","Events vs. Luminosity Section;LS;# events",NLumiBlocks_,0.5,NLumiBlocks_+0.5);
186  meOnline_ = dbe_->bookInt("Online");
187  meOnline_->Fill((int)Online_);
188  meProcessedEndLumi_ = dbe_->bookInt("EndLumiBlock_MonitorModule");
190  meCurrentCalibType_= dbe_->bookInt("CURRENT_EVENT_TYPE");
192 
193  meHB_ = dbe_->bookInt("HBpresent");
194  meHE_ = dbe_->bookInt("HEpresent");
195  meHO_ = dbe_->bookInt("HOpresent");
196  meHF_ = dbe_->bookInt("HFpresent");
197  if (meHB_) meHB_->Fill(-1);
198  if (meHE_) meHE_->Fill(-1);
199  if (meHO_) meHO_->Fill(-1);
200  if (meHF_) meHF_->Fill(-1);
201 
202  meFEDS_ = dbe_->book1D("FEDs Unpacked","FEDs Unpacked; Hcal FEDs 700-731",1+(FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID),FEDNumbering::MINHCALFEDID-0.5,FEDNumbering::MAXHCALFEDID+0.5);
203 
204  meCalibType_ = dbe_->book1D("CalibrationType","Calibration Type",9,-0.5,8.5);
205  meCalibType_->setBinLabel(1,"Normal",1);
206  meCalibType_->setBinLabel(2,"Ped",1);
207  meCalibType_->setBinLabel(3,"RADDAM",1);
208  meCalibType_->setBinLabel(4,"HBHEHPD",1);
209  meCalibType_->setBinLabel(5,"HOHPD",1);
210  meCalibType_->setBinLabel(6,"HFPMT",1);
211  meCalibType_->setBinLabel(7,"ZDC",1);
212  meCalibType_->setBinLabel(8,"CASTOR",1);
213 
214  } // if (dbe_)
215  return;
216 } // void HcalMonitorModule::setup(void)
217 
218 
220 {
221  if (debug_>0) std::cout <<"HcalMonitorModule::cleanup"<<std::endl;
222  if (!enableCleanup_) return;
223  if (dbe_)
224  {
225  dbe_->setCurrentFolder(prefixME_+"HcalInfo");
226  if ( meStatus_ )
228  meStatus_ = 0;
229  if ( meRun_ )
231  meRun_ = 0;
232  if ( meEvt_ )
234  meEvt_ = 0;
235  if (meIevt_)
237  meIevt_=0;
238  if (meIevtHist_)
240  meIevtHist_=0;
241  if (meFEDS_)
243  meFEDS_ = 0;
244  if (meCalibType_)
246  meCalibType_ = 0;
247  if (meCurrentCalibType_)
250  if (meProcessedEndLumi_)
253  if (meHB_)
255  meHB_=0;
256 
257  if (meHE_)
259  meHE_=0;
260  if (meHO_)
262  meHO_=0;
263  if (meHF_)
265  meHF_=0;
266  } // if (dbe_)
267 
268  fedsListed_=false;
269  HBpresent_=0;
270  HEpresent_=0;
271  HOpresent_=0;
272  HFpresent_=0;
273  init_=false;
274 
275 } // void HcalMonitorModule::cleanup(void)
276 
277 
278 
280  const edm::EventSetup& c)
281 {
282  if (debug_>0) std::cout <<"HcalMonitorModule::beginLuminosityBlock"<<std::endl;
283 }// void HcalMonitorModule::beginLuminosityBlock(...)
284 
285 
286 
287 
289  const edm::EventSetup& c)
290 {
291  if (debug_>0) std::cout <<"HcalMonitorModule::endLuminosityBlock"<<std::endl;
293 }// void HcalMonitorModule::endLuminosityBlock(...)
294 
295 
296 
298 {
299  if (debug_>0) std::cout <<"HcalMonitorModule::endJob()"<<std::endl;
300  if (dbe_)
301  {
302  meStatus_ = dbe_->get(prefixME_ + "/EventInfo/STATUS");
303  meRun_ = dbe_->get(prefixME_ + "/EventInfo/RUN");
304  meEvt_ = dbe_->get(prefixME_ + "/EventInfo/EVT");
305  }
306  if (meStatus_) meStatus_->Fill(2);
307  if (meRun_) meRun_->Fill(runNumber_);
308  if (meEvt_) meEvt_->Fill(evtNumber_);
309  if (init_) this->cleanup();
310 } // void HcalMonitorModule::endJob(void)
311 
312 
313 
315 {
316  if (!init_) this->setup();
317 
318  LogDebug("HcalMonitorModule")<<"processing event "<<ievt_;
319 
320  // Fill Monitor Elements with run, evt, processed event info
321  ++ievt_;
322  runNumber_=e.id().run();
323  evtNumber_=e.id().event();
324  if (meRun_) meRun_->Fill(runNumber_);
325  if (meEvt_) meEvt_->Fill(evtNumber_);
326  if (meIevt_) meIevt_->Fill(ievt_);
327  if (meIevtHist_) meIevtHist_->Fill(1);
329  if (ievt_==1)
330  {
331  LogDebug("HcalMonitorModule") << "processing run " << runNumber_;
332  // begin-of-run
333  if ( meStatus_ ) meStatus_->Fill(0);
334  }
335  else
336  {
337  // running
338  if ( meStatus_ ) meStatus_->Fill(1);
339  }
340 
341  // Try to get raw data
343  if (!(e.getByLabel(FEDRawDataCollection_,rawraw)))
344  {
345  edm::LogWarning("HcalMonitorModule")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
346  return;
347  }
348 
349  // Get Event Calibration Type -- copy of Bryan Dahmes' filter
350  int calibType=-1;
351  int numEmptyFEDs = 0 ;
352  std::vector<int> calibTypeCounter(8,0) ;
354  {
355  const FEDRawData& fedData = rawraw->FEDData(i) ;
356 
357  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
358  if ( fedData.size() < 24 ) continue;
359 
360  int value = (int)((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
361  if(value>7)
362  {
363  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<<i<<" (should be 0-7). I am bailing out...";
364  return;
365  }
366 
367  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
368  } // for (int i = FEDNumbering::MINHCALFEDID; ...)
369 
370  int maxCount = 0;
371  int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
372  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
373  if ( calibTypeCounter.at(i) > maxCount )
374  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
375  if ( maxCount == numberOfFEDIds ) break ;
376  }
377 
378  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
379  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Conflicting calibration types found. Assigning type "
380  << calibType ;
381  LogDebug("HcalMonitorModule::CalibTypeFilter") << "Calibration type is: " << calibType ;
382  // Fill histogram of calibration types, as well as integer to keep track of current value
383  if (meCalibType_) meCalibType_->Fill(calibType);
386 
387  if (debug_>2) std::cout <<"\t<HcalMonitorModule> ievt = "<<ievt_<<" calibration type = "<<calibType<<std::endl;
388 
389  // Check to see which subdetectors are present.
390  // May only need to do this on first event? Subdets don't appear during a run?
391  if (HBpresent_==0)
393  if (HEpresent_==0)
395  if (HOpresent_==0)
397  if (HFpresent_==0)
399 
400  // Here, we do need this information each event
402  if (!(e.getByLabel(inputLabelReport_,report)))
403  {
404  edm::LogWarning("HcalMonitorModule")<<" Unpacker Report "<<inputLabelReport_<<" not available";
405  return;
406  }
407 
408  if (!fedsListed_)
409  {
410  const std::vector<int> feds = (*report).getFedsUnpacked();
411  for(unsigned int f=0; f<feds.size(); ++f)
412  meFEDS_->Fill(feds[f]);
413  fedsListed_ = true;
414  } // if (!fedsListed_)
415 
416 } // void HcalMonitorModule::analyze(...)
417 
418 
419 
421  HcalSubdetector subdet,
422  const HcalElectronicsMap& emap)
423 {
424 
425  std::vector<int> fedUnpackList;
426  for (int i=FEDNumbering::MINHCALFEDID;
428  i++)
429  fedUnpackList.push_back(i);
430 
431  if (debug_>1) std::cout <<"<HcalMonitorModule::CheckSubdetectorStatus> Checking subdetector "<<subdet<<std::endl;
432  for (std::vector<int>::const_iterator i=fedUnpackList.begin();
433  i!=fedUnpackList.end();
434  ++i)
435  {
436  if (debug_>2) std::cout <<"\t<HcalMonitorModule::CheckSubdetectorStatus> FED = "<<*i<<std::endl;
437  const FEDRawData& fed =(*rawraw).FEDData(*i);
438  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
439 
440  // get the DCC header
441  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fed.data());
442  if (!dccHeader) return;
443  int dccid=dccHeader->getSourceId();
444  // check for HF
445  if (subdet == HcalForward && dccid>717 && dccid<724)
446  {
447  HFpresent_=1;
449  return;
450  }
451  else if (subdet==HcalOuter && dccid>723)
452  {
453  HOpresent_=1;
455  return;
456  }
457  else if (dccid<718 && (subdet==HcalBarrel || subdet==HcalEndcap))
458  {
459  HcalHTRData htr;
460  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
461  {
462  if (!dccHeader->getSpigotPresent(spigot)) continue;
463 
464  // Load the given decoder with the pointer and length from this spigot.
465  dccHeader->getSpigotData(spigot,htr, fed.size());
466 
467  // check min length, correct wordcount, empty event, or total length if histo event.
468  if (!htr.check()) continue;
469  if (htr.isHistogramEvent()) continue;
470 
471  int firstFED = FEDNumbering::MINHCALFEDID;
472 
473  // Tease out HB and HE, which share HTRs in HBHE
474  for(int fchan=0; fchan<3; ++fchan) //0,1,2 are valid
475  {
476  for(int fib=1; fib<9; ++fib) //1...8 are valid
477  {
478  HcalElectronicsId eid(fchan,fib,spigot,dccid-firstFED);
479  eid.setHTR(htr.readoutVMECrateId(),
480  htr.htrSlot(),htr.htrTopBottom());
481 
482  DetId did=emap.lookup(eid);
483  if (!did.null())
484  {
485 
486  if ((HcalSubdetector)did.subdetId()==subdet)
487  {
488  if (subdet==HcalBarrel)
489  {
490  HBpresent_=1;
492  return;
493  }
494  else if (subdet==HcalEndcap)
495  {
496  HEpresent_=1;
498  return;
499  }
500  } // if ((HcalSubdetector)did.subdetId()==subdet)
501  } // if (!did.null())
502  } // for (int fib=1;fib<9;...)
503  } // for (int fchan=0; fchan<3;...)
504  } // for (int spigot=0;spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
505  } //else if (dcc<718 && (subdet...))
506  } // loop over fedUnpackList
507 
508 
509 } // void HcalMonitorModule::CheckSubdetectorStatus(...)
510 
#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:64
edm::InputTag FEDRawDataCollection_
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
Definition: HcalHTRData.cc:344
#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:49
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:340
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
HcalSubdetector
Definition: HcalAssistant.h:32
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:1468
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
MonitorElement * meHE_
int getSourceId() const
Definition: HcalDCCHeader.h:34
Definition: DetId.h:20
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:47
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
Definition: HcalHTRData.cc:348
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:21
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:29
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:624
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:429
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:387
Definition: Run.h:33
MonitorElement * meEvtsVsLS_