00001 #include "DQM/HcalMonitorClient/interface/HcalDigiClient.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 HcalDigiClient::HcalDigiClient(std::string myname)
00021 {
00022 name_=myname;
00023 }
00024
00025 HcalDigiClient::HcalDigiClient(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>("DigiFolder","DigiMonitor_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>("Digi_validHtmlOutput",true);
00039 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040 badChannelStatusMask_ = ps.getUntrackedParameter<int>("Digi_BadChannelStatusMask",
00041 ps.getUntrackedParameter<int>("BadChannelStatusMask",
00042 (1<<HcalChannelStatus::HcalCellDead)));
00043
00044 minerrorrate_ = ps.getUntrackedParameter<double>("Digi_minerrorrate",
00045 ps.getUntrackedParameter<double>("minerrorrate",0.05));
00046 minevents_ = ps.getUntrackedParameter<int>("Digi_minevents",
00047 ps.getUntrackedParameter<int>("minevents",1));
00048 ProblemCellsByDepth=0;
00049 HFTiming_averageTime=0;
00050 }
00051
00052 void HcalDigiClient::analyze()
00053 {
00054 if (debug_>2) std::cout <<"\tHcalDigiClient::analyze()"<<std::endl;
00055 calculateProblems();
00056
00057
00058 TH2F* TimingStudyTime=0;
00059 TH2F* TimingStudyOcc=0;
00060 std::string s=subdir_+"HFTimingStudy/sumplots/HFTiming_Total_Time";
00061
00062 MonitorElement* me=dqmStore_->get(s.c_str());
00063 if (me!=0)
00064 TimingStudyTime=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,TimingStudyTime, debug_);
00065
00066 s=subdir_+"HFTimingStudy/sumplots/HFTiming_Occupancy";
00067 me=dqmStore_->get(s.c_str());
00068 if (me!=0)
00069 TimingStudyOcc=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,TimingStudyOcc, debug_);
00070
00071 if (HFTiming_averageTime!=0)
00072 {
00073 HFTiming_averageTime->Reset();
00074 if (TimingStudyTime!=0 && TimingStudyOcc!=0)
00075 {
00076 int etabins=(HFTiming_averageTime->getTH2F())->GetNbinsX();
00077 int phibins=(HFTiming_averageTime->getTH2F())->GetNbinsY();
00078 for (int x=1;x<=etabins;++x)
00079 for (int y=1;y<=phibins;++y)
00080 if (TimingStudyOcc->GetBinContent(x,y)!=0)
00081 HFTiming_averageTime->setBinContent(x,y,TimingStudyTime->GetBinContent(x,y)*1./TimingStudyOcc->GetBinContent(x,y));
00082 }
00083 HFTiming_averageTime->getTH2F()->SetMinimum(0);
00084 }
00085 }
00086
00087 void HcalDigiClient::calculateProblems()
00088 {
00089 if (debug_>2) std::cout <<"\t\tHcalDigiClient::calculateProblems()"<<std::endl;
00090 if(!dqmStore_) return;
00091 int totalevents=0;
00092 int etabins=0, phibins=0, zside=0;
00093 double problemvalue=0;
00094
00095
00096 if (ProblemCells!=0)
00097 {
00098 ProblemCells->Reset();
00099 (ProblemCells->getTH2F())->SetMaximum(1.05);
00100 (ProblemCells->getTH2F())->SetMinimum(0.);
00101 }
00102 for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00103 {
00104 if (ProblemCellsByDepth->depth[d]!=0)
00105 {
00106 ProblemCellsByDepth->depth[d]->Reset();
00107 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00108 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00109 }
00110 }
00111
00112
00113 TH2F* BadDigisByDepth[4];
00114 TH2F* GoodDigisByDepth[4];
00115
00116 std::vector<std::string> name = HcalEtaPhiHistNames();
00117
00118 bool gothistos=true;
00119
00120 MonitorElement* me;
00121 for (int i=0;i<4;++i)
00122 {
00123 std::string s=subdir_+"bad_digis/bad_digi_occupancy/"+name[i]+"Bad Digi Map";
00124 me=dqmStore_->get(s.c_str());
00125 if (me==0)
00126 {
00127 gothistos=false;
00128 if (debug_>0) std::cout <<"<HcalDigiClient::calculateProblems> Could not get histogram with name "<<s<<std::endl;
00129 }
00130 BadDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadDigisByDepth[i], debug_);
00131
00132 s=subdir_+"good_digis/digi_occupancy/"+name[i]+" Digi Eta-Phi Occupancy Map";
00133 me=dqmStore_->get(s.c_str());
00134 if (me==0)
00135 {
00136 gothistos=false;
00137 if (debug_>0) std::cout <<"<HcalDigiClient::calculateProblems> Could not get histogram with name "<<s<<std::endl;
00138 }
00139 GoodDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadDigisByDepth[i], debug_);
00140 }
00141
00142 if (gothistos==false)
00143 {
00144 if (debug_>0) std::cout <<"<HcalDigiClient::calculateProblems> Unable to get all necessary histograms to evaluate problem rate"<<std::endl;
00145 return;
00146 }
00147
00148 for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00149 {
00150 if (ProblemCellsByDepth->depth[d]==0) continue;
00151
00152 if (BadDigisByDepth[d]==0 || GoodDigisByDepth[d]==0) continue;
00153 totalevents=(int)GoodDigisByDepth[d]->GetBinContent(0,0);
00154 if (totalevents<minevents_ ) continue;
00155 enoughevents_=true;
00156 etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00157 phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00158 for (int eta=0;eta<etabins;++eta)
00159 {
00160 int ieta=CalcIeta(eta,d+1);
00161 if (ieta==-9999) continue;
00162 for (int phi=0;phi<phibins;++phi)
00163 {
00164 problemvalue=0;
00165 if (BadDigisByDepth[d]->GetBinContent(eta+1,phi+1) > 0)
00166 problemvalue=(BadDigisByDepth[d]->GetBinContent(eta+1,phi+1)*1./(BadDigisByDepth[d]->GetBinContent(eta+1,phi+1)+GoodDigisByDepth[d]->GetBinContent(eta+1,phi+1)));
00167
00168 zside=0;
00169 if (isHF(eta,d+1))
00170 ieta<0 ? zside = -1 : zside = 1;
00171
00172
00173
00174 if (problemvalue>minerrorrate_)
00175 {
00176 HcalSubdetector subdet=HcalEmpty;
00177 if (isHB(eta,d+1))subdet=HcalBarrel;
00178 else if (isHE(eta,d+1)) subdet=HcalEndcap;
00179 else if (isHF(eta,d+1)) subdet=HcalForward;
00180 else if (isHO(eta,d+1)) subdet=HcalOuter;
00181 HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00182 if (badstatusmap.find(hcalid)!=badstatusmap.end())
00183 problemvalue=999;
00184 }
00185 ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00186 if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00187 }
00188 }
00189 }
00190
00191 if (ProblemCells==0)
00192 {
00193 if (debug_>0) std::cout <<"<HcalDigiClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00194 return;
00195 }
00196
00197
00198 etabins=(ProblemCells->getTH2F())->GetNbinsX();
00199 phibins=(ProblemCells->getTH2F())->GetNbinsY();
00200 for (int eta=0;eta<etabins;++eta)
00201 {
00202 for (int phi=0;phi<phibins;++phi)
00203 {
00204 if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00205 ProblemCells->setBinContent(eta+1,phi+1,1.);
00206 }
00207 }
00208 FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00209 FillUnphysicalHEHFBins(ProblemCells);
00210 return;
00211 }
00212
00213
00214 void HcalDigiClient::beginJob()
00215 {
00216 dqmStore_ = edm::Service<DQMStore>().operator->();
00217 if (debug_>0)
00218 {
00219 std::cout <<"<HcalDigiClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
00220 dqmStore_->showDirStructure();
00221 }
00222 }
00223
00224 void HcalDigiClient::endJob(){}
00225
00226 void HcalDigiClient::beginRun(void)
00227 {
00228 enoughevents_=false;
00229 if (!dqmStore_)
00230 {
00231 if (debug_>0) std::cout <<"<HcalDigiClient::beginRun> dqmStore does not exist!"<<std::endl;
00232 return;
00233 }
00234 dqmStore_->setCurrentFolder(subdir_);
00235 problemnames_.clear();
00236 ProblemCells=dqmStore_->book2D(" ProblemDigis",
00237 " Problem Digi Rate for all HCAL;ieta;iphi",
00238 85,-42.5,42.5,
00239 72,0.5,72.5);
00240 problemnames_.push_back(ProblemCells->getName());
00241 if (debug_>1)
00242 std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
00243 dqmStore_->setCurrentFolder(subdir_+"problem_digis");
00244 ProblemCellsByDepth = new EtaPhiHists();
00245 ProblemCellsByDepth->setup(dqmStore_," Problem Digi Rate");
00246 for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00247 problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00248
00249 nevts_=0;
00250
00251 dqmStore_->setCurrentFolder(subdir_+"HFTimingStudy");
00252 HFTiming_averageTime=dqmStore_->book2D("HFTimingStudy_Average_Time","HFTimingStudy Average Time (time sample)",83,-41.5,41.5,72,0.5,72.5);
00253 }
00254
00255 void HcalDigiClient::endRun(void){analyze();}
00256
00257 void HcalDigiClient::setup(void){}
00258 void HcalDigiClient::cleanup(void){}
00259
00260 bool HcalDigiClient::hasErrors_Temp(void)
00261 {
00262 if (!ProblemCells)
00263 {
00264 if (debug_>1) std::cout <<"<HcalDigiClient::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 HcalDigiClient::hasWarnings_Temp(void){return false;}
00293 bool HcalDigiClient::hasOther_Temp(void){return false;}
00294 bool HcalDigiClient::test_enabled(void){return true;}
00295
00296
00297 void HcalDigiClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00298 {
00299
00300
00301 }
00302
00303