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