CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDetDiagNoiseMonitorClient.cc
Go to the documentation of this file.
4 
8 
9 #include <iostream>
10 
11 /*
12  * \file HcalDetDiagNoiseMonitorClient.cc
13  *
14  * \author J. Temple
15  * \brief Hcal DetDiagNoiseMonitor 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>("DetDiagNoiseMonitorFolder","DetDiagNoiseMonitor_Hcal/"); // DetDiagNoiseMonitor_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>("DetDiagNoiseMonitor_validHtmlOutput",true);
37  cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
38  badChannelStatusMask_ = ps.getUntrackedParameter<int>("DetDiagNoiseMonitor_BadChannelStatusMask",
39  ps.getUntrackedParameter<int>("BadChannelStatusMask",0));
40 
41  minerrorrate_ = ps.getUntrackedParameter<double>("DetDiagNoiseMonitor_minerrorrate",
42  ps.getUntrackedParameter<double>("minerrorrate",0.05));
43  minevents_ = ps.getUntrackedParameter<int>("DetDiagNoiseMonitor_minevents",
44  ps.getUntrackedParameter<int>("minevents",1));
45  ProblemCells=0;
47 
48  doProblemCellSetup_ = true;
49 }
50 
52 {
53  if (debug_>2) std::cout <<"\tHcalDetDiagNoiseMonitorClient::analyze()"<<std::endl;
55  calculateProblems(ib,ig);
56 }
57 
59 {
60  if (debug_>2) std::cout <<"\t\tHcalDetDiagNoiseMonitorClient::calculateProblems()"<<std::endl;
61  //double totalevents=0;
62  int etabins=0, phibins=0, zside=0;
63  double problemvalue=0;
64 
65  // Clear away old problems
66  if (ProblemCells!=0)
67  {
69  (ProblemCells->getTH2F())->SetMaximum(1.05);
70  (ProblemCells->getTH2F())->SetMinimum(0.);
71  }
72  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
73  {
74  if (ProblemCellsByDepth->depth[d]!=0)
75  {
76  ProblemCellsByDepth->depth[d]->Reset();
77  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
78  (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
79  }
80  }
81  enoughevents_=true;
82  // Get histograms that are used in testing
83  // currently none used,
84 
85  std::vector<std::string> name = HcalEtaPhiHistNames();
86 
87  // This is a sample of how to get a histogram from the task that can then be used for evaluation purposes
88  /*
89  TH2F* BadTiming[4];
90  TH2F* BadEnergy[4];
91  MonitorElement* me;
92  for (int i=0;i<4;++i)
93  {
94  std::string s=subdir_+name[i]+" Problem Bad Laser Timing";
95  me=dqmStore_->get(s.c_str());
96  if (me!=0) BadTiming[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadTiming[i], debug_);
97  else if (debug_>0) std::cout <<"<HcalDetDiagNoiseMonitorClient::analyze> could not get histogram '"<<s<<"'"<<std::endl;
98  s=subdir_+name[i]+" Problem Bad Laser Energy";
99  me=dqmStore_->get(s.c_str());
100  if (me!=0) BadEnergy[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadEnergy[i], debug_);
101  else if (debug_>0) std::cout <<"<HcalDetDiagNoiseMonitorClient::analyze> could not get histogram '"<<s<<"'"<<std::endl;
102  }
103  */
104 
105  // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
106  // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
107 
108  for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
109  {
110  if (ProblemCellsByDepth->depth[d]==0) continue;
111 
112  //totalevents=DigiPresentByDepth[d]->GetBinContent(0);
113  //totalevents=0;
114  // Check underflow bins for events processed
115  /*
116  if (BadTiming[d]!=0) totalevents = BadTiming[d]->GetBinContent(0);
117  else if (BadEnergy[d]!=0) totalevents = BadEnergy[d]->GetBinContent(0);
118  */
119  //if (totalevents==0 || totalevents<minevents_) continue;
120 
121  //totalevents=1; // temporary value pending removal of histogram normalization from tasks
122 
123  etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
124  phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
125  for (int eta=0;eta<etabins;++eta)
126  {
127  int ieta=CalcIeta(eta,d+1);
128  if (ieta==-9999) continue;
129  for (int phi=0;phi<phibins;++phi)
130  {
131  problemvalue=0;
132  /*
133  if (BadTiming[d]!=0) problemvalue += BadTiming[d]->GetBinContent(eta+1,phi+1)*1./totalevents;
134  else if (BadEnergy[d]!=0) problemvalue += BadEnergy[d]->GetBinContent(eta+1,phi+1)*1./totalevents;
135  */
136  if (problemvalue==0) continue;
137  // problem value is a rate; we can normalize it here
138  problemvalue = std::min(1.,problemvalue);
139 
140  zside=0;
141  if (isHF(eta,d+1)) // shift ieta by 1 for HF
142  ieta<0 ? zside = -1 : zside = 1;
143 
144  // For problem cells that exceed our allowed rate,
145  // set the values to -1 if the cells are already marked in the status database
146  if (problemvalue>minerrorrate_)
147  {
148  HcalSubdetector subdet=HcalEmpty;
149  if (isHB(eta,d+1))subdet=HcalBarrel;
150  else if (isHE(eta,d+1)) subdet=HcalEndcap;
151  else if (isHF(eta,d+1)) subdet=HcalForward;
152  else if (isHO(eta,d+1)) subdet=HcalOuter;
153  HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
154  if (badstatusmap.find(hcalid)!=badstatusmap.end())
155  problemvalue=999;
156  }
157 
158  ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
159  if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
160  } // loop on phi
161  } // loop on eta
162  } // loop on depth
163 
164  if (ProblemCells==0)
165  {
166  if (debug_>0) std::cout <<"<HcalDetDiagNoiseMonitorClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
167  return;
168  }
169 
170  // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
171  etabins=(ProblemCells->getTH2F())->GetNbinsX();
172  phibins=(ProblemCells->getTH2F())->GetNbinsY();
173  for (int eta=0;eta<etabins;++eta)
174  {
175  for (int phi=0;phi<phibins;++phi)
176  {
179  }
180  }
181 
184  return;
185 }
186 
187 //void HcalDetDiagNoiseMonitorClient::endJob(){}
188 
190 {
191 
193  problemnames_.clear();
194 
195  // Put the appropriate name of your problem summary here
196  ProblemCells=ib.book2D(" ProblemDetDiagNoiseMonitor",
197  " Problem DetDiagNoiseMonitor Rate for all HCAL;ieta;iphi",
198  85,-42.5,42.5,
199  72,0.5,72.5);
200  problemnames_.push_back(ProblemCells->getName());
201  if (debug_>1)
202  std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
203  ib.setCurrentFolder(subdir_+"problem_DetDiagNoiseMonitor");
205  ProblemCellsByDepth->setup(ib," Problem DetDiagNoiseMonitor Rate");
206  for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
207  problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
208 
209  doProblemCellSetup_ = false;
210 }
211 
213 {
214  enoughevents_=false;
215  nevts_=0;
216 }
217 
218 //void HcalDetDiagNoiseMonitorClient::endRun(void){analyze();}
219 
222 
224 {
225  if (!ProblemCells)
226  {
227  if (debug_>1) std::cout <<"<HcalDetDiagNoiseMonitorClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
228  return false;
229  }
230  int problemcount=0;
231  int ieta=-9999;
232 
233  for (int depth=0;depth<4; ++depth)
234  {
235  int etabins = (ProblemCells->getTH2F())->GetNbinsX();
236  int phibins = (ProblemCells->getTH2F())->GetNbinsY();
237  for (int hist_eta=0;hist_eta<etabins;++hist_eta)
238  {
239  for (int hist_phi=0; hist_phi<phibins;++hist_phi)
240  {
241  ieta=CalcIeta(hist_eta,depth+1);
242  if (ieta==-9999) continue;
244  continue;
245  if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
246  ++problemcount;
247 
248  } // for (int hist_phi=1;...)
249  } // for (int hist_eta=1;...)
250  } // for (int depth=0;...)
251 
252  if (problemcount>0) return true;
253  return false;
254 }
255 
259 
260 
261 void HcalDetDiagNoiseMonitorClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
262 {
263  // This gets called by HcalMonitorClient
264  // trigger primitives don't yet contribute to channel status (though they could...)
265  // see dead or hot cell code for an example
266 
267 } //void HcalDetDiagNoiseMonitorClient::updateChannelStatus
268 
270 {
272 }
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)
int ib
Definition: cuy.py:660
void setupProblemCells(DQMStore::IBooker &, DQMStore::IGetter &)
std::vector< std::string > HcalEtaPhiHistNames()
int zside(DetId const &)
bool isHE(int etabin, int depth)
void analyze(DQMStore::IBooker &, DQMStore::IGetter &)
void Fill(long long x)
tuple d
Definition: ztail.py:151
void updateChannelStatus(std::map< HcalDetId, unsigned int > &myqual)
std::vector< MonitorElement * > depth
int CalcIeta(int subdet, int eta, int depth)
std::vector< std::string > problemnames_
EtaPhiHists * ProblemCellsByDepth
HcalSubdetector
Definition: HcalAssistant.h:31
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
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
TH2F * getTH2F(void) const
void Reset(void)
reset ME (ie. contents, errors, etc)