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