00001 #include "DQM/HcalMonitorClient/interface/HcalTrigPrimClient.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 HcalTrigPrimClient::HcalTrigPrimClient(std::string myname)
00021 {
00022 name_=myname;
00023 }
00024
00025 HcalTrigPrimClient::HcalTrigPrimClient(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>("TrigPrimFolder","TrigPrimMonitor_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>("TrigPrim_validHtmlOutput",true);
00039 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040 badChannelStatusMask_ = ps.getUntrackedParameter<int>("TrigPrim_BadChannelStatusMask",
00041 ps.getUntrackedParameter<int>("BadChannelStatusMask",0));
00042
00043 minerrorrate_ = ps.getUntrackedParameter<double>("TrigPrim_minerrorrate",
00044 ps.getUntrackedParameter<double>("minerrorrate",0.01));
00045 minevents_ = ps.getUntrackedParameter<int>("TrigPrim_minevents",
00046 ps.getUntrackedParameter<int>("minevents",1));
00047 ProblemCells=0;
00048 ProblemCellsByDepth=0;
00049 }
00050
00051 void HcalTrigPrimClient::analyze()
00052 {
00053 if (debug_>2) std::cout <<"\tHcalTrigPrimClient::analyze()"<<std::endl;
00054 calculateProblems();
00055 }
00056
00057 void HcalTrigPrimClient::calculateProblems()
00058 {
00059 if (debug_>2) std::cout <<"\t\tHcalTrigPrimClient::calculateProblems()"<<std::endl;
00060 if(!dqmStore_) return;
00061 double totalevents=0;
00062 int etabins=0, phibins=0;
00063 double problemvalue=0;
00064 enoughevents_=false;
00065
00066
00067 if (ProblemCells!=0)
00068 {
00069 ProblemCells->Reset();
00070 (ProblemCells->getTH2F())->SetMaximum(1.05);
00071 (ProblemCells->getTH2F())->SetMinimum(0.);
00072 }
00073 for (unsigned int d=0;d<ProblemCellsByDepth->depth.size();++d)
00074 {
00075 if (ProblemCellsByDepth->depth[d]!=0)
00076 {
00077 ProblemCellsByDepth->depth[d]->Reset();
00078 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00079 (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00080 }
00081 }
00082
00083 for (unsigned int d=0;d<ProblemsByDepthZS_->depth.size();++d)
00084 {
00085 if (ProblemsByDepthZS_->depth[d]!=0)
00086 {
00087 ProblemsByDepthZS_->depth[d]->Reset();
00088 (ProblemsByDepthZS_->depth[d]->getTH2F())->SetMaximum(1.05);
00089 (ProblemsByDepthZS_->depth[d]->getTH2F())->SetMinimum(0.);
00090 }
00091 }
00092
00093 for (unsigned int d=0;d<ProblemsByDepthNZS_->depth.size();++d)
00094 {
00095 if (ProblemsByDepthNZS_->depth[d]!=0)
00096 {
00097 ProblemsByDepthNZS_->depth[d]->Reset();
00098 (ProblemsByDepthNZS_->depth[d]->getTH2F())->SetMaximum(1.05);
00099 (ProblemsByDepthNZS_->depth[d]->getTH2F())->SetMinimum(0.);
00100 }
00101 }
00102
00103
00104
00105
00106 std::vector<std::string> name = HcalEtaPhiHistNames();
00107
00108
00109
00110
00111 MonitorElement* me;
00112 TH2F *goodZS=0;
00113 TH2F *badZS=0;
00114 TH2F* goodNZS=0;
00115 TH2F* badNZS=0;
00116
00117 me=dqmStore_->get(subdir_+"Good TPs_ZS");
00118 if (!me && debug_>0)
00119 std::cout <<"<HcalTrigPrimClient::calculateProblems> Could not get histogram named '"<<subdir_<<"Good TPs_ZS'"<<std::endl;
00120 else goodZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, goodZS, debug_);
00121
00122 me=dqmStore_->get(subdir_+"Bad TPs_ZS");
00123 if (!me && debug_>0)
00124 std::cout <<"<HcalTrigPrimClient::calculateProblems> Could not get histogram named '"<<subdir_<<"Bad TPs_ZS'"<<std::endl;
00125 else badZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, badZS, debug_);
00126
00127 me=dqmStore_->get(subdir_+"noZS/Good TPs_noZS");
00128 if (!me && debug_>0)
00129 std::cout <<"<HcalTrigPrimClient::calculateProblems> Could not get histogram named '"<<subdir_<<"noZS/Good TPs_noZS'"<<std::endl;
00130 else goodNZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, goodNZS, debug_);
00131
00132 me=dqmStore_->get(subdir_+"noZS/Bad TPs_noZS");
00133 if (!me && debug_>0)
00134 std::cout <<"<HcalTrigPrimClient::calculateProblems> Could not get histogram named '"<<subdir_<<"noZS/Bad TPs_noZS'"<<std::endl;
00135 else badNZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, badNZS, debug_);
00136
00137
00138 if (goodZS!=0)
00139 {
00140 etabins=goodZS->GetNbinsX();
00141 phibins=goodZS->GetNbinsY();
00142 totalevents=goodNZS->GetBinContent(0);
00143 }
00144 else if (goodNZS!=0)
00145 {
00146 etabins=goodNZS->GetNbinsX();
00147 phibins=goodNZS->GetNbinsY();
00148 totalevents=goodNZS->GetBinContent(0);
00149 }
00150
00151 if (totalevents<minevents_)
00152 {
00153 enoughevents_=false;
00154 if (debug_>2) std::cout <<"<HcalTrigPrimClient::calculateProblems()> Not enough events! events = "<<totalevents<<" minimum required = "<<minevents_<<std::endl;
00155 return;
00156 }
00157 enoughevents_=true;
00158
00159
00160
00161 int ieta=-99, iphi=-99;
00162 int badvalZS=0, goodvalZS=0;
00163 int badvalNZS=0, goodvalNZS=0;
00164 for (int eta=1;eta<=etabins;++eta)
00165 {
00166 ieta=eta-33;
00167 for (int phi=1;phi<=phibins;++phi)
00168 {
00169 badvalZS=0, goodvalZS=0;
00170 badvalNZS=0, goodvalNZS=0;
00171 iphi=phi;
00172 if (badZS!=0) badvalZS=(int)badZS->GetBinContent(eta,phi);
00173 if (badNZS!=0) badvalNZS=(int)badNZS->GetBinContent(eta,phi);
00174 if (badvalZS+badvalNZS==0) continue;
00175 if (goodZS!=0) goodvalZS=(int)goodZS->GetBinContent(eta,phi);
00176 if (goodNZS!=0) goodvalNZS=(int)goodNZS->GetBinContent(eta,phi);
00177
00178 if (badvalNZS>0)
00179 {
00180 problemvalue=badvalNZS*1./(badvalNZS+goodvalNZS);
00181 if (abs(ieta)<29)
00182 {
00183 ProblemsByDepthNZS_->depth[0]->Fill(ieta,iphi,problemvalue);
00184 if (abs(ieta)==28)
00185 ProblemsByDepthNZS_->depth[0]->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00186 }
00187 else
00188 {
00189
00190
00191
00192
00193
00194
00195
00196 int newieta=-99;
00197 for (int i=0;i<3;++i)
00198 {
00199 newieta=i+29+3*(abs(ieta)-29)+1;
00200 if (ieta<0) newieta*=-1;
00201 ProblemsByDepthNZS_->depth[0]->Fill(newieta,iphi,problemvalue);
00202 ProblemsByDepthNZS_->depth[0]->Fill(newieta,(iphi-2+72)%72,problemvalue);
00203 }
00204 if (abs(ieta)==32)
00205 {
00206 ProblemsByDepthNZS_->depth[0]->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00207 ProblemsByDepthNZS_->depth[0]->Fill(newieta,(iphi-2+72)%72,problemvalue);
00208 }
00209 }
00210 }
00211 if (badvalZS>0)
00212 {
00213 problemvalue=badvalZS*1./(badvalZS+goodvalZS);
00214 if (abs(ieta)<29)
00215 {
00216 ProblemsByDepthZS_->depth[0]->Fill(ieta,iphi,problemvalue);
00217 if (abs(ieta)==28)
00218 ProblemsByDepthZS_->depth[0]->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00219 }
00220 else
00221 {
00222 int newieta=-99;
00223 for (int i=0;i<3;++i)
00224 {
00225 newieta=i+29+3*(abs(ieta)-29)+1;
00226 if (ieta<0) newieta*=-1;
00227 ProblemsByDepthZS_->depth[0]->Fill(newieta,iphi,problemvalue);
00228 ProblemsByDepthZS_->depth[0]->Fill(newieta,(iphi-2+72)%72,problemvalue);
00229 }
00230 if (abs(ieta)==32)
00231 {
00232 ProblemsByDepthZS_->depth[0]->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00233 ProblemsByDepthZS_->depth[0]->Fill(42*abs(ieta)/ieta,(iphi-2+72)%72,problemvalue);
00234 }
00235 }
00236 }
00237 if (badvalZS>0 || badvalNZS>0)
00238 {
00239
00240
00241
00242
00243 if (badvalZS==0) continue;
00244 problemvalue=(badvalZS*1.)/(badvalZS+goodvalZS);
00245 if (abs(ieta)<29)
00246 {
00247 ProblemCellsByDepth->depth[0]->Fill(ieta,iphi,problemvalue);
00248 ProblemCells->Fill(ieta,iphi,problemvalue);
00249 if (abs(ieta)==28)
00250 {
00251 ProblemCellsByDepth->depth[0]->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00252 ProblemCells->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00253 }
00254 }
00255 else
00256 {
00257 int newieta=-99;
00258 int newiphi=(iphi-2+72)%72;
00259
00260
00261
00262 for (int i=0;i<3;++i)
00263 {
00264 newieta=i+29+3*(abs(ieta)-29)+1;
00265 if (ieta<0) newieta*=-1;
00266 ProblemCellsByDepth->depth[0]->Fill(newieta,iphi,problemvalue);
00267 ProblemCells->Fill(newieta,iphi,problemvalue);
00268 ProblemCellsByDepth->depth[0]->Fill(newieta,newiphi,problemvalue);
00269 ProblemCells->Fill(newieta,newiphi,problemvalue);
00270 }
00271 if (abs(ieta)==32)
00272 {
00273 ProblemCellsByDepth->depth[0]->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00274 ProblemCells->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00275 ProblemCellsByDepth->depth[0]->Fill(42*abs(ieta)/ieta,newiphi,problemvalue);
00276 ProblemCells->Fill(42*abs(ieta)/ieta,newiphi,problemvalue);
00277 }
00278 }
00279 }
00280 }
00281 }
00282
00283
00284 if (ProblemCells==0)
00285 {
00286 if (debug_>0) std::cout <<"<HcalTrigPrimClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00287 return;
00288 }
00289
00290
00291 etabins=(ProblemCells->getTH2F())->GetNbinsX();
00292 phibins=(ProblemCells->getTH2F())->GetNbinsY();
00293 for (int eta=0;eta<etabins;++eta)
00294 {
00295 for (int phi=0;phi<phibins;++phi)
00296 {
00297 if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00298 ProblemCells->setBinContent(eta+1,phi+1,1.);
00299 }
00300 }
00301
00302 FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00303 FillUnphysicalHEHFBins(*ProblemsByDepthZS_);
00304 FillUnphysicalHEHFBins(*ProblemsByDepthNZS_);
00305 FillUnphysicalHEHFBins(ProblemCells);
00306 return;
00307 }
00308
00309 void HcalTrigPrimClient::beginJob()
00310 {
00311 dqmStore_ = edm::Service<DQMStore>().operator->();
00312 if (debug_>0)
00313 {
00314 std::cout <<"<HcalTrigPrimClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
00315 dqmStore_->showDirStructure();
00316 }
00317 }
00318 void HcalTrigPrimClient::endJob(){}
00319
00320 void HcalTrigPrimClient::beginRun(void)
00321 {
00322 enoughevents_=false;
00323 if (!dqmStore_)
00324 {
00325 if (debug_>0) std::cout <<"<HcalTrigPrimClient::beginRun> dqmStore does not exist!"<<std::endl;
00326 return;
00327 }
00328 dqmStore_->setCurrentFolder(subdir_);
00329 problemnames_.clear();
00330
00331
00332 ProblemCells=dqmStore_->book2D(" ProblemTriggerPrimitives",
00333 " Problem Trigger Primitive Rate for all HCAL;ieta;iphi",
00334 85,-42.5,42.5,
00335 72,0.5,72.5);
00336 problemnames_.push_back(ProblemCells->getName());
00337 if (debug_>1)
00338 std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<" \t Failed? "<<(ProblemCells==0)<<std::endl;
00339 dqmStore_->setCurrentFolder(subdir_+"problem_triggerprimitives");
00340 ProblemCellsByDepth = new EtaPhiHists();
00341 ProblemCellsByDepth->setup(dqmStore_," Problem Trigger Primitive Rate");
00342 for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00343 problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00344 nevts_=0;
00345
00346 dqmStore_->setCurrentFolder(subdir_+"problem_ZS");
00347 ProblemsByDepthZS_ = new EtaPhiHists();
00348 ProblemsByDepthZS_->setup(dqmStore_,"ZS Problem Trigger Primitive Rate");
00349 dqmStore_->setCurrentFolder(subdir_+"problem_NZS");
00350 ProblemsByDepthNZS_ = new EtaPhiHists();
00351 ProblemsByDepthNZS_->setup(dqmStore_,"NZS Problem Trigger Primitive Rate");
00352 }
00353
00354 void HcalTrigPrimClient::endRun(void){analyze();}
00355
00356 void HcalTrigPrimClient::setup(void){}
00357 void HcalTrigPrimClient::cleanup(void){}
00358
00359 bool HcalTrigPrimClient::hasErrors_Temp(void)
00360 {
00361 if (!ProblemCells)
00362 {
00363 if (debug_>1) std::cout <<"<HcalTrigPrimClient::hasErrors_Temp> ProblemCells histogram does not exist!"<<std::endl;
00364 return false;
00365 }
00366 int problemcount=0;
00367 int ieta=-9999;
00368
00369 for (int depth=0;depth<4; ++depth)
00370 {
00371 int etabins = (ProblemCells->getTH2F())->GetNbinsX();
00372 int phibins = (ProblemCells->getTH2F())->GetNbinsY();
00373 for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00374 {
00375 for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00376 {
00377 ieta=CalcIeta(hist_eta,depth+1);
00378 if (ieta==-9999) continue;
00379 if (ProblemCellsByDepth->depth[depth]==0)
00380 continue;
00381 if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00382 ++problemcount;
00383
00384 }
00385 }
00386 }
00387
00388 if (problemcount>0) return true;
00389 return false;
00390 }
00391
00392 bool HcalTrigPrimClient::hasWarnings_Temp(void){return false;}
00393 bool HcalTrigPrimClient::hasOther_Temp(void){return false;}
00394 bool HcalTrigPrimClient::test_enabled(void){return true;}
00395
00396
00397 void HcalTrigPrimClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00398 {
00399
00400
00401
00402
00403 }
00404
00405