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  meIevt_=0;
88  meIevtHist_=0;
89  meEvtsVsLS_=0;
91  meHB_=0;
92  meHE_=0;
93  meHO_=0;
94  meHF_=0;
95  eMap_=0;
96 
97 } // HcalMonitorModule::HcalMonitorModule
98 
99 
100 //Destructor
102 {
103 
104 } //HcalMonitorModule::~HcalMonitorModule()
105 
107 {
108 
109  if ( debug_>0 ) std::cout << "HcalMonitorModule: dqmBeginRun" << std::endl;
110  // reset histograms & counters on a new run, unless merging allowed
111 
112  if (eMap_==0) //eMap_ not created yet
113  {
114  if (debug_>1) std::cout <<"\t<HcalMonitorModule::bookHistograms> Getting Emap!"<<std::endl;
116  es.get<HcalDbRecord>().get( pSetup );
117  eMap_=pSetup->getHcalMapping();
118  }
119  if (mergeRuns_) return;
120  this->reset();
121 
122 }
123 
124 
126 {
127  this->setup(ib);
128 } //HcalMonitorModule::beginRun(....)
129 
130 
132 
133  if ( debug_>0 ) std::cout << "HcalMonitorModule: endRun" << std::endl;
134 
135  // end-of-run
136  if ( meStatus_ ) meStatus_->Fill(2);
137 
138  if ( meRun_ ) meRun_->Fill(runNumber_);
139  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
140 }
141 
143 {
144  if (debug_>0) std::cout <<"HcalMonitorModule::reset"<<std::endl;
145  // Call Reset() on all MonitorElement histograms
147  if (meFEDS_) meFEDS_->Reset();
148  if (meIevt_) meIevt_->Fill(0);
149  if (meIevtHist_) meIevtHist_->Reset();
150  if (meEvtsVsLS_) meEvtsVsLS_->Reset();
151  ievt_=0;
153  if (meHB_) meHB_->Fill(-1);
154  if (meHE_) meHE_->Fill(-1);
155  if (meHO_) meHO_->Fill(-1);
156  if (meHF_) meHF_->Fill(-1);
157  HBpresent_=0;
158  HEpresent_=0;
159  HOpresent_=0;
160  HFpresent_=0;
161  fedsListed_=false;
162 } // void HcalMonitorModule::reset(void)
163 
165 {
166  // Run this on first event in run; set up all necessary monitor elements
167  if (debug_>0) std::cout <<"HcalMonitorModule::setup"<<std::endl;
168  ib.setCurrentFolder(prefixME_+"HcalInfo");
169  meStatus_ = ib.bookInt("STATUS");
170  if (meStatus_) meStatus_->Fill(-1);
171  meRun_ = ib.bookInt("RUN");
172  if (meRun_) meRun_->Fill(-1);
173  meEvt_ = ib.bookInt("EVT");
174  if (meEvt_) meEvt_->Fill(-1);
175  meIevt_ = ib.bookInt("EventsProcessed");
176  if (meIevt_) meIevt_->Fill(-1);
177  meIevtHist_ = ib.book1D("EventsInHcalMonitorModule","Events Seen by HcalMonitorModule",1,0.5,1.5);
178  meIevtHist_->setBinLabel(1,"Nevents",1);
179  meEvtsVsLS_ = ib.book1D("EventsVsLS","Events vs. Luminosity Section;LS;# events",NLumiBlocks_,0.5,NLumiBlocks_+0.5);
180  meOnline_ = ib.bookInt("Online");
181  meOnline_->Fill((int)Online_);
182  meProcessedEndLumi_ = ib.bookInt("EndLumiBlock_MonitorModule");
184  meCurrentCalibType_= ib.bookInt("CURRENT_EVENT_TYPE");
186 
187  meHB_ = ib.bookInt("HBpresent");
188  meHE_ = ib.bookInt("HEpresent");
189  meHO_ = ib.bookInt("HOpresent");
190  meHF_ = ib.bookInt("HFpresent");
191  if (meHB_) meHB_->Fill(-1);
192  if (meHE_) meHE_->Fill(-1);
193  if (meHO_) meHO_->Fill(-1);
194  if (meHF_) meHF_->Fill(-1);
195 
196  meFEDS_ = ib.book1D("FEDs Unpacked","FEDs Unpacked; Hcal FEDs 700-731",1+(FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID),FEDNumbering::MINHCALFEDID-0.5,FEDNumbering::MAXHCALFEDID+0.5);
197 
198  meCalibType_ = ib.book1D("CalibrationType","Calibration Type",9,-0.5,8.5);
199  meCalibType_->setBinLabel(1,"Normal",1);
200  meCalibType_->setBinLabel(2,"Ped",1);
201  meCalibType_->setBinLabel(3,"RADDAM",1);
202  meCalibType_->setBinLabel(4,"HBHEHPD",1);
203  meCalibType_->setBinLabel(5,"HOHPD",1);
204  meCalibType_->setBinLabel(6,"HFPMT",1);
205  meCalibType_->setBinLabel(7,"ZDC",1);
206  meCalibType_->setBinLabel(8,"CASTOR",1);
207 
208  return;
209 } // void HcalMonitorModule::setup(void)
210 
211 
213 {
214  if (debug_>0) std::cout <<"HcalMonitorModule::cleanup"<<std::endl;
215  if (!enableCleanup_) return;
216  // Removed calls to dbe_->RemoveElement
217 
218  fedsListed_=false;
219  HBpresent_=0;
220  HEpresent_=0;
221  HOpresent_=0;
222  HFpresent_=0;
223 
224 } // void HcalMonitorModule::cleanup(void)
225 
226 
227 
229  const edm::EventSetup& c)
230 {
231  if (debug_>0) std::cout <<"HcalMonitorModule::endLuminosityBlock"<<std::endl;
233 }// void HcalMonitorModule::endLuminosityBlock(...)
234 
235 
236 
237 
239 {
240 
241  LogDebug("HcalMonitorModule")<<"processing event "<<ievt_;
242 
243  // Fill Monitor Elements with run, evt, processed event info
244  ++ievt_;
245  runNumber_=e.id().run();
246  evtNumber_=e.id().event();
247  if (meRun_) meRun_->Fill(runNumber_);
248  if (meEvt_) meEvt_->Fill(evtNumber_);
249  if (meIevt_) meIevt_->Fill(ievt_);
250  if (meIevtHist_) meIevtHist_->Fill(1);
252  if (ievt_==1)
253  {
254  LogDebug("HcalMonitorModule") << "processing run " << runNumber_;
255  // begin-of-run
256  if ( meStatus_ ) meStatus_->Fill(0);
257  }
258  else
259  {
260  // running
261  if ( meStatus_ ) meStatus_->Fill(1);
262  }
263 
264  // Try to get raw data
266  if (!(e.getByToken(tok_raw_,rawraw)))
267  {
268  edm::LogWarning("HcalMonitorModule")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
269  return;
270  }
271 
272  // Get Event Calibration Type -- copy of Bryan Dahmes' filter
273  int calibType=-1;
274  int numEmptyFEDs = 0 ;
275  std::vector<int> calibTypeCounter(8,0) ;
277  {
278  const FEDRawData& fedData = rawraw->FEDData(i) ;
279 
280  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
281  if ( fedData.size() < 24 ) continue;
282 
283  int value = (int)((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
284  if(value>7)
285  {
286  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<<i<<" (should be 0-7). I am bailing out...";
287  return;
288  }
289 
290  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
291  } // for (int i = FEDNumbering::MINHCALFEDID; ...)
292 
293  int maxCount = 0;
294  int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
295  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
296  if ( calibTypeCounter.at(i) > maxCount )
297  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
298  if ( maxCount == numberOfFEDIds ) break ;
299  }
300 
301  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
302  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Conflicting calibration types found. Assigning type "
303  << calibType ;
304  LogDebug("HcalMonitorModule::CalibTypeFilter") << "Calibration type is: " << calibType ;
305  // Fill histogram of calibration types, as well as integer to keep track of current value
306  if (meCalibType_) meCalibType_->Fill(calibType);
309 
310  if (debug_>2) std::cout <<"\t<HcalMonitorModule> ievt = "<<ievt_<<" calibration type = "<<calibType<<std::endl;
311 
312  // Check to see which subdetectors are present.
313  // May only need to do this on first event? Subdets don't appear during a run?
314  if (HBpresent_==0)
316  if (HEpresent_==0)
318  if (HOpresent_==0)
320  if (HFpresent_==0)
322 
323  // Here, we do need this information each event
325  if (!(e.getByToken(tok_report_,report)))
326  {
327  edm::LogWarning("HcalMonitorModule")<<" Unpacker Report "<<inputLabelReport_<<" not available";
328  return;
329  }
330 
331  if (!fedsListed_)
332  {
333  const std::vector<int> feds = (*report).getFedsUnpacked();
334  for(unsigned int f=0; f<feds.size(); ++f)
335  meFEDS_->Fill(feds[f]);
336  fedsListed_ = true;
337  } // if (!fedsListed_)
338 
339 } // void HcalMonitorModule::analyze(...)
340 
341 
342 
344  HcalSubdetector subdet,
345  const HcalElectronicsMap& emap)
346 {
347 
348  std::vector<int> fedUnpackList;
349  for (int i=FEDNumbering::MINHCALFEDID;
351  i++)
352  fedUnpackList.push_back(i);
353 
354  if (debug_>1) std::cout <<"<HcalMonitorModule::CheckSubdetectorStatus> Checking subdetector "<<subdet<<std::endl;
355  for (std::vector<int>::const_iterator i=fedUnpackList.begin();
356  i!=fedUnpackList.end();
357  ++i)
358  {
359  if (debug_>2) std::cout <<"\t<HcalMonitorModule::CheckSubdetectorStatus> FED = "<<*i<<std::endl;
360  const FEDRawData& fed =(*rawraw).FEDData(*i);
361  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
362 
363  // get the DCC header
364  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fed.data());
365  if (!dccHeader) return;
366  int dccid=dccHeader->getSourceId();
367  // check for HF
368  if (subdet == HcalForward && dccid>717 && dccid<724)
369  {
370  HFpresent_=1;
372  return;
373  }
374  else if (subdet==HcalOuter && dccid>723)
375  {
376  HOpresent_=1;
378  return;
379  }
380  else if (dccid<718 && (subdet==HcalBarrel || subdet==HcalEndcap))
381  {
382  HcalHTRData htr;
383  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
384  {
385  if (!dccHeader->getSpigotPresent(spigot)) continue;
386 
387  // Load the given decoder with the pointer and length from this spigot.
388  dccHeader->getSpigotData(spigot,htr, fed.size());
389 
390  // check min length, correct wordcount, empty event, or total length if histo event.
391  if (!htr.check()) continue;
392  if (htr.isHistogramEvent()) continue;
393 
394  int firstFED = FEDNumbering::MINHCALFEDID;
395 
396  // Tease out HB and HE, which share HTRs in HBHE
397  for(int fchan=0; fchan<3; ++fchan) //0,1,2 are valid
398  {
399  for(int fib=1; fib<9; ++fib) //1...8 are valid
400  {
401  HcalElectronicsId eid(fchan,fib,spigot,dccid-firstFED);
402  eid.setHTR(htr.readoutVMECrateId(),
403  htr.htrSlot(),htr.htrTopBottom());
404 
405  DetId did=emap.lookup(eid);
406  if (!did.null())
407  {
408 
409  if ((HcalSubdetector)did.subdetId()==subdet)
410  {
411  if (subdet==HcalBarrel)
412  {
413  HBpresent_=1;
415  return;
416  }
417  else if (subdet==HcalEndcap)
418  {
419  HEpresent_=1;
421  return;
422  }
423  } // if ((HcalSubdetector)did.subdetId()==subdet)
424  } // if (!did.null())
425  } // for (int fib=1;fib<9;...)
426  } // for (int fchan=0; fchan<3;...)
427  } // for (int spigot=0;spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
428  } //else if (dcc<718 && (subdet...))
429  } // loop over fedUnpackList
430 
431 
432 } // void HcalMonitorModule::CheckSubdetectorStatus(...)
433 
#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:446
#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:59
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 &)
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:274
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: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_
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:41
edm::EDGetTokenT< HcalUnpackerReport > tok_report_
MonitorElement * meEvtsVsLS_