CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZDCMonitorModule.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 ZDCMonitorModule.cc
43  *
44  * $Date: 2013/01/05 19:47:01 $
45  * $Revision: 1.7 $
46  * \author J Temple
47  *
48  * JAIME! UPDATE THIS INFO FOR ZDC!
49  * New version of ZDCMonitorModule stores only a few necessary variables that other tasks need to grab
50  * (Online_ boolean, subsystem folder name, subdetector presence check, etc.)
51  * Modeled heavily on EcalBarrelMonitorModule code.
52 
53  * 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.
54 
55 */
56 
57 
58 //Constructor
59 
61 { // Set initial values
62  init_=false; // first event sets up Monitor Elements and sets init_ to true
63 
64  // get ps objects
65  Online_ = ps.getUntrackedParameter<bool>("online",false);
66  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
67  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
68  debug_ = ps.getUntrackedParameter<int>("debug",0);
69 
70  FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection");
72 
73  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
74  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
75  prefixME_.append("/");
76 
77  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
78 
79 } // ZDCMonitorModule::ZDCMonitorModule
80 
81 
82 //Destructor
84 {
85 
86 } //ZDCMonitorModule::~ZDCMonitorModule()
87 
88 
89 
91 {
92  if (debug_>0) std::cout <<"ZDCMonitorModule::beginJob()"<<std::endl;
93  // Get DQM service
95  // set default values
96  ievt_=0;
97  fedsListed_=false;
98  ZDCpresent_=0;
99  // Set pointers to null
100  meCalibType_=0;
101  meFEDS_=0;
102  meIevt_=0;
103  meIevtHist_=0;
104  meEvtsVsLS_=0;
106  meZDC_=0;
107 
108 }
109 
111 {
112  if ( debug_>0 ) std::cout << "ZDCMonitorModule: beginRun" << std::endl;
113  // reset histograms & counters on a new run, unless merging allowed
114 
115  if (eMap_==0) //eMap_ not created yet
116  {
117  if (debug_>1) std::cout <<"\t<ZDCMonitorModule::beginRun> Getting Emap!"<<std::endl;
119  c.get<HcalDbRecord>().get( pSetup );
120  eMap_=pSetup->getHcalMapping();
121  }
122  if (mergeRuns_) return;
123  this->setup();
124  this->reset();
125 
126 } //ZDCMonitorModule::beginRun(....)
127 
128 
130 
131  if ( debug_>0 ) std::cout << "ZDCMonitorModule: endRun" << std::endl;
132 
133  // end-of-run
134  if ( meStatus_ ) meStatus_->Fill(2);
135 
136  if ( meRun_ ) meRun_->Fill(runNumber_);
137  if ( meEvt_ ) meEvt_->Fill(evtNumber_);
138 }
139 
141 {
142  if (debug_>0) std::cout <<"ZDCMonitorModule::reset"<<std::endl;
143  // Call Reset() on all MonitorElement histograms
145  if (meFEDS_) meFEDS_->Reset();
146  if (meIevt_) meIevt_->Fill(0);
147  if (meIevtHist_) meIevtHist_->Reset();
148  if (meEvtsVsLS_) meEvtsVsLS_->Reset();
149  ievt_=0;
151  if (meZDC_) meZDC_->Fill(-1);
152  ZDCpresent_=0;
153 
154  fedsListed_=false;
155 } // void ZDCMonitorModule::reset(void)
156 
158 {
159  // Run this on first event in run; set up all necessary monitor elements
160  if (debug_>0) std::cout <<"ZDCMonitorModule::setup"<<std::endl;
161  init_=true;
162  if (dbe_)
163  {
164  dbe_->setCurrentFolder(prefixME_+"ZDCInfo");
165  meStatus_ = dbe_->bookInt("STATUS");
166  if (meStatus_) meStatus_->Fill(-1);
167  meRun_ = dbe_->bookInt("RUN");
168  if (meRun_) meRun_->Fill(-1);
169  meEvt_ = dbe_->bookInt("EVT");
170  if (meEvt_) meEvt_->Fill(-1);
171  meIevt_ = dbe_->bookInt("EventsProcessed");
172  if (meIevt_) meIevt_->Fill(-1);
173  meIevtHist_ = dbe_->book1D("EventsInZDCMonitorModule","Events Seen by ZDCMonitorModule",1,0.5,1.5);
174  meIevtHist_->setBinLabel(1,"Nevents",1);
175  meEvtsVsLS_ = dbe_->book1D("EventsVsLS","Events vs. Luminosity Section;LS;# events",NLumiBlocks_,0.5,NLumiBlocks_+0.5);
176  meOnline_ = dbe_->bookInt("Online");
177  meOnline_->Fill((int)Online_);
178  meProcessedEndLumi_ = dbe_->bookInt("EndLumiBlock_MonitorModule");
180  meCurrentCalibType_= dbe_->bookInt("CURRENT_EVENT_TYPE");
182 
183  meZDC_ = dbe_->bookInt("ZDCpresent");
184  if (meZDC_) meZDC_->Fill(-1);
185 
186  meFEDS_ = dbe_->book1D("FEDs Unpacked","FEDs Unpacked; Hcal FEDs 700-731",1+(FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID),FEDNumbering::MINHCALFEDID-0.5,FEDNumbering::MAXHCALFEDID+0.5);
187 
188  meCalibType_ = dbe_->book1D("CalibrationType","Calibration Type",9,-0.5,8.5);
189  meCalibType_->setBinLabel(1,"Normal",1);
190  meCalibType_->setBinLabel(2,"Ped",1);
191  meCalibType_->setBinLabel(3,"RADDAM",1);
192  meCalibType_->setBinLabel(4,"HBHEHPD",1);
193  meCalibType_->setBinLabel(5,"HOHPD",1);
194  meCalibType_->setBinLabel(6,"HFPMT",1);
195  meCalibType_->setBinLabel(7,"ZDC",1); // Is this used for ZDC calibraitons??
196  meCalibType_->setBinLabel(8,"CASTOR",1);
197 
198  } // if (dbe_)
199  return;
200 } // void ZDCMonitorModule::setup(void)
201 
202 
204 {
205  if (debug_>0) std::cout <<"ZDCMonitorModule::cleanup"<<std::endl;
206  if (!enableCleanup_) return;
207  if (dbe_)
208  {
209  dbe_->setCurrentFolder(prefixME_+"ZDCInfo");
210  if ( meStatus_ )
212  meStatus_ = 0;
213  if ( meRun_ )
215  meRun_ = 0;
216  if ( meEvt_ )
218  meEvt_ = 0;
219  if (meIevt_)
221  meIevt_=0;
222  if (meIevtHist_)
224  meIevtHist_=0;
225  if (meFEDS_)
227  meFEDS_ = 0;
228  if (meCalibType_)
230  meCalibType_ = 0;
231  if (meCurrentCalibType_)
234  if (meProcessedEndLumi_)
237  if (meZDC_)
239  meZDC_=0;
240  } // if (dbe_)
241 
242  fedsListed_=false;
243  ZDCpresent_=0;
244  init_=false;
245 
246 } // void ZDCMonitorModule::cleanup(void)
247 
248 
249 
251  const edm::EventSetup& c)
252 {
253  if (debug_>0) std::cout <<"ZDCMonitorModule::beginLuminosityBlock"<<std::endl;
254 }// void ZDCMonitorModule::beginLuminosityBlock(...)
255 
256 
257 
258 
260  const edm::EventSetup& c)
261 {
262  if (debug_>0) std::cout <<"ZDCMonitorModule::endLuminosityBlock"<<std::endl;
264 }// void ZDCMonitorModule::endLuminosityBlock(...)
265 
266 
267 
269 {
270  if (debug_>0) std::cout <<"ZDCMonitorModule::endJob()"<<std::endl;
271  if (dbe_)
272  {
273  meStatus_ = dbe_->get(prefixME_ + "/EventInfo/STATUS");
274  meRun_ = dbe_->get(prefixME_ + "/EventInfo/RUN");
275  meEvt_ = dbe_->get(prefixME_ + "/EventInfo/EVT");
276  }
277  if (meStatus_) meStatus_->Fill(2);
278  if (meRun_) meRun_->Fill(runNumber_);
279  if (meEvt_) meEvt_->Fill(evtNumber_);
280  if (init_) this->cleanup();
281 } // void ZDCMonitorModule::endJob(void)
282 
283 
284 
286 {
287  if (!init_) this->setup();
288 
289  LogDebug("ZDCMonitorModule")<<"processing event "<<ievt_;
290 
291  // Fill Monitor Elements with run, evt, processed event info
292  ++ievt_;
293  runNumber_=e.id().run();
294  evtNumber_=e.id().event();
295  if (meRun_) meRun_->Fill(runNumber_);
296  if (meEvt_) meEvt_->Fill(evtNumber_);
297  if (meIevt_) meIevt_->Fill(ievt_);
298  if (meIevtHist_) meIevtHist_->Fill(1);
300  if (ievt_==1)
301  {
302  LogDebug("ZDCMonitorModule") << "processing run " << runNumber_;
303  // begin-of-run
304  if ( meStatus_ ) meStatus_->Fill(0);
305  }
306  else
307  {
308  // running
309  if ( meStatus_ ) meStatus_->Fill(1);
310  }
311 
312  // Try to get raw data
314  if (!(e.getByLabel(FEDRawDataCollection_,rawraw)))
315  {
316  edm::LogWarning("ZDCMonitorModule")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
317  return;
318  }
319 
320  // Get Event Calibration Type -- copy of Bryan Dahmes' filter
321  int calibType=-1;
322  int numEmptyFEDs = 0 ;
323  std::vector<int> calibTypeCounter(8,0) ;
325  {
326  const FEDRawData& fedData = rawraw->FEDData(i) ;
327 
328  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
329  if ( fedData.size() < 24 ) continue;
330 
331  int value = (int)((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
332  if(value>7)
333  {
334  edm::LogWarning("ZDCMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<<i<<" (should be 0-7). I am bailing out...";
335  return;
336  }
337 
338  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
339  } // for (int i = FEDNumbering::MINHCALFEDID; ...)
340 
341  int maxCount = 0;
342  int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
343  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
344  if ( calibTypeCounter.at(i) > maxCount )
345  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
346  if ( maxCount == numberOfFEDIds ) break ;
347  }
348 
349  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
350  edm::LogWarning("ZDCMonitorModule::CalibTypeFilter") << "Conflicting calibration types found. Assigning type "
351  << calibType ;
352  LogDebug("ZDCMonitorModule::CalibTypeFilter") << "Calibration type is: " << calibType ;
353  // Fill histogram of calibration types, as well as integer to keep track of current value
354  if (meCalibType_) meCalibType_->Fill(calibType);
357 
358  if (debug_>2) std::cout <<"\t<ZDCMonitorModule> ievt = "<<ievt_<<" calibration type = "<<calibType<<std::endl;
359 
360  // Check to see which subdetectors are present.
361  // May only need to do this on first event? Subdets don't appear during a run?
362  if (ZDCpresent_==0)
363  CheckSubdetectorStatus(rawraw, *eMap_);
364 
365 
366  // Here, we do need this information each event
368  if (!(e.getByLabel(inputLabelReport_,report)))
369  {
370  edm::LogWarning("ZDCMonitorModule")<<" Unpacker Report "<<inputLabelReport_<<" not available";
371  return;
372  }
373 
374  if (!fedsListed_)
375  {
376  const std::vector<int> feds = (*report).getFedsUnpacked();
377  for(unsigned int f=0; f<feds.size(); ++f)
378  meFEDS_->Fill(feds[f]);
379  fedsListed_ = true;
380  } // if (!fedsListed_)
381 
382 } // void ZDCMonitorModule::analyze(...)
383 
384 
385 
387  const HcalElectronicsMap& emap)
388 {
389 
390  std::vector<int> fedUnpackList;
391  for (int i=FEDNumbering::MINHCALFEDID;
393  i++)
394  fedUnpackList.push_back(i);
395 
396  if (debug_>1) std::cout <<"<ZDCMonitorModule::CheckSubdetectorStatus> Checking ZDC "<<std::endl;
397  for (std::vector<int>::const_iterator i=fedUnpackList.begin();
398  i!=fedUnpackList.end();
399  ++i)
400  {
401  if (debug_>2) std::cout <<"\t<ZDCMonitorModule::CheckSubdetectorStatus> FED = "<<*i<<std::endl;
402  const FEDRawData& fed =(*rawraw).FEDData(*i);
403  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
404 
405  // get the DCC header
406  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fed.data());
407  if (!dccHeader) return;
408  //int dccid=dccHeader->getSourceId();
409 
410  // This is how HcalForward data is identified:
411  //if (subdet == HcalForward && dccid>717 && dccid<724)
412  // check for ZDC at some point -- how?
413  // For now, just assume ZDC info is present, with dummy condition
414  if (1>0)
415  {
416  ZDCpresent_=1;
418  break;
419  }
420  } //loop over fedUnpack list
421 
422 } // void ZDCMonitorModule::CheckSubdetectorStatus(...)
423 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
void beginRun(const edm::Run &run, const edm::EventSetup &c)
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 * meOnline_
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
MonitorElement * meRun_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string prefixME_
ZDCMonitorModule(const edm::ParameterSet &ps)
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
void analyze(const edm::Event &e, const edm::EventSetup &c)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
tuple report
Definition: zeeHLT_cff.py:9
const HcalElectronicsMap * eMap_
MonitorElement * meEvtsVsLS_
MonitorElement * meEvt_
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
void endRun(const edm::Run &run, const edm::EventSetup &c)
MonitorElement * meZDC_
double f[11][100]
MonitorElement * meCalibType_
MonitorElement * meIevt_
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag inputLabelReport_
const T & get() const
Definition: EventSetup.h:55
MonitorElement * meProcessedEndLumi_
edm::EventID id() const
Definition: EventBase.h:56
edm::InputTag FEDRawDataCollection_
MonitorElement * meStatus_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
tuple cout
Definition: gather_cfg.py:121
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:624
void CheckSubdetectorStatus(const edm::Handle< FEDRawDataCollection > &rawraw, const HcalElectronicsMap &emap)
void Reset(void)
reset ME (ie. contents, errors, etc)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
MonitorElement * meFEDS_
Definition: Run.h:33
MonitorElement * meIevtHist_
MonitorElement * meCurrentCalibType_