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