00001 #include "DQM/HcalMonitorClient/interface/HcalBeamClient.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 HcalBeamClient::HcalBeamClient(std::string myname)
00021 {
00022 name_=myname;
00023 }
00024
00025 HcalBeamClient::HcalBeamClient(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>("BeamFolder","BeamMonitor_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>("Beam_validHtmlOutput",true);
00039 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040
00041 badChannelStatusMask_ = ps.getUntrackedParameter<int>("Beam_BadChannelStatusMask",
00042 ps.getUntrackedParameter<int>("BadChannelStatusMask",
00043 ((1<<HcalChannelStatus::HcalCellDead)||
00044 (1<<HcalChannelStatus::HcalCellHot))
00045 ));
00046
00047 minerrorrate_ = ps.getUntrackedParameter<double>("Beam_minerrorrate",
00048 ps.getUntrackedParameter<double>("minerrorrate",0.05));
00049 minevents_ = ps.getUntrackedParameter<int>("Beam_minevents",
00050 ps.getUntrackedParameter<int>("minevents",1));
00051 ProblemCells=0;
00052 ProblemCellsByDepth=0;
00053 }
00054
00055 void HcalBeamClient::analyze()
00056 {
00057 if (debug_>2) std::cout <<"\tHcalBeamClient::analyze()"<<std::endl;
00058 enoughevents_=false;
00059 calculateProblems();
00060 }
00061
00062 void HcalBeamClient::calculateProblems()
00063 {
00064 if (debug_>2) std::cout <<"\t\tHcalBeamClient::calculateProblems()"<<std::endl;
00065 if(!dqmStore_) return;
00066 double totalLumiBlocks=0;
00067
00068 int etabins=0, phibins=0, zside=0;
00069 double problemvalue=0;
00070
00071
00072 if (ProblemCells!=0)
00073 {
00074 ProblemCells->Reset();
00075 (ProblemCells->getTH2F())->SetMaximum(1.05);
00076 (ProblemCells->getTH2F())->SetMinimum(0.);
00077 }
00078 for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00079 {
00080 if (ProblemCellsByDepth->depth[d]!=0)
00081 {
00082 ProblemCellsByDepth->depth[d]->Reset();
00083 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00084 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00085 }
00086 }
00087
00088
00089
00090
00091
00092 TH2F* dead = 0;
00093 TH2F* hot = 0;
00094 MonitorElement* me;
00095 me=dqmStore_->get(subdir_+"Lumi/HFlumi_total_deadcells");
00096 if (me!=0)
00097 dead=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,dead,debug_);
00098 else if (debug_>0) std::cout <<" <HcalBeamClient::calculateProblems> Unable to get dead cell plot 'HFlumi_total_deadcells"<<std::endl;
00099 me=dqmStore_->get(subdir_+"Lumi/HFlumi_total_hotcells");
00100 if (me!=0)
00101 hot=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,dead,debug_);
00102 else if (debug_>0) std::cout <<" <HcalBeamClient::calculateProblems> Unable to get hot cell plot 'HFlumi_total_hotcells"<<std::endl;
00103 int myieta=0;
00104 int mydepth=0;
00105 int myiphi=0;
00106
00107 enoughevents_=true;
00108
00109 if (dead!=0 || hot!=0)
00110 {
00111 if (dead!=0)
00112 {
00113 totalLumiBlocks=dead->GetBinContent(-1,-1);
00114 etabins=dead->GetNbinsX();
00115 phibins=dead->GetNbinsY();
00116 }
00117 else
00118 {
00119 totalLumiBlocks=hot->GetBinContent(-1,-1);
00120 etabins=hot->GetNbinsX();
00121 phibins=hot->GetNbinsY();
00122 }
00123 if (totalLumiBlocks<minevents_ || totalLumiBlocks==0)
00124 return;
00125 for (int i=0;i<etabins;++i)
00126 {
00127 i<=3 ? myieta = i-36 : myieta=i+29;
00128 if (abs(myieta)==33 || abs(myieta)==34)
00129 mydepth=1;
00130 else if (abs(myieta)==35 || abs(myieta)==36)
00131 mydepth=2;
00132 for (int j=0;j<phibins;++j)
00133 {
00134 problemvalue=0;
00135 myiphi=2*j+1;
00136 if (dead!=0 && dead->GetBinContent(i+1,j+1)*1./totalLumiBlocks>minerrorrate_)
00137 {
00138 problemvalue+=dead->GetBinContent(i+1,j+1)*1./totalLumiBlocks;
00139 if (debug_>1) std::cout <<"<HcalBeamClient::calculateProblem> Dead cell found at ieta = "<<myieta<<" iphi = "<<myiphi<<" depth = "<<mydepth<<std::endl;
00140 }
00141 if (hot!=0 && hot->GetBinContent(i+1,j+1)*1./totalLumiBlocks>minerrorrate_)
00142 {
00143 problemvalue+=hot->GetBinContent(i+1,j+1)*1./totalLumiBlocks;
00144 if (debug_>1) std::cout <<"<HcalBeamClient::calculateProblem> hot cell found at ieta = "<<myieta<<" iphi = "<<myiphi<<" depth = "<<mydepth<<std::endl;
00145 }
00146 if (problemvalue==0) continue;
00147
00148 HcalDetId hcalid(HcalForward, myieta, myiphi, mydepth);
00149 if (badstatusmap.find(hcalid)!=badstatusmap.end())
00150 problemvalue=999;
00151 myieta<0 ? zside=-1 : zside=1;
00152 ProblemCellsByDepth->depth[mydepth-1]->Fill(myieta+zside,myiphi,problemvalue);
00153 if (ProblemCells!=0) ProblemCells->Fill(myieta+zside,myiphi,problemvalue);
00154 }
00155 }
00156 }
00157
00158
00159 if (ProblemCells==0)
00160 {
00161 if (debug_>0) std::cout <<"<HcalBeamClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00162 return;
00163 }
00164
00165
00166 etabins=(ProblemCells->getTH2F())->GetNbinsX();
00167 phibins=(ProblemCells->getTH2F())->GetNbinsY();
00168 for (int eta=0;eta<etabins;++eta)
00169 {
00170 for (int phi=0;phi<phibins;++phi)
00171 {
00172 if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00173 ProblemCells->setBinContent(eta+1,phi+1,1.);
00174 }
00175 }
00176 FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00177 FillUnphysicalHEHFBins(ProblemCells);
00178 return;
00179 }
00180
00181 void HcalBeamClient::beginJob()
00182 {
00183 dqmStore_ = edm::Service<DQMStore>().operator->();
00184 if (debug_>0)
00185 {
00186 std::cout <<"<HcalBeamClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
00187 dqmStore_->showDirStructure();
00188 }
00189 }
00190 void HcalBeamClient::endJob(){}
00191
00192 void HcalBeamClient::beginRun(void)
00193 {
00194 enoughevents_=false;
00195 if (!dqmStore_)
00196 {
00197 if (debug_>0) std::cout <<"<HcalBeamClient::beginRun> dqmStore does not exist!"<<std::endl;
00198 return;
00199 }
00200 dqmStore_->setCurrentFolder(subdir_);
00201 problemnames_.clear();
00202
00203
00204 if (ProblemCells==0)
00205 ProblemCells=dqmStore_->book2D(" Problem BeamMonitor",
00206 " Problem Beam Monitor Rate for all HCAL;ieta;iphi",
00207 85,-42.5,42.5,
00208 72,0.5,72.5);
00209 problemnames_.push_back(ProblemCells->getName());
00210 if (debug_>1)
00211 std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
00212 dqmStore_->setCurrentFolder(subdir_+"problem_beammonitor");
00213 nevts_=0;
00214 if (ProblemCellsByDepth!=0) return;
00215 ProblemCellsByDepth = new EtaPhiHists();
00216 ProblemCellsByDepth->setup(dqmStore_," Problem BeamMonitor Rate");
00217 for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00218 problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00219 }
00220
00221 void HcalBeamClient::endRun(void){analyze();}
00222
00223 void HcalBeamClient::setup(void){}
00224 void HcalBeamClient::cleanup(void){}
00225
00226 bool HcalBeamClient::hasErrors_Temp(void)
00227 {
00228 if (!ProblemCells)
00229 {
00230 if (debug_>1) std::cout <<"<HcalBeamClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
00231 return false;
00232 }
00233 int problemcount=0;
00234 int ieta=-9999;
00235
00236 for (int depth=0;depth<4; ++depth)
00237 {
00238 int etabins = (ProblemCells->getTH2F())->GetNbinsX();
00239 int phibins = (ProblemCells->getTH2F())->GetNbinsY();
00240 for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00241 {
00242 for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00243 {
00244 ieta=CalcIeta(hist_eta,depth+1);
00245 if (ieta==-9999) continue;
00246 if (ProblemCellsByDepth->depth[depth]==0)
00247 continue;
00248 if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00249 ++problemcount;
00250
00251 }
00252 }
00253 }
00254
00255 if (problemcount>0) return true;
00256 return false;
00257 }
00258
00259 bool HcalBeamClient::hasWarnings_Temp(void){return false;}
00260 bool HcalBeamClient::hasOther_Temp(void){return false;}
00261 bool HcalBeamClient::test_enabled(void){return true;}
00262
00263
00264 void HcalBeamClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00265 {
00266
00267
00268
00269
00270 }
00271
00272