CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalHotCellClient.cc
Go to the documentation of this file.
4 
8 
9 #include <iostream>
10 
11 /*
12  * \file HcalHotCellClient.cc
13  *
14  * $Date: 2010/11/17 19:17:42 $
15  * $Revision: 1.76 $
16  * \author J. Temple
17  * \brief Hot 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>("HotCellFolder","HotCellMonitor_Hcal/"); // HotCellMonitor_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>("HotCell_validHtmlOutput",true);
39  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
40  badChannelStatusMask_ = ps.getUntrackedParameter<int>("HotCell_BadChannelStatusMask",
41  ps.getUntrackedParameter<int>("BadChannelStatusMask",
42  (1<<HcalChannelStatus::HcalCellHot))); // identify channel status values to mask
43 
44  minerrorrate_ = ps.getUntrackedParameter<double>("HotCell_minerrorrate",
45  ps.getUntrackedParameter<double>("minerrorrate",0.25));
46  minevents_ = ps.getUntrackedParameter<int>("HotCell_minevents",
47  ps.getUntrackedParameter<int>("minevents",100));
48  Online_ = ps.getUntrackedParameter<bool>("online",false);
49 
51  ProblemCells=0;
52 }
53 
55 {
56  if (debug_>2) std::cout <<"\tHcalHotCellClient::analyze()"<<std::endl;
58 }
59 
61 {
62  if (debug_>2) std::cout <<"\t\tHcalHotCellClient::calculateProblems()"<<std::endl;
63  if(!dqmStore_) return;
64  double totalevents=0;
65  int etabins=0, phibins=0, zside=0;
66  double problemvalue=0;
67 
68  // Clear away old problems
69  if (ProblemCells!=0)
70  {
72  (ProblemCells->getTH2F())->SetMaximum(1.05);
73  (ProblemCells->getTH2F())->SetMinimum(0.);
74  }
75  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
76  {
77  if (ProblemCellsByDepth->depth[d]!=0)
78  {
79  ProblemCellsByDepth->depth[d]->Reset();
80  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
81  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
82  }
83  }
84 
85  // Get histograms that are used in testing
86  TH2F* HotAboveThresholdByDepth[4];
87  TH2F* HotAlwaysAboveThresholdByDepth[4];
88  TH2F* HotAboveETThresholdByDepth[4];
89  TH2F* HotAlwaysAboveETThresholdByDepth[4];
90  TH2F* HotNeighborsByDepth[4];
91 
92  std::vector<std::string> name = HcalEtaPhiHistNames();
93 
94  bool neighbortest=false;
95 
96  MonitorElement* me;
97  for (int i=0;i<4;++i)
98  {
99  // Assume histograms aren't found by default
100  HotAboveThresholdByDepth[i]=0;
101  HotAlwaysAboveThresholdByDepth[i]=0;
102  HotAboveETThresholdByDepth[i]=0;
103  HotAlwaysAboveETThresholdByDepth[i]=0;
104  HotNeighborsByDepth[i]=0;
105 
106  std::string s=subdir_+"hot_rechit_above_threshold/"+name[i]+"Hot Cells Above ET Threshold";
107  me=dqmStore_->get(s.c_str());
108  if (me!=0)HotAboveETThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAboveETThresholdByDepth[i], debug_);
109 
110  s=subdir_+"hot_rechit_always_above_threshold/"+name[i]+"Hot Cells Persistently Above ET Threshold";
111  me=dqmStore_->get(s.c_str());
112  if (me!=0)HotAlwaysAboveETThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAlwaysAboveETThresholdByDepth[i], debug_);
113 
114  s=subdir_+"hot_rechit_above_threshold/"+name[i]+"Hot Cells Above Energy Threshold";
115  me=dqmStore_->get(s.c_str());
116  if (me!=0)HotAboveThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAboveThresholdByDepth[i], debug_);
117 
118  s=subdir_+"hot_rechit_always_above_threshold/"+name[i]+"Hot Cells Persistently Above Energy Threshold";
119  me=dqmStore_->get(s.c_str());
120  if (me!=0)HotAlwaysAboveThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAlwaysAboveThresholdByDepth[i], debug_);
121 
122  s=subdir_+"hot_neighbortest/"+name[i]+"Hot Cells Failing Neighbor Test";
123  me=dqmStore_->get(s.c_str());
124  if (me!=0)HotNeighborsByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotNeighborsByDepth[i], debug_);
125  s=subdir_+"hot_neighbortest/NeighborTestEnabled";
126  me=dqmStore_->get(s.c_str());
127  if (me!=0 && me->getIntValue()==1)
128  neighbortest=true;
129  }
130 
131 
132  // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
133  // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
134 
135  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
136  {
137  if (ProblemCellsByDepth->depth[d]==0) continue;
138 
139  if (HotAboveETThresholdByDepth[d]) totalevents = std::max(totalevents, HotAboveETThresholdByDepth[d]->GetBinContent(0));
140  else if (HotAlwaysAboveETThresholdByDepth[d]) totalevents = std::max(totalevents, HotAlwaysAboveETThresholdByDepth[d]->GetBinContent(0));
141  else if (HotAboveThresholdByDepth[d]) totalevents = std::max(totalevents, HotAboveThresholdByDepth[d]->GetBinContent(0));
142  else if (HotAlwaysAboveThresholdByDepth[d]) totalevents = std::max(totalevents, HotAlwaysAboveThresholdByDepth[d]->GetBinContent(0));
143  else if (neighbortest==true && HotNeighborsByDepth[d]) totalevents = std::max(totalevents, HotNeighborsByDepth[d]->GetBinContent(0));
144  else if (debug_>0) std::cout <<"<HcalHotCellClient::calculateProblems> No evaluation histograms found; no valid hot tests enabled?" << std::endl;
145  if (totalevents==0 || totalevents<minevents_) continue;
146  enoughevents_=true; // kind of a hack here
147  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
148  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
149  problemvalue=0;
150  for (int eta=0;eta<etabins;++eta)
151  {
152  int ieta=CalcIeta(eta,d+1);
153  if (ieta==-9999) continue;
154  for (int phi=0;phi<phibins;++phi)
155  {
156  problemvalue=0; // problem fraction sums over all three tests
157  // If cell is never-present in all runs, then problemvalue = event
158  if (HotAboveETThresholdByDepth[d]!=0)
159  problemvalue+=HotAboveETThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
160  if (HotAboveThresholdByDepth[d]!=0)
161  problemvalue+=HotAboveThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
162  if (HotAlwaysAboveThresholdByDepth[d]!=0)
163  problemvalue+=HotAlwaysAboveThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
164  if (neighbortest==true && HotNeighborsByDepth[d]!=0)
165  problemvalue+=HotNeighborsByDepth[d]->GetBinContent(eta+1,phi+1);
166  if (problemvalue==0) continue;
167  problemvalue/=totalevents; // problem value is a rate; should be between 0 and 1
168  problemvalue = std::min(1.,problemvalue);
169 
170  zside=0;
171  if (isHF(eta,d+1)) // shift ieta by 1 for HF
172  ieta<0 ? zside = -1 : zside = 1;
173 
174  // For problem cells that exceed our allowed rate,
175  // set the values to -1 if the cells are already marked in the status database
176  if (problemvalue>minerrorrate_)
177  {
178  HcalSubdetector subdet=HcalEmpty;
179  if (isHB(eta,d+1))subdet=HcalBarrel;
180  else if (isHE(eta,d+1)) subdet=HcalEndcap;
181  else if (isHF(eta,d+1)) subdet=HcalForward;
182  else if (isHO(eta,d+1)) subdet=HcalOuter;
183  HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
184  if (badstatusmap.find(hcalid)!=badstatusmap.end())
185  problemvalue=999;
186  }
187  ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
188  if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
189  } // loop on phi
190  } // loop on eta
191  } // loop on depth
192 
193  if (ProblemCells==0)
194  {
195  if (debug_>0) std::cout <<"<HcalHotCellClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
196  return;
197  }
198 
199  // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
200  etabins=(ProblemCells->getTH2F())->GetNbinsX();
201  phibins=(ProblemCells->getTH2F())->GetNbinsY();
202  for (int eta=0;eta<etabins;++eta)
203  {
204  for (int phi=0;phi<phibins;++phi)
205  {
208  }
209  }
210 
213  return;
214 }
215 
216 
218 {
220  if (debug_>0)
221  {
222  std::cout <<"<HcalHotCellClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
224  }
225 }
226 
228 
230 {
231  enoughevents_=false;
232  if (!dqmStore_)
233  {
234  if (debug_>0) std::cout <<"<HcalHotCellClient::beginRun> dqmStore does not exist!"<<std::endl;
235  return;
236  }
238  problemnames_.clear();
239  ProblemCells=dqmStore_->book2D(" ProblemHotCells",
240  " Problem Hot Cell Rate for all HCAL;ieta;iphi",
241  85,-42.5,42.5,
242  72,0.5,72.5);
243  problemnames_.push_back(ProblemCells->getName());
244  if (debug_>1)
245  std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
246  dqmStore_->setCurrentFolder(subdir_+"problem_hotcells");
248  ProblemCellsByDepth->setup(dqmStore_," Problem Hot Cell Rate");
249  for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
250  problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
251 
252  nevts_=0;
253 }
254 
256 
259 
261 {
262  if (!ProblemCells)
263  {
264  if (debug_>1) std::cout <<"<HcalHotCellClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
265  return false;
266  }
267  int problemcount=0;
268  int ieta=-9999;
269 
270  for (int depth=0;depth<4; ++depth)
271  {
272  int etabins = (ProblemCells->getTH2F())->GetNbinsX();
273  int phibins = (ProblemCells->getTH2F())->GetNbinsY();
274  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
275  {
276  for (int hist_phi=0; hist_phi<phibins;++hist_phi)
277  {
278  ieta=CalcIeta(hist_eta,depth+1);
279  if (ieta==-9999) continue;
280  if (ProblemCellsByDepth->depth[depth]==0)
281  continue;
282  if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
283  ++problemcount;
284  } // for (int hist_phi=1;...)
285  } // for (int hist_eta=1;...)
286  } // for (int depth=0;...)
287 
288  if (problemcount>0) return true;
289  return false;
290 }
291 
292 bool HcalHotCellClient::hasWarnings_Temp(void){return false;}
293 bool HcalHotCellClient::hasOther_Temp(void){return false;}
294 bool HcalHotCellClient::test_enabled(void){return true;}
295 
296 
297 void HcalHotCellClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
298 {
299  // This gets called by HcalMonitorClient
300 
301  if (nevts_<minevents_) return; // not enough events to make judgment; don't create new status file
302 
303  float binval;
304  int ieta=0;
305  int iphi=0;
306  int etabins=0;
307  int phibins=0;
308 
309  int subdet=0;
310  if (debug_>1)
311  {
312  std::cout <<"<HcalHotCellClient> Summary of Hot Cells in Run: "<<std::endl;
313  std::cout <<"(Error rate must be >= "<<minerrorrate_*100.<<"% )"<<std::endl;
314  }
315  for (int d=0;d<4;++d)
316  {
317  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
318  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
319  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
320  {
321  ieta=CalcIeta(hist_eta,d+1);
322  if (ieta==-9999) continue;
323  for (int hist_phi=0;hist_phi<phibins;++hist_phi)
324  {
325  iphi=hist_phi+1;
326 
327  // ProblemCells have already been normalized
328  binval=ProblemCellsByDepth->depth[d]->getBinContent(hist_eta+1,hist_phi+1);
329 
330  // Set subdetector labels for output
331  if (d<2)
332  {
333  if (isHB(hist_eta,d+1))
334  subdet=HcalBarrel;
335  else if (isHE(hist_eta,d+1))
336  subdet=HcalEndcap;
337  else if (isHF(hist_eta,d+1))
338  subdet=HcalForward;
339  }
340  else if (d==2)
341  subdet=HcalEndcap;
342  else if (d==3)
343  subdet=HcalOuter;
344  // Set correct depth label
345 
346  HcalDetId myid((HcalSubdetector)(subdet), ieta, iphi, d+1);
347  // Need this to keep from flagging non-existent HE/HF cells
348  if (!validDetId((HcalSubdetector)(subdet), ieta, iphi, d+1))
349  continue;
350 
351  int hotcell=0;
352  if (binval>minerrorrate_)
353  hotcell=1;
354  if (hotcell==1 && debug_>0)
355  std::cout <<"Hot Cell : subdetector = "<<subdet<<" (eta,phi,depth) = ("<<ieta<<", "<<iphi<<", "<<d+1<<"): "<<binval*100.<<"%"<<std::endl;
356 
357  // DetID not found in quality list; add it. (This shouldn't happen!)
358  if (myqual.find(myid)==myqual.end())
359  {
360  myqual[myid]=(hotcell<<HcalChannelStatus::HcalCellHot); //
361  }
362  else
363  {
364  int mask=(1<<HcalChannelStatus::HcalCellHot);
365  // hot cell found; 'or' the hot cell mask with existing ID
366  if (hotcell==1)
367  myqual[myid] |=mask;
368  // cell is not found, 'and' the inverse of the mask with the existing ID.
369  // Does this work correctly? I think so, but need to verify.
370  // Also, do we want to allow the client to turn off hot cell masks, or only add them?
371  else
372  myqual[myid] &=~mask;
373  }
374  } // for (int hist_phi=1;hist_phi<=phibins;++hist_phi)
375  } // for (int hist_eta=1;hist_eta<=etabins;++hist_eta)
376  } // for (int d=0;d<4;++d)
377 
378 
379 } //void HcalHotCellClient::updateChannelStatus
380 
381 
bool isHO(int etabin, int depth)
void calculateProblems(void)
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)
HcalHotCellClient()
Constructors.
std::vector< MonitorElement * > depth
int CalcIeta(int subdet, int eta, int depth)
const T & max(const T &a, const T &b)
std::vector< std::string > problemnames_
void updateChannelStatus(std::map< HcalDetId, unsigned int > &myqual)
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:1265
bool isHB(int etabin, int depth)
bool isHF(int etabin, int depth)
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:41
string s
Definition: asciidump.py:422
void showDirStructure(void) const
Definition: DQMStore.cc:2554
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:642
void Reset(void)
reset ME (ie. contents, errors, etc)
DQMStore * dqmStore_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)
Definition: DDAxes.h:10