00001 #include "DQM/HcalMonitorClient/interface/HcalHotCellClient.h"
00002 #include "DQM/HcalMonitorClient/interface/HcalClientUtils.h"
00003 #include "DQM/HcalMonitorClient/interface/HcalHistoUtils.h"
00004
00005 #include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
00006 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00007 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
00008
00009 #include <iostream>
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 HcalHotCellClient::HcalHotCellClient(std::string myname)
00021 {
00022 name_=myname;
00023 }
00024
00025 HcalHotCellClient::HcalHotCellClient(std::string myname, const edm::ParameterSet& ps)
00026 {
00027 name_=myname;
00028 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
00029 debug_ = ps.getUntrackedParameter<int>("debug",0);
00030 prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00031 if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00032 prefixME_.append("/");
00033 subdir_ = ps.getUntrackedParameter<std::string>("HotCellFolder","HotCellMonitor_Hcal/");
00034 if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00035 subdir_.append("/");
00036 subdir_=prefixME_+subdir_;
00037
00038 validHtmlOutput_ = ps.getUntrackedParameter<bool>("HotCell_validHtmlOutput",true);
00039 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040 badChannelStatusMask_ = ps.getUntrackedParameter<int>("HotCell_BadChannelStatusMask",
00041 ps.getUntrackedParameter<int>("BadChannelStatusMask",
00042 (1<<HcalChannelStatus::HcalCellHot)));
00043
00044 minerrorrate_ = ps.getUntrackedParameter<double>("HotCell_minerrorrate",
00045 ps.getUntrackedParameter<double>("minerrorrate",0.25));
00046 minevents_ = ps.getUntrackedParameter<int>("HotCell_minevents",
00047 ps.getUntrackedParameter<int>("minevents",100));
00048 Online_ = ps.getUntrackedParameter<bool>("online",false);
00049
00050 ProblemCellsByDepth=0;
00051 ProblemCells=0;
00052 }
00053
00054 void HcalHotCellClient::analyze()
00055 {
00056 if (debug_>2) std::cout <<"\tHcalHotCellClient::analyze()"<<std::endl;
00057 calculateProblems();
00058 }
00059
00060 void HcalHotCellClient::calculateProblems()
00061 {
00062 if (debug_>2) std::cout <<"\t\tHcalHotCellClient::calculateProblems()"<<std::endl;
00063 if(!dqmStore_) return;
00064 double totalevents=0;
00065 int etabins=0, phibins=0, zside=0;
00066 double problemvalue=0;
00067
00068
00069 if (ProblemCells!=0)
00070 {
00071 ProblemCells->Reset();
00072 (ProblemCells->getTH2F())->SetMaximum(1.05);
00073 (ProblemCells->getTH2F())->SetMinimum(0.);
00074 }
00075 for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00076 {
00077 if (ProblemCellsByDepth->depth[d]!=0)
00078 {
00079 ProblemCellsByDepth->depth[d]->Reset();
00080 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00081 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00082 }
00083 }
00084
00085
00086 TH2F* HotAboveThresholdByDepth[4];
00087 TH2F* HotAlwaysAboveThresholdByDepth[4];
00088 TH2F* HotAboveETThresholdByDepth[4];
00089 TH2F* HotAlwaysAboveETThresholdByDepth[4];
00090 TH2F* HotNeighborsByDepth[4];
00091
00092 std::vector<std::string> name = HcalEtaPhiHistNames();
00093
00094 bool neighbortest=false;
00095
00096 MonitorElement* me;
00097 for (int i=0;i<4;++i)
00098 {
00099
00100 HotAboveThresholdByDepth[i]=0;
00101 HotAlwaysAboveThresholdByDepth[i]=0;
00102 HotAboveETThresholdByDepth[i]=0;
00103 HotAlwaysAboveETThresholdByDepth[i]=0;
00104 HotNeighborsByDepth[i]=0;
00105
00106 std::string s=subdir_+"hot_rechit_above_threshold/"+name[i]+"Hot Cells Above ET Threshold";
00107 me=dqmStore_->get(s.c_str());
00108 if (me!=0)HotAboveETThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAboveETThresholdByDepth[i], debug_);
00109
00110 s=subdir_+"hot_rechit_always_above_threshold/"+name[i]+"Hot Cells Persistently Above ET Threshold";
00111 me=dqmStore_->get(s.c_str());
00112 if (me!=0)HotAlwaysAboveETThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAlwaysAboveETThresholdByDepth[i], debug_);
00113
00114 s=subdir_+"hot_rechit_above_threshold/"+name[i]+"Hot Cells Above Energy Threshold";
00115 me=dqmStore_->get(s.c_str());
00116 if (me!=0)HotAboveThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAboveThresholdByDepth[i], debug_);
00117
00118 s=subdir_+"hot_rechit_always_above_threshold/"+name[i]+"Hot Cells Persistently Above Energy Threshold";
00119 me=dqmStore_->get(s.c_str());
00120 if (me!=0)HotAlwaysAboveThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAlwaysAboveThresholdByDepth[i], debug_);
00121
00122 s=subdir_+"hot_neighbortest/"+name[i]+"Hot Cells Failing Neighbor Test";
00123 me=dqmStore_->get(s.c_str());
00124 if (me!=0)HotNeighborsByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotNeighborsByDepth[i], debug_);
00125 s=subdir_+"hot_neighbortest/NeighborTestEnabled";
00126 me=dqmStore_->get(s.c_str());
00127 if (me!=0 && me->getIntValue()==1)
00128 neighbortest=true;
00129 }
00130
00131
00132
00133
00134
00135 for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00136 {
00137 if (ProblemCellsByDepth->depth[d]==0) continue;
00138
00139 if (HotAboveETThresholdByDepth[d]) totalevents = std::max(totalevents, HotAboveETThresholdByDepth[d]->GetBinContent(0));
00140 else if (HotAlwaysAboveETThresholdByDepth[d]) totalevents = std::max(totalevents, HotAlwaysAboveETThresholdByDepth[d]->GetBinContent(0));
00141 else if (HotAboveThresholdByDepth[d]) totalevents = std::max(totalevents, HotAboveThresholdByDepth[d]->GetBinContent(0));
00142 else if (HotAlwaysAboveThresholdByDepth[d]) totalevents = std::max(totalevents, HotAlwaysAboveThresholdByDepth[d]->GetBinContent(0));
00143 else if (neighbortest==true && HotNeighborsByDepth[d]) totalevents = std::max(totalevents, HotNeighborsByDepth[d]->GetBinContent(0));
00144 else if (debug_>0) std::cout <<"<HcalHotCellClient::calculateProblems> No evaluation histograms found; no valid hot tests enabled?" << std::endl;
00145 if (totalevents==0 || totalevents<minevents_) continue;
00146 enoughevents_=true;
00147 etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00148 phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00149 problemvalue=0;
00150 for (int eta=0;eta<etabins;++eta)
00151 {
00152 int ieta=CalcIeta(eta,d+1);
00153 if (ieta==-9999) continue;
00154 for (int phi=0;phi<phibins;++phi)
00155 {
00156 problemvalue=0;
00157
00158 if (HotAboveETThresholdByDepth[d]!=0)
00159 problemvalue+=HotAboveETThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
00160 if (HotAboveThresholdByDepth[d]!=0)
00161 problemvalue+=HotAboveThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
00162 if (HotAlwaysAboveThresholdByDepth[d]!=0)
00163 problemvalue+=HotAlwaysAboveThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
00164 if (neighbortest==true && HotNeighborsByDepth[d]!=0)
00165 problemvalue+=HotNeighborsByDepth[d]->GetBinContent(eta+1,phi+1);
00166 if (problemvalue==0) continue;
00167 problemvalue/=totalevents;
00168 problemvalue = std::min(1.,problemvalue);
00169
00170 zside=0;
00171 if (isHF(eta,d+1))
00172 ieta<0 ? zside = -1 : zside = 1;
00173
00174
00175
00176 if (problemvalue>minerrorrate_)
00177 {
00178 HcalSubdetector subdet=HcalEmpty;
00179 if (isHB(eta,d+1))subdet=HcalBarrel;
00180 else if (isHE(eta,d+1)) subdet=HcalEndcap;
00181 else if (isHF(eta,d+1)) subdet=HcalForward;
00182 else if (isHO(eta,d+1)) subdet=HcalOuter;
00183 HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00184 if (badstatusmap.find(hcalid)!=badstatusmap.end())
00185 problemvalue=999;
00186 }
00187 ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00188 if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00189 }
00190 }
00191 }
00192
00193 if (ProblemCells==0)
00194 {
00195 if (debug_>0) std::cout <<"<HcalHotCellClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00196 return;
00197 }
00198
00199
00200 etabins=(ProblemCells->getTH2F())->GetNbinsX();
00201 phibins=(ProblemCells->getTH2F())->GetNbinsY();
00202 for (int eta=0;eta<etabins;++eta)
00203 {
00204 for (int phi=0;phi<phibins;++phi)
00205 {
00206 if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00207 ProblemCells->setBinContent(eta+1,phi+1,1.);
00208 }
00209 }
00210
00211 FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00212 FillUnphysicalHEHFBins(ProblemCells);
00213 return;
00214 }
00215
00216
00217 void HcalHotCellClient::beginJob()
00218 {
00219 dqmStore_ = edm::Service<DQMStore>().operator->();
00220 if (debug_>0)
00221 {
00222 std::cout <<"<HcalHotCellClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
00223 dqmStore_->showDirStructure();
00224 }
00225 }
00226
00227 void HcalHotCellClient::endJob(){}
00228
00229 void HcalHotCellClient::beginRun(void)
00230 {
00231 enoughevents_=false;
00232 if (!dqmStore_)
00233 {
00234 if (debug_>0) std::cout <<"<HcalHotCellClient::beginRun> dqmStore does not exist!"<<std::endl;
00235 return;
00236 }
00237 dqmStore_->setCurrentFolder(subdir_);
00238 problemnames_.clear();
00239 ProblemCells=dqmStore_->book2D(" ProblemHotCells",
00240 " Problem Hot Cell Rate for all HCAL;ieta;iphi",
00241 85,-42.5,42.5,
00242 72,0.5,72.5);
00243 problemnames_.push_back(ProblemCells->getName());
00244 if (debug_>1)
00245 std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
00246 dqmStore_->setCurrentFolder(subdir_+"problem_hotcells");
00247 ProblemCellsByDepth=new EtaPhiHists();
00248 ProblemCellsByDepth->setup(dqmStore_," Problem Hot Cell Rate");
00249 for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00250 problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00251
00252 nevts_=0;
00253 }
00254
00255 void HcalHotCellClient::endRun(void){analyze();}
00256
00257 void HcalHotCellClient::setup(void){}
00258 void HcalHotCellClient::cleanup(void){}
00259
00260 bool HcalHotCellClient::hasErrors_Temp(void)
00261 {
00262 if (!ProblemCells)
00263 {
00264 if (debug_>1) std::cout <<"<HcalHotCellClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
00265 return false;
00266 }
00267 int problemcount=0;
00268 int ieta=-9999;
00269
00270 for (int depth=0;depth<4; ++depth)
00271 {
00272 int etabins = (ProblemCells->getTH2F())->GetNbinsX();
00273 int phibins = (ProblemCells->getTH2F())->GetNbinsY();
00274 for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00275 {
00276 for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00277 {
00278 ieta=CalcIeta(hist_eta,depth+1);
00279 if (ieta==-9999) continue;
00280 if (ProblemCellsByDepth->depth[depth]==0)
00281 continue;
00282 if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00283 ++problemcount;
00284 }
00285 }
00286 }
00287
00288 if (problemcount>0) return true;
00289 return false;
00290 }
00291
00292 bool HcalHotCellClient::hasWarnings_Temp(void){return false;}
00293 bool HcalHotCellClient::hasOther_Temp(void){return false;}
00294 bool HcalHotCellClient::test_enabled(void){return true;}
00295
00296
00297 void HcalHotCellClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00298 {
00299
00300
00301 if (nevts_<minevents_) return;
00302
00303 float binval;
00304 int ieta=0;
00305 int iphi=0;
00306 int etabins=0;
00307 int phibins=0;
00308
00309 int subdet=0;
00310 if (debug_>1)
00311 {
00312 std::cout <<"<HcalHotCellClient> Summary of Hot Cells in Run: "<<std::endl;
00313 std::cout <<"(Error rate must be >= "<<minerrorrate_*100.<<"% )"<<std::endl;
00314 }
00315 for (int d=0;d<4;++d)
00316 {
00317 etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00318 phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00319 for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00320 {
00321 ieta=CalcIeta(hist_eta,d+1);
00322 if (ieta==-9999) continue;
00323 for (int hist_phi=0;hist_phi<phibins;++hist_phi)
00324 {
00325 iphi=hist_phi+1;
00326
00327
00328 binval=ProblemCellsByDepth->depth[d]->getBinContent(hist_eta+1,hist_phi+1);
00329
00330
00331 if (d<2)
00332 {
00333 if (isHB(hist_eta,d+1))
00334 subdet=HcalBarrel;
00335 else if (isHE(hist_eta,d+1))
00336 subdet=HcalEndcap;
00337 else if (isHF(hist_eta,d+1))
00338 subdet=HcalForward;
00339 }
00340 else if (d==2)
00341 subdet=HcalEndcap;
00342 else if (d==3)
00343 subdet=HcalOuter;
00344
00345
00346 HcalDetId myid((HcalSubdetector)(subdet), ieta, iphi, d+1);
00347
00348 if (!validDetId((HcalSubdetector)(subdet), ieta, iphi, d+1))
00349 continue;
00350
00351 int hotcell=0;
00352 if (binval>minerrorrate_)
00353 hotcell=1;
00354 if (hotcell==1 && debug_>0)
00355 std::cout <<"Hot Cell : subdetector = "<<subdet<<" (eta,phi,depth) = ("<<ieta<<", "<<iphi<<", "<<d+1<<"): "<<binval*100.<<"%"<<std::endl;
00356
00357
00358 if (myqual.find(myid)==myqual.end())
00359 {
00360 myqual[myid]=(hotcell<<HcalChannelStatus::HcalCellHot);
00361 }
00362 else
00363 {
00364 int mask=(1<<HcalChannelStatus::HcalCellHot);
00365
00366 if (hotcell==1)
00367 myqual[myid] |=mask;
00368
00369
00370
00371 else
00372 myqual[myid] &=~mask;
00373 }
00374 }
00375 }
00376 }
00377
00378
00379 }
00380
00381