CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDeadCellClient.cc
Go to the documentation of this file.
4 
8 
9 #include <iostream>
10 
11 /*
12  * \file HcalDeadCellClient.cc
13  *
14  * \author J. Temple
15  * \brief Dead Cell Client class
16  */
17 
19 {
20  name_=myname;
21  std::cout <<"MY NAME = "<<name_.c_str()<<std::endl;
22 }
23 
25 {
26  name_=myname;
27  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
28  debug_ = ps.getUntrackedParameter<int>("debug",0);
29  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
30  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
31  prefixME_.append("/");
32  subdir_ = ps.getUntrackedParameter<std::string>("DeadCellFolder","DeadCellMonitor_Hcal/"); // DeadCellMonitor_Hcal
33  if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
34  subdir_.append("/");
35  subdir_=prefixME_+subdir_;
36 
37  validHtmlOutput_ = ps.getUntrackedParameter<bool>("DeadCell_validHtmlOutput",true);
38  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
39  badChannelStatusMask_ = ps.getUntrackedParameter<int>("DeadCell_BadChannelStatusMask",
40  ps.getUntrackedParameter<int>("BadChannelStatusMask",
41  (1<<HcalChannelStatus::HcalCellDead))); // identify channel status values to mask
42 
43  minerrorrate_ = ps.getUntrackedParameter<double>("DeadCell_minerrorrate",
44  ps.getUntrackedParameter<double>("minerrorrate",0.25));
45  minevents_ = ps.getUntrackedParameter<int>("DeadCell_minevents",
46  ps.getUntrackedParameter<int>("minevents",1000));
47 
48  excludeHOring2_backup_=ps.getUntrackedParameter<bool>("excludeHOring2_backup",false); // this is used only if excludeHOring2 value from Dead Cell task can't be read
49  Online_ = ps.getUntrackedParameter<bool>("online",false);
50 
52  ProblemCells=0;
53 
54 }
55 
57 {
58  if (debug_>2) std::cout <<"\tHcalDeadCellClient::analyze()"<<std::endl;
60 }
61 
63 {
64 
65 
66  if (debug_>2) std::cout <<"\t\tHcalDeadCellClient::calculateProblems()"<<std::endl;
67  if(!dqmStore_)
68  {
69  if (debug_>2) std::cout <<"DQM STORE DOESN'T EXIST"<<std::endl;
70  return;
71  }
72 
73  MonitorElement* temp_present;
74 
75  temp_present=dqmStore_->get(subdir_+"ExcludeHOring2");
76  int excludeFromHOring2 = 0;
77  if (temp_present)
78  {
79  excludeFromHOring2 = temp_present->getIntValue();
80  if (debug_>2)
81  std::cout <<"Read 'excludeFromHOring2' from HcalMonitorTask output; value = "<<excludeFromHOring2<<std::endl;
82  }
83  else
84  {
85  excludeHOring2_backup_==true ? excludeFromHOring2=1 : excludeFromHOring2=0;
86  if (debug_>2)
87  std::cout <<"Could not read excludeFromHOring2 from HcalMonitorTasks; using value from cfg file: "<<excludeFromHOring2<<std::endl;
88  }
89 
90  // Don't fill histograms if nothing from Hcal is present
91  if (HBpresent_!=1)
92  {
93  temp_present=dqmStore_->get(prefixME_+"HcalInfo/HBpresent");
94  if (temp_present!=0)
95  HBpresent_=temp_present->getIntValue();
96  }
97  if (HEpresent_!=1)
98  {
99  temp_present=dqmStore_->get(prefixME_+"HcalInfo/HEpresent");
100  if (temp_present!=0)
101  HEpresent_=temp_present->getIntValue();
102  }
103  if (HOpresent_!=1)
104  {
105  temp_present=dqmStore_->get(prefixME_+"HcalInfo/HOpresent");
106  if (temp_present!=0)
107  HOpresent_=temp_present->getIntValue();
108  }
109  if (HFpresent_!=1)
110  {
111  temp_present=dqmStore_->get(prefixME_+"HcalInfo/HFpresent");
112  if (temp_present!=0)
113  HFpresent_=temp_present->getIntValue();
114  }
115  // Never saw any data from any Hcal FED; don't count as dead.
116  if (HBpresent_==-1 && HEpresent_==-1 && HOpresent_==-1 && HFpresent_==-1)
117  return;
118  double totalevents=0;
119  int etabins=0, phibins=0, zside=0;
120  double problemvalue=0;
121 
122  // Clear away old problems
123  if (ProblemCells!=0)
124  {
125  ProblemCells->Reset();
126  (ProblemCells->getTH2F())->SetMaximum(1.05);
127  (ProblemCells->getTH2F())->SetMinimum(0.);
128  }
129  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
130  {
131  if (ProblemCellsByDepth->depth[d]!=0)
132  {
133  ProblemCellsByDepth->depth[d]->Reset();
134  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
135  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
136  }
137  }
138 
139  // Get histograms that are used in testing
140  TH2F* DigiPresentByDepth[4];
141  TH2F* RecentMissingDigisByDepth[4];
142  TH2F* RecHitsPresentByDepth[4];
143  TH2F* RecentMissingRecHitsByDepth[4];
144 
145  std::vector<std::string> name = HcalEtaPhiHistNames();
146 
147  MonitorElement* me;
148  for (int i=0;i<4;++i)
149  {
150  // Assume that histograms can't be found
151  DigiPresentByDepth[i]=0;
152  RecentMissingDigisByDepth[i]=0;
153  RecHitsPresentByDepth[i]=0;
154  RecentMissingRecHitsByDepth[i]=0;
155 
156  std::string s=subdir_+"dead_digi_never_present/"+name[i]+"Digi Present At Least Once";
157  me=dqmStore_->get(s.c_str());
158  if (me!=0) DigiPresentByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, DigiPresentByDepth[i], debug_);
159 
160  s=subdir_+"dead_digi_often_missing/"+name[i]+"Dead Cells with No Digis";
161  me=dqmStore_->get(s.c_str());
162  if (me!=0) RecentMissingDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecentMissingDigisByDepth[i], debug_);
163 
164  s=subdir_+"dead_rechit_never_present/"+name[i]+"RecHit Above Threshold At Least Once";
165  me=dqmStore_->get(s.c_str());
166  if (me!=0) RecHitsPresentByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecHitsPresentByDepth[i], debug_);
167 
168  s=subdir_+"dead_rechit_often_missing/"+name[i]+"RecHits Failing Energy Threshold Test";
169  me=dqmStore_->get(s.c_str());
170  if (me!=0)RecentMissingRecHitsByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecentMissingRecHitsByDepth[i], debug_);
171 
172  }
173 
174  // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
175  // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
176 
177  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
178  {
179  if (ProblemCellsByDepth->depth[d]==0) continue;
180 
181  if (DigiPresentByDepth[d]==0) continue;
182  // Get number of entries from DigiPresent histogram
183  // (need to do this for offline DQM combinations of output)
184  totalevents=DigiPresentByDepth[d]->GetBinContent(0);
185  if (totalevents==0 || totalevents<minevents_) continue;
186  enoughevents_=true; // kind of a hack here
187  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
188  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
189  problemvalue=0;
190  for (int eta=0;eta<etabins;++eta)
191  {
192  int ieta=CalcIeta(eta,d+1);
193  if (ieta==-9999) continue;
194 
195  for (int phi=0;phi<phibins;++phi)
196  {
197  problemvalue=0;
198  // Don't count problems in HO ring 2 if the "excludeFromHOring2" bit is in use
199  if (isHO(eta,d+1) && excludeFromHOring2>0 && isSiPM(ieta,phi+1,d+1)==false && abs(ieta)>10)
200  continue;
201 
202  // Never-present histogram is a boolean, with underflow bin = 1 (for each instance)
203  // Offline DQM adds up never-present histograms from multiple outputs
204  // For now, we want offline DQM to show LS-based 'occupancies', rather than simple boolean on/off
205  // May change in the future?
206 
207  // If cell is never-present in all runs, then problemvalue = event
208  if (DigiPresentByDepth[d]!=0 && DigiPresentByDepth[d]->GetBinContent(eta+1,phi+1)==0)
209  problemvalue=totalevents;
210 
211  // Rec Hit presence test
212  else if (RecHitsPresentByDepth[d]!=0)
213  {
214  if (RecHitsPresentByDepth[d]->GetBinContent(eta+1,phi+1)==0)
215  problemvalue=totalevents;
216  else if (RecHitsPresentByDepth[d]->GetBinContent(eta+1,phi+1)>1)
217  RecHitsPresentByDepth[d]->SetBinContent(eta+1,phi+1,1);
218  }
219  else
220  {
221  if (RecentMissingDigisByDepth[d]!=0)
222  problemvalue+=RecentMissingDigisByDepth[d]->GetBinContent(eta+1,phi+1);
223  if (RecentMissingRecHitsByDepth[d]!=0)
224  problemvalue+=RecentMissingRecHitsByDepth[d]->GetBinContent(eta+1,phi+1);
225  }
226 
227  if (problemvalue==0) continue;
228 
229  problemvalue/=totalevents; // problem value is a rate; should be between 0 and 1
230  problemvalue = std::min(1.,problemvalue);
231 
232  zside=0;
233  if (isHF(eta,d+1)) // shift ieta by 1 for HF
234  ieta<0 ? zside = -1 : zside = 1;
235 
236  // For problem cells that exceed our allowed rate,
237  // set the values to -1 if the cells are already marked in the status database
238  if (problemvalue>minerrorrate_)
239  {
240  HcalSubdetector subdet=HcalEmpty;
241  if (isHB(eta,d+1))subdet=HcalBarrel;
242  else if (isHE(eta,d+1)) subdet=HcalEndcap;
243  else if (isHF(eta,d+1)) subdet=HcalForward;
244  else if (isHO(eta,d+1)) subdet=HcalOuter;
245  HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
246  if (badstatusmap.find(hcalid)!=badstatusmap.end())
247  problemvalue=999;
248  }
249  ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
250  if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
251  } // loop on phi
252  } // loop on eta
253  } // loop on depth
254 
255  if (ProblemCells==0)
256  {
257  if (debug_>0) std::cout <<"<HcalDeadCellClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
258  return;
259  }
260 
261  // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
262  etabins=(ProblemCells->getTH2F())->GetNbinsX();
263  phibins=(ProblemCells->getTH2F())->GetNbinsY();
264  for (int eta=0;eta<etabins;++eta)
265  {
266  for (int phi=0;phi<phibins;++phi)
267  {
270  }
271  }
272 
275  return;
276 }
277 
279 {
281  if (debug_>0)
282  {
283  std::cout <<"<HcalDeadCellClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
285  }
286 }
288 
290 {
291  enoughevents_=false;
292  HBpresent_=-1;
293  HEpresent_=-1;
294  HOpresent_=-1;
295  HFpresent_=-1;
296  if (!dqmStore_)
297  {
298  if (debug_>0) std::cout <<"<HcalDeadCellClient::beginRun> dqmStore does not exist!"<<std::endl;
299  return;
300  }
302  problemnames_.clear();
303  ProblemCells=dqmStore_->book2D(" ProblemDeadCells",
304  " Problem Dead Cell Rate for all HCAL;ieta;iphi",
305  85,-42.5,42.5,
306  72,0.5,72.5);
307  problemnames_.push_back(ProblemCells->getName());
308  if (debug_>1)
309  std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
310  dqmStore_->setCurrentFolder(subdir_+"problem_deadcells");
312  ProblemCellsByDepth->setup(dqmStore_," Problem Dead Cell Rate");
313  for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
314  problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
315 
316  nevts_=0;
317 }
318 
320 
323 
325 {
326  if (!ProblemCells)
327  {
328  if (debug_>1) std::cout <<"<HcalDeadCellClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
329  return false;
330  }
331  int problemcount=0;
332  int ieta=-9999;
333 
334  for (int depth=0;depth<4; ++depth)
335  {
336  int etabins = (ProblemCells->getTH2F())->GetNbinsX();
337  int phibins = (ProblemCells->getTH2F())->GetNbinsY();
338  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
339  {
340  for (int hist_phi=0; hist_phi<phibins;++hist_phi)
341  {
342  ieta=CalcIeta(hist_eta,depth+1);
343  if (ieta==-9999) continue;
344  if (ProblemCellsByDepth->depth[depth]==0)
345  continue;
346  if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
347  ++problemcount;
348  } // for (int hist_phi=1;...)
349  } // for (int hist_eta=1;...)
350  } // for (int depth=0;...)
351 
352  if (problemcount>0) return true;
353  return false;
354 }
355 
356 bool HcalDeadCellClient::hasWarnings_Temp(void){return false;}
357 bool HcalDeadCellClient::hasOther_Temp(void){return false;}
358 bool HcalDeadCellClient::test_enabled(void){return true;}
359 
360 
361 
362 void HcalDeadCellClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
363 {
364  // This gets called by HcalMonitorClient
365 
366  if (enoughevents_==false) return; // not enough events to make judgment; don't create new status file
367 
368  float binval;
369  int ieta=0;
370  int iphi=0;
371  int etabins=0;
372  int phibins=0;
373 
374  int subdet=0;
375  if (debug_>1)
376  {
377  std::cout <<"<HcalDeadCellClient> Summary of Dead Cells in Run: "<<std::endl;
378  std::cout <<"(Error rate must be >= "<<minerrorrate_*100.<<"% )"<<std::endl;
379  }
380  for (int d=0;d<4;++d)
381  {
382  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
383  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
384  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
385  {
386  ieta=CalcIeta(hist_eta,d+1);
387  if (ieta==-9999) continue;
388  for (int hist_phi=0;hist_phi<phibins;++hist_phi)
389  {
390  iphi=hist_phi+1;
391 
392  // ProblemCells have already been normalized
393  binval=ProblemCellsByDepth->depth[d]->getBinContent(hist_eta+1,hist_phi+1);
394 
395  // Set subdetector labels for output
396  if (d<2)
397  {
398  if (isHB(hist_eta,d+1))
399  subdet=HcalBarrel;
400  else if (isHE(hist_eta,d+1))
401  subdet=HcalEndcap;
402  else if (isHF(hist_eta,d+1))
403  subdet=HcalForward;
404  }
405  else if (d==2)
406  subdet=HcalEndcap;
407  else if (d==3)
408  subdet=HcalOuter;
409  // Set correct depth label
410 
411  HcalDetId myid((HcalSubdetector)(subdet), ieta, iphi, d+1);
412  // Need this to keep from flagging non-existent HE/HF cells
413  if (!validDetId((HcalSubdetector)(subdet), ieta, iphi, d+1))
414  continue;
415 
416  int deadcell=0;
417  if (binval>minerrorrate_)
418  deadcell=1;
419  if (deadcell==1 && debug_>0)
420  std::cout <<"Dead Cell : subdetector = "<<subdet<<" (eta,phi,depth) = ("<<ieta<<", "<<iphi<<", "<<d+1<<"): "<<binval*100.<<"%"<<std::endl;
421 
422  // DetID not found in quality list; add it.
423  if (myqual.find(myid)==myqual.end())
424  myqual[myid]=(deadcell<<HcalChannelStatus::HcalCellDead); // deadcell shifted to bit 6
425  else
426  {
427  int mask=(1<<HcalChannelStatus::HcalCellDead);
428  // dead cell found; 'or' the dead cell mask with existing ID
429  if (deadcell==1)
430  myqual[myid] |=mask;
431  // cell is not found, 'and' the inverse of the mask with the existing ID.
432  // Does this work correctly? I think so, but need to verify.
433  // Also, do we want to allow the client to turn off dead cell masks, or only add them?
434  else
435  myqual[myid] &=~mask;
436  }
437  } // for (int hist_phi=1;hist_phi<=phibins;++hist_phi)
438  } // for (int hist_eta=1;hist_eta<=etabins;++hist_eta)
439  } // for (int d=0;d<4;++d)
440 
441 
442 } //void HcalDeadCellClient::updateChannelStatus
443 
445 {}
bool isHO(int etabin, int depth)
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 * ProblemCells
std::string name()
void setBinContent(int binx, double content)
set content of bin (1-D)
std::vector< std::string > HcalEtaPhiHistNames()
void setup(DQMStore *&m_dbe, std::string Name, std::string Units="")
bool isHE(int etabin, int depth)
T eta() const
void Fill(long long x)
bool isSiPM(int ieta, int iphi, int depth)
std::vector< MonitorElement * > depth
int CalcIeta(int subdet, int eta, int depth)
std::vector< std::string > problemnames_
EtaPhiHists * ProblemCellsByDepth
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1624
bool isHB(int etabin, int depth)
bool isHF(int etabin, int depth)
~HcalDeadCellClient()
Destructor.
int64_t getIntValue(void) const
std::string subdir_
std::map< HcalDetId, unsigned int > badstatusmap
void FillUnphysicalHEHFBins(std::vector< TH2F > &hh)
double getBinContent(int binx) const
get content of bin (1-D)
std::string prefixME_
tuple cout
Definition: gather_cfg.py:121
void showDirStructure(void) const
Definition: DQMStore.cc:2962
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1001
void Reset(void)
reset ME (ie. contents, errors, etc)
void updateChannelStatus(std::map< HcalDetId, unsigned int > &myqual)
DQMStore * dqmStore_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:585
HcalDeadCellClient()
Constructors.
bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)
Definition: DDAxes.h:10