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  doProblemCellSetup_ = true;
55 
56 }
57 
59 {
60  if (debug_>2) std::cout <<"\tHcalDeadCellClient::analyze()"<<std::endl;
62  calculateProblems(ib,ig);
63 }
64 
66 {
67 
68 
69  if (debug_>2) std::cout <<"\t\tHcalDeadCellClient::calculateProblems()"<<std::endl;
70 
71  MonitorElement* temp_present;
72 
73  temp_present=ig.get(subdir_+"ExcludeHOring2");
74  int excludeFromHOring2 = 0;
75  if (temp_present)
76  {
77  excludeFromHOring2 = temp_present->getIntValue();
78  if (debug_>2)
79  std::cout <<"Read 'excludeFromHOring2' from HcalMonitorTask output; value = "<<excludeFromHOring2<<std::endl;
80  }
81  else
82  {
83  excludeHOring2_backup_==true ? excludeFromHOring2=1 : excludeFromHOring2=0;
84  if (debug_>2)
85  std::cout <<"Could not read excludeFromHOring2 from HcalMonitorTasks; using value from cfg file: "<<excludeFromHOring2<<std::endl;
86  }
87 
88  // Don't fill histograms if nothing from Hcal is present
89  if (HBpresent_!=1)
90  {
91  temp_present=ig.get(prefixME_+"HcalInfo/HBpresent");
92  if (temp_present!=0)
93  HBpresent_=temp_present->getIntValue();
94  }
95  if (HEpresent_!=1)
96  {
97  temp_present=ig.get(prefixME_+"HcalInfo/HEpresent");
98  if (temp_present!=0)
99  HEpresent_=temp_present->getIntValue();
100  }
101  if (HOpresent_!=1)
102  {
103  temp_present=ig.get(prefixME_+"HcalInfo/HOpresent");
104  if (temp_present!=0)
105  HOpresent_=temp_present->getIntValue();
106  }
107  if (HFpresent_!=1)
108  {
109  temp_present=ig.get(prefixME_+"HcalInfo/HFpresent");
110  if (temp_present!=0)
111  HFpresent_=temp_present->getIntValue();
112  }
113  // Never saw any data from any Hcal FED; don't count as dead.
114  if (HBpresent_==-1 && HEpresent_==-1 && HOpresent_==-1 && HFpresent_==-1)
115  return;
116  double totalevents=0;
117  int etabins=0, phibins=0, zside=0;
118  double problemvalue=0;
119 
120  // Clear away old problems
121  if (ProblemCells!=0)
122  {
123  ProblemCells->Reset();
124  (ProblemCells->getTH2F())->SetMaximum(1.05);
125  (ProblemCells->getTH2F())->SetMinimum(0.);
126  }
127  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
128  {
129  if (ProblemCellsByDepth->depth[d]!=0)
130  {
131  ProblemCellsByDepth->depth[d]->Reset();
132  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
133  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
134  }
135  }
136 
137  // Get histograms that are used in testing
138  TH2F* DigiPresentByDepth[4];
139  TH2F* RecentMissingDigisByDepth[4];
140  TH2F* RecHitsPresentByDepth[4];
141  TH2F* RecentMissingRecHitsByDepth[4];
142 
143  std::vector<std::string> name = HcalEtaPhiHistNames();
144 
146  for (int i=0;i<4;++i)
147  {
148  // Assume that histograms can't be found
149  DigiPresentByDepth[i]=0;
150  RecentMissingDigisByDepth[i]=0;
151  RecHitsPresentByDepth[i]=0;
152  RecentMissingRecHitsByDepth[i]=0;
153 
154  std::string s=subdir_+"dead_digi_never_present/"+name[i]+"Digi Present At Least Once";
155  me=ig.get(s.c_str());
156  if (me!=0) DigiPresentByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, DigiPresentByDepth[i], debug_);
157 
158  s=subdir_+"dead_digi_often_missing/"+name[i]+"Dead Cells with No Digis";
159  me=ig.get(s.c_str());
160  if (me!=0) RecentMissingDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecentMissingDigisByDepth[i], debug_);
161 
162  s=subdir_+"dead_rechit_never_present/"+name[i]+"RecHit Above Threshold At Least Once";
163  me=ig.get(s.c_str());
164  if (me!=0) RecHitsPresentByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecHitsPresentByDepth[i], debug_);
165 
166  s=subdir_+"dead_rechit_often_missing/"+name[i]+"RecHits Failing Energy Threshold Test";
167  me=ig.get(s.c_str());
168  if (me!=0)RecentMissingRecHitsByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecentMissingRecHitsByDepth[i], debug_);
169 
170  }
171 
172  // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
173  // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
174 
175  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
176  {
177  if (ProblemCellsByDepth->depth[d]==0) continue;
178 
179  if (DigiPresentByDepth[d]==0) continue;
180  // Get number of entries from DigiPresent histogram
181  // (need to do this for offline DQM combinations of output)
182  totalevents=DigiPresentByDepth[d]->GetBinContent(0);
183  if (totalevents==0 || totalevents<minevents_) continue;
184  enoughevents_=true; // kind of a hack here
185  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
186  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
187  problemvalue=0;
188  for (int eta=0;eta<etabins;++eta)
189  {
190  int ieta=CalcIeta(eta,d+1);
191  if (ieta==-9999) continue;
192 
193  for (int phi=0;phi<phibins;++phi)
194  {
195  problemvalue=0;
196  // Don't count problems in HO ring 2 if the "excludeFromHOring2" bit is in use
197  if (isHO(eta,d+1) && excludeFromHOring2>0 && isSiPM(ieta,phi+1,d+1)==false && abs(ieta)>10)
198  continue;
199 
200  // Never-present histogram is a boolean, with underflow bin = 1 (for each instance)
201  // Offline DQM adds up never-present histograms from multiple outputs
202  // For now, we want offline DQM to show LS-based 'occupancies', rather than simple boolean on/off
203  // May change in the future?
204 
205  // If cell is never-present in all runs, then problemvalue = event
206  if (DigiPresentByDepth[d]!=0 && DigiPresentByDepth[d]->GetBinContent(eta+1,phi+1)==0)
207  problemvalue=totalevents;
208 
209  // Rec Hit presence test
210  else if (RecHitsPresentByDepth[d]!=0)
211  {
212  if (RecHitsPresentByDepth[d]->GetBinContent(eta+1,phi+1)==0)
213  problemvalue=totalevents;
214  else if (RecHitsPresentByDepth[d]->GetBinContent(eta+1,phi+1)>1)
215  RecHitsPresentByDepth[d]->SetBinContent(eta+1,phi+1,1);
216  }
217  else
218  {
219  if (RecentMissingDigisByDepth[d]!=0)
220  problemvalue+=RecentMissingDigisByDepth[d]->GetBinContent(eta+1,phi+1);
221  if (RecentMissingRecHitsByDepth[d]!=0)
222  problemvalue+=RecentMissingRecHitsByDepth[d]->GetBinContent(eta+1,phi+1);
223  }
224 
225  if (problemvalue==0) continue;
226 
227  problemvalue/=totalevents; // problem value is a rate; should be between 0 and 1
228  problemvalue = std::min(1.,problemvalue);
229 
230  zside=0;
231  if (isHF(eta,d+1)) // shift ieta by 1 for HF
232  ieta<0 ? zside = -1 : zside = 1;
233 
234  // For problem cells that exceed our allowed rate,
235  // set the values to -1 if the cells are already marked in the status database
236  if (problemvalue>minerrorrate_)
237  {
238  HcalSubdetector subdet=HcalEmpty;
239  if (isHB(eta,d+1))subdet=HcalBarrel;
240  else if (isHE(eta,d+1)) subdet=HcalEndcap;
241  else if (isHF(eta,d+1)) subdet=HcalForward;
242  else if (isHO(eta,d+1)) subdet=HcalOuter;
243  HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
244  if (badstatusmap.find(hcalid)!=badstatusmap.end())
245  problemvalue=999;
246  }
247  ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
248  if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
249  } // loop on phi
250  } // loop on eta
251  } // loop on depth
252 
253  if (ProblemCells==0)
254  {
255  if (debug_>0) std::cout <<"<HcalDeadCellClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
256  return;
257  }
258 
259  // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
260  etabins=(ProblemCells->getTH2F())->GetNbinsX();
261  phibins=(ProblemCells->getTH2F())->GetNbinsY();
262  for (int eta=0;eta<etabins;++eta)
263  {
264  for (int phi=0;phi<phibins;++phi)
265  {
268  }
269  }
270 
273  return;
274 }
275 
277 
279 {
280 
282  problemnames_.clear();
283  ProblemCells=ib.book2D(" ProblemDeadCells",
284  " Problem Dead Cell Rate for all HCAL;ieta;iphi",
285  85,-42.5,42.5,
286  72,0.5,72.5);
287  problemnames_.push_back(ProblemCells->getName());
288  if (debug_>1)
289  std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
290  ib.setCurrentFolder(subdir_+"problem_deadcells");
292  ProblemCellsByDepth->setup(ib," Problem Dead Cell Rate");
293  for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
294  problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
295 
296  doProblemCellSetup_ = false;
297 
298 }
299 
301 {
302  enoughevents_=false;
303  HBpresent_=-1;
304  HEpresent_=-1;
305  HOpresent_=-1;
306  HFpresent_=-1;
307 
308  nevts_=0;
309 }
310 
311 //void HcalDeadCellClient::endRun(void){analyze();}
312 
315 
317 {
318  if (!ProblemCells)
319  {
320  if (debug_>1) std::cout <<"<HcalDeadCellClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
321  return false;
322  }
323  int problemcount=0;
324  int ieta=-9999;
325 
326  for (int depth=0;depth<4; ++depth)
327  {
328  int etabins = (ProblemCells->getTH2F())->GetNbinsX();
329  int phibins = (ProblemCells->getTH2F())->GetNbinsY();
330  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
331  {
332  for (int hist_phi=0; hist_phi<phibins;++hist_phi)
333  {
334  ieta=CalcIeta(hist_eta,depth+1);
335  if (ieta==-9999) continue;
337  continue;
338  if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
339  ++problemcount;
340  } // for (int hist_phi=1;...)
341  } // for (int hist_eta=1;...)
342  } // for (int depth=0;...)
343 
344  if (problemcount>0) return true;
345  return false;
346 }
347 
348 bool HcalDeadCellClient::hasWarnings_Temp(void){return false;}
349 bool HcalDeadCellClient::hasOther_Temp(void){return false;}
350 bool HcalDeadCellClient::test_enabled(void){return true;}
351 
352 
353 
354 void HcalDeadCellClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
355 {
356  // This gets called by HcalMonitorClient
357 
358  if (enoughevents_==false) return; // not enough events to make judgment; don't create new status file
359 
360  float binval;
361  int ieta=0;
362  int iphi=0;
363  int etabins=0;
364  int phibins=0;
365 
366  int subdet=0;
367  if (debug_>1)
368  {
369  std::cout <<"<HcalDeadCellClient> Summary of Dead Cells in Run: "<<std::endl;
370  std::cout <<"(Error rate must be >= "<<minerrorrate_*100.<<"% )"<<std::endl;
371  }
372  for (int d=0;d<4;++d)
373  {
374  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
375  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
376  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
377  {
378  ieta=CalcIeta(hist_eta,d+1);
379  if (ieta==-9999) continue;
380  for (int hist_phi=0;hist_phi<phibins;++hist_phi)
381  {
382  iphi=hist_phi+1;
383 
384  // ProblemCells have already been normalized
385  binval=ProblemCellsByDepth->depth[d]->getBinContent(hist_eta+1,hist_phi+1);
386 
387  // Set subdetector labels for output
388  if (d<2)
389  {
390  if (isHB(hist_eta,d+1))
391  subdet=HcalBarrel;
392  else if (isHE(hist_eta,d+1))
393  subdet=HcalEndcap;
394  else if (isHF(hist_eta,d+1))
395  subdet=HcalForward;
396  }
397  else if (d==2)
398  subdet=HcalEndcap;
399  else if (d==3)
400  subdet=HcalOuter;
401  // Set correct depth label
402 
403  HcalDetId myid((HcalSubdetector)(subdet), ieta, iphi, d+1);
404  // Need this to keep from flagging non-existent HE/HF cells
405  if (!(topo_->validDetId((HcalSubdetector)(subdet), ieta, iphi, d+1))) continue;
406 
407  int deadcell=0;
408  if (binval>minerrorrate_)
409  deadcell=1;
410  if (deadcell==1 && debug_>0)
411  std::cout <<"Dead Cell : subdetector = "<<subdet<<" (eta,phi,depth) = ("<<ieta<<", "<<iphi<<", "<<d+1<<"): "<<binval*100.<<"%"<<std::endl;
412 
413  // DetID not found in quality list; add it.
414  if (myqual.find(myid)==myqual.end())
415  myqual[myid]=(deadcell<<HcalChannelStatus::HcalCellDead); // deadcell shifted to bit 6
416  else
417  {
418  int mask=(1<<HcalChannelStatus::HcalCellDead);
419  // dead cell found; 'or' the dead cell mask with existing ID
420  if (deadcell==1)
421  myqual[myid] |=mask;
422  // cell is not found, 'and' the inverse of the mask with the existing ID.
423  // Does this work correctly? I think so, but need to verify.
424  // Also, do we want to allow the client to turn off dead cell masks, or only add them?
425  else
426  myqual[myid] &=~mask;
427  }
428  } // for (int hist_phi=1;hist_phi<=phibins;++hist_phi)
429  } // for (int hist_eta=1;hist_eta<=etabins;++hist_eta)
430  } // for (int d=0;d<4;++d)
431 
432 
433 } //void HcalDeadCellClient::updateChannelStatus
434 
436 {
438 }
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
void setupProblemCells(DQMStore::IBooker &, DQMStore::IGetter &)
MonitorElement * ProblemCells
std::string name()
void setBinContent(int binx, double content)
set content of bin (1-D)
int ib
Definition: cuy.py:660
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:304
bool validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const
std::vector< std::string > HcalEtaPhiHistNames()
const HcalTopology * topo_
int zside(DetId const &)
bool isHE(int etabin, int depth)
void Fill(long long x)
tuple d
Definition: ztail.py:151
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
void setup(DQMStore::IBooker &m_dbe, std::string Name, std::string Units="")
T min(T a, T b)
Definition: MathUtil.h:58
bool isHB(int etabin, int depth)
virtual void calculateProblems(void)
bool isHF(int etabin, int depth)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
~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:145
void analyze(DQMStore::IBooker &, DQMStore::IGetter &)
TH2F * getTH2F(void) const
void Reset(void)
reset ME (ie. contents, errors, etc)
void updateChannelStatus(std::map< HcalDetId, unsigned int > &myqual)
HcalDeadCellClient()
Constructors.