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 
58  // get ps objects
59  Online_ = ps.getUntrackedParameter<bool>("online",false);
60  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
61  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
62  debug_ = ps.getUntrackedParameter<int>("debug",0);
63 
64  FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection");
65  tok_raw_ = consumes<FEDRawDataCollection>(FEDRawDataCollection_);
66 
68  tok_report_ = consumes<HcalUnpackerReport>(inputLabelReport_);
69 
70  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
71  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
72  prefixME_.append("/");
73 
74  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
75 
76  // beginJob contents
77  // set default values
78  ievt_=0;
79  fedsListed_=false;
80  HBpresent_=0;
81  HEpresent_=0;
82  HOpresent_=0;
83  HFpresent_=0;
84  // Set pointers to null
85  meCalibType_=0;
86  meFEDS_=0;
87  meUTCAFEDS_=0;
88  meIevt_=0;
89  meIevtHist_=0;
90  meEvtsVsLS_=0;
92  meHB_=0;
93  meHE_=0;
94  meHO_=0;
95  meHF_=0;
96  eMap_=0;
97 
98 } // HcalMonitorModule::HcalMonitorModule
99 
100 
101 //Destructor
103 {
104 
105 } //HcalMonitorModule::~HcalMonitorModule()
106 
108 {
109 
110  if ( debug_>0 ) std::cout << "HcalMonitorModule: dqmBeginRun" << std::endl;
111  // reset histograms & counters on a new run, unless merging allowed
112 
113  if (eMap_==0) //eMap_ not created yet
114  {
115  if (debug_>1) std::cout <<"\t<HcalMonitorModule::bookHistograms> Getting Emap!"<<std::endl;
117  es.get<HcalDbRecord>().get( pSetup );
118  eMap_=pSetup->getHcalMapping();
119  }
120  if (mergeRuns_) return;
121  this->reset();
122 
123 }
124 
125 
127 {
128  this->setup(ib);
129 } //HcalMonitorModule::beginRun(....)
130 
131 
133 
134  if ( debug_>0 ) std::cout << "HcalMonitorModule: endRun" << std::endl;
135 
136  // end-of-run
137  if ( meStatus_ ) meStatus_->Fill(2);
138 
139  if ( meRun_ ) meRun_->Fill(runNumber_);
140  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
141 }
142 
144 {
145  if (debug_>0) std::cout <<"HcalMonitorModule::reset"<<std::endl;
146  // Call Reset() on all MonitorElement histograms
148  if (meFEDS_) meFEDS_->Reset();
149  if (meUTCAFEDS_) meUTCAFEDS_->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  ib.setCurrentFolder(prefixME_+"HcalInfo");
171  meStatus_ = ib.bookInt("STATUS");
172  if (meStatus_) meStatus_->Fill(-1);
173  meRun_ = ib.bookInt("RUN");
174  if (meRun_) meRun_->Fill(-1);
175  meEvt_ = ib.bookInt("EVT");
176  if (meEvt_) meEvt_->Fill(-1);
177  meIevt_ = ib.bookInt("EventsProcessed");
178  if (meIevt_) meIevt_->Fill(-1);
179  meIevtHist_ = ib.book1D("EventsInHcalMonitorModule","Events Seen by HcalMonitorModule",1,0.5,1.5);
180  meIevtHist_->setBinLabel(1,"Nevents",1);
181  meEvtsVsLS_ = ib.book1D("EventsVsLS","Events vs. Luminosity Section;LS;# events",NLumiBlocks_,0.5,NLumiBlocks_+0.5);
182  meOnline_ = ib.bookInt("Online");
183  meOnline_->Fill((int)Online_);
184  meProcessedEndLumi_ = ib.bookInt("EndLumiBlock_MonitorModule");
186  meCurrentCalibType_= ib.bookInt("CURRENT_EVENT_TYPE");
188 
189  meHB_ = ib.bookInt("HBpresent");
190  meHE_ = ib.bookInt("HEpresent");
191  meHO_ = ib.bookInt("HOpresent");
192  meHF_ = ib.bookInt("HFpresent");
193  if (meHB_) meHB_->Fill(-1);
194  if (meHE_) meHE_->Fill(-1);
195  if (meHO_) meHO_->Fill(-1);
196  if (meHF_) meHF_->Fill(-1);
197 
198  meFEDS_ = ib.book1D("FEDs Unpacked","FEDs Unpacked; Hcal FEDs 700-731",1+(FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID),FEDNumbering::MINHCALFEDID-0.5,FEDNumbering::MAXHCALFEDID+0.5);
199  meUTCAFEDS_ = ib.book1D("uTCA FEDs Unpacked",
200  "uTCA FEDs Unpacked; Hcal uTCA FEDs 1118, 1120, 1122",
201  5, 1117.5, 1122.5);
202 
203  meCalibType_ = ib.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  return;
214 } // void HcalMonitorModule::setup(void)
215 
216 
218 {
219  if (debug_>0) std::cout <<"HcalMonitorModule::cleanup"<<std::endl;
220  if (!enableCleanup_) return;
221  // Removed calls to dbe_->RemoveElement
222 
223  fedsListed_=false;
224  HBpresent_=0;
225  HEpresent_=0;
226  HOpresent_=0;
227  HFpresent_=0;
228 
229 } // void HcalMonitorModule::cleanup(void)
230 
231 
232 
234  const edm::EventSetup& c)
235 {
236  if (debug_>0) std::cout <<"HcalMonitorModule::endLuminosityBlock"<<std::endl;
238 }// void HcalMonitorModule::endLuminosityBlock(...)
239 
240 
241 
242 
244 {
245 
246  LogDebug("HcalMonitorModule")<<"processing event "<<ievt_;
247 
248  // Fill Monitor Elements with run, evt, processed event info
249  ++ievt_;
250  runNumber_=e.id().run();
251  evtNumber_=e.id().event();
252  if (meRun_) meRun_->Fill(runNumber_);
253  if (meEvt_) meEvt_->Fill(evtNumber_);
254  if (meIevt_) meIevt_->Fill(ievt_);
255  if (meIevtHist_) meIevtHist_->Fill(1);
257  if (ievt_==1)
258  {
259  LogDebug("HcalMonitorModule") << "processing run " << runNumber_;
260  // begin-of-run
261  if ( meStatus_ ) meStatus_->Fill(0);
262  }
263  else
264  {
265  // running
266  if ( meStatus_ ) meStatus_->Fill(1);
267  }
268 
269  // Try to get raw data
271  if (!(e.getByToken(tok_raw_,rawraw)))
272  {
273  edm::LogWarning("HcalMonitorModule")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
274  return;
275  }
276 
277  // Get Event Calibration Type -- copy of Bryan Dahmes' filter
278  int calibType=-1;
279  int numEmptyFEDs = 0 ;
280  std::vector<int> calibTypeCounter(8,0) ;
281  for(int i = FEDNumbering::MINHCALFEDID;
283  {
285  continue;
286 
287  if (debug_>0)
288  std::cout << "### Processin FED: " << i << std::endl;
289 
290  const FEDRawData& fedData = rawraw->FEDData(i) ;
291 
292  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
293  if ( fedData.size() < 24 ) continue;
294 
295  int value = (int)((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
296  if (debug_>0)
297  std::cout << "### FED: " << i << " CalibType: " << value
298  << std::endl;
299 
300  if(value>7)
301  {
302  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<< i <<" (should be 0-7). I am bailing out...";
303  return;
304  }
305 
306  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
307  } // for (int i = FEDNumbering::MINHCALFEDID; ...)
308 
309  int maxCount = 0;
310  int numberOfFEDIds = (FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID+1) +
312  if (debug_>0)
313  std::cout << "numberOfFEDIds=" << numberOfFEDIds << std::endl
314  << "number of emptyFEDs=" << numEmptyFEDs << std::endl;
315  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
316  if ( calibTypeCounter.at(i) > maxCount )
317  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
318  if ( maxCount == numberOfFEDIds ) break ;
319  }
320 
321  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
322  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Conflicting calibration types found. Assigning type "
323  << calibType ;
324  LogDebug("HcalMonitorModule::CalibTypeFilter") << "Calibration type is: " << calibType ;
325  // Fill histogram of calibration types, as well as integer to keep track of current value
326  if (meCalibType_) meCalibType_->Fill(calibType);
329 
330  if (debug_>2) std::cout <<"\t<HcalMonitorModule> ievt = "<<ievt_<<" calibration type = "<<calibType<<std::endl;
331 
332  // Check to see which subdetectors are present.
333  // May only need to do this on first event? Subdets don't appear during a run?
334  if (HBpresent_==0)
336  if (HEpresent_==0)
338  if (HOpresent_==0)
340  if (HFpresent_==0)
342 
343  // Here, we do need this information each event
345 // edm::Handle<HcalUnpackerReport> reportUTCA;
346 /* if (!(e.getByToken(tok_reportUTCA_, reportUTCA)));
347  {
348  edm::LogWarning("HcalMonitorModule") << "uTCA Unpacker Report "
349  << inputLabelReportUTCA_ << " not availalbe";
350  return;
351  }*/
352  if (!(e.getByToken(tok_report_,report)))
353  {
354  edm::LogWarning("HcalMonitorModule")<<" Unpacker Report "<<inputLabelReport_<<" not available";
355  return;
356  }
357 
358  if (!fedsListed_)
359  {
360  const std::vector<int> feds = (*report).getFedsUnpacked();
361  for(unsigned int f=0; f<feds.size(); ++f)
362  if (feds[f]<1118)
363  meFEDS_->Fill(feds[f]);
364  else
365  meUTCAFEDS_->Fill(feds[f]);
366  fedsListed_ = true;
367  } // if (!fedsListed_)
368 
369 } // void HcalMonitorModule::analyze(...)
370 
371 
372 
374  HcalSubdetector subdet,
375  const HcalElectronicsMap& emap)
376 {
377 
378  std::vector<int> fedUnpackList;
379  for (int i=FEDNumbering::MINHCALFEDID;
381  i++)
382  {
384  continue;
385  fedUnpackList.push_back(i);
386  }
387 
388 
389  if (debug_>1) std::cout <<"<HcalMonitorModule::CheckSubdetectorStatus> Checking subdetector "<<subdet<<std::endl;
390  for (std::vector<int>::const_iterator i=fedUnpackList.begin();
391  i!=fedUnpackList.end();
392  ++i)
393  {
394  if (debug_>2) std::cout <<"\t<HcalMonitorModule::CheckSubdetectorStatus> FED = "<<*i<<std::endl;
395  const FEDRawData& fed =(*rawraw).FEDData(*i);
396  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
397 
398  // get the DCC header
399  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fed.data());
400  if (!dccHeader) return;
401  int dccid=dccHeader->getSourceId();
402  // check for HF
403 // if (subdet == HcalForward && dccid>717 && dccid<724)
404  if (subdet==HcalForward && ((dccid>=1118 && dccid<=1122) ||
405  (dccid>=718 && dccid<=723)))
406  {
407  HFpresent_=1;
409  return;
410  }
411  else if (subdet==HcalOuter && dccid>723)
412  {
413  HOpresent_=1;
415  return;
416  }
417  else if (dccid<718 && (subdet==HcalBarrel || subdet==HcalEndcap))
418  {
419  HcalHTRData htr;
420  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
421  {
422  if (!dccHeader->getSpigotPresent(spigot)) continue;
423 
424  // Load the given decoder with the pointer and length from this spigot.
425  dccHeader->getSpigotData(spigot,htr, fed.size());
426 
427  // check min length, correct wordcount, empty event, or total length if histo event.
428  if (!htr.check()) continue;
429  if (htr.isHistogramEvent()) continue;
430 
431  int firstFED = FEDNumbering::MINHCALFEDID;
432 
433  // Tease out HB and HE, which share HTRs in HBHE
434  for(int fchan=0; fchan<3; ++fchan) //0,1,2 are valid
435  {
436  for(int fib=1; fib<9; ++fib) //1...8 are valid
437  {
438  HcalElectronicsId eid(fchan,fib,spigot,dccid-firstFED);
439  eid.setHTR(htr.readoutVMECrateId(),
440  htr.htrSlot(),htr.htrTopBottom());
441 
442  DetId did=emap.lookup(eid);
443  if (!did.null())
444  {
445 
446  if ((HcalSubdetector)did.subdetId()==subdet)
447  {
448  if (subdet==HcalBarrel)
449  {
450  HBpresent_=1;
452  return;
453  }
454  else if (subdet==HcalEndcap)
455  {
456  HEpresent_=1;
458  return;
459  }
460  } // if ((HcalSubdetector)did.subdetId()==subdet)
461  } // if (!did.null())
462  } // for (int fib=1;fib<9;...)
463  } // for (int fchan=0; fchan<3;...)
464  } // for (int spigot=0;spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
465  } //else if (dcc<718 && (subdet...))
466  } // loop over fedUnpackList
467 
468 
469 } // void HcalMonitorModule::CheckSubdetectorStatus(...)
470 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * meStatus_
edm::InputTag inputLabelReport_
MonitorElement * meHB_
int ib
Definition: cuy.py:660
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_
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:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
tuple calibType
Definition: diJetCalib.py:20
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:103
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:62
MonitorElement * meHO_
edm::EventNumber_t evtNumber_
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_
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
Definition: HcalHTRData.cc:338
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
void dqmBeginRun(edm::Run const &, edm::EventSetup const &)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
HcalSubdetector
Definition: HcalAssistant.h:31
double f[11][100]
void setup(DQMStore::IBooker &)
MonitorElement * meUTCAFEDS_
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
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 setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:273
edm::RunNumber_t runNumber_
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
MonitorElement * meRun_
HcalMonitorModule(const edm::ParameterSet &ps)
const T & get() const
Definition: EventSetup.h:56
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:59
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:145
MonitorElement * meHF_
MonitorElement * meOnline_
void Reset(void)
reset ME (ie. contents, errors, etc)
Readout chain identification for Hcal.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385
Definition: Run.h:43
edm::EDGetTokenT< HcalUnpackerReport > tok_report_
MonitorElement * meEvtsVsLS_