CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/HcalMonitorClient/src/HcalDigiClient.cc

Go to the documentation of this file.
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  * \file HcalDigiClient.cc
00013  * 
00014  * $Date: 2011/04/12 18:25:42 $
00015  * $Revision: 1.69 $
00016  * \author J. Temple
00017  * \brief DigiClient class
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/"); // 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))); // identify channel status values to mask
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   Online_                = ps.getUntrackedParameter<bool>("online",false);
00049 
00050   ProblemCellsByDepth=0;
00051   ProblemCells=0;
00052 
00053   HFTiming_averageTime=0;
00054 }
00055 
00056 void HcalDigiClient::analyze()
00057 {
00058   if (debug_>2) std::cout <<"\tHcalDigiClient::analyze()"<<std::endl;
00059   calculateProblems();
00060 
00061   // Get Pawel's timing plots to form averages
00062   TH2F* TimingStudyTime=0;
00063   TH2F* TimingStudyOcc=0;
00064   std::string s=subdir_+"HFTimingStudy/sumplots/HFTiming_Total_Time";
00065   
00066   MonitorElement* me=dqmStore_->get(s.c_str());
00067   if (me!=0)
00068     TimingStudyTime=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,TimingStudyTime, debug_);
00069 
00070   s=subdir_+"HFTimingStudy/sumplots/HFTiming_Occupancy";
00071   me=dqmStore_->get(s.c_str());
00072   if (me!=0)
00073     TimingStudyOcc=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,TimingStudyOcc, debug_);
00074 
00075   if (HFTiming_averageTime!=0)
00076     {
00077       HFTiming_averageTime->Reset();
00078       if (TimingStudyTime!=0 && TimingStudyOcc!=0)
00079         {
00080           int etabins=(HFTiming_averageTime->getTH2F())->GetNbinsX();
00081           int phibins=(HFTiming_averageTime->getTH2F())->GetNbinsY();
00082           for (int x=1;x<=etabins;++x)
00083             for (int y=1;y<=phibins;++y)
00084               if (TimingStudyOcc->GetBinContent(x,y)!=0)
00085                 HFTiming_averageTime->setBinContent(x,y,TimingStudyTime->GetBinContent(x,y)*1./TimingStudyOcc->GetBinContent(x,y));
00086         }
00087       HFTiming_averageTime->getTH2F()->SetMinimum(0);
00088     }
00089 }
00090 
00091 void HcalDigiClient::calculateProblems()
00092 {
00093  if (debug_>2) std::cout <<"\t\tHcalDigiClient::calculateProblems()"<<std::endl;
00094   if(!dqmStore_) return;
00095   int totalevents=0;
00096   int etabins=0, phibins=0, zside=0;
00097   double problemvalue=0;
00098 
00099   // Clear away old problems
00100   if (ProblemCells!=0)
00101     {
00102       ProblemCells->Reset();
00103       (ProblemCells->getTH2F())->SetMaximum(1.05);
00104       (ProblemCells->getTH2F())->SetMinimum(0.);
00105     }
00106   for  (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00107     {
00108       if (ProblemCellsByDepth->depth[d]!=0) 
00109         {
00110           ProblemCellsByDepth->depth[d]->Reset();
00111           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00112           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00113         }
00114     }
00115 
00116   // Get histograms that are used in testing
00117   TH2F* BadDigisByDepth[4];
00118   TH2F* GoodDigisByDepth[4];
00119 
00120   std::vector<std::string> name = HcalEtaPhiHistNames();
00121 
00122   bool gothistos=true;
00123 
00124   MonitorElement* me;
00125   for (int i=0;i<4;++i)
00126     {
00127       std::string s=subdir_+"bad_digis/bad_digi_occupancy/"+name[i]+"Bad Digi Map";
00128       me=dqmStore_->get(s.c_str());
00129       if (me==0) 
00130         {
00131           gothistos=false;
00132           if (debug_>0) std::cout <<"<HcalDigiClient::calculateProblems> Could not get histogram with name "<<s<<std::endl;
00133         }
00134       BadDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadDigisByDepth[i], debug_);
00135 
00136       s=subdir_+"good_digis/digi_occupancy/"+name[i]+" Digi Eta-Phi Occupancy Map";
00137       me=dqmStore_->get(s.c_str());
00138       if (me==0) 
00139         {
00140           gothistos=false;
00141           if (debug_>0) std::cout <<"<HcalDigiClient::calculateProblems> Could not get histogram with name "<<s<<std::endl;
00142         }
00143       GoodDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadDigisByDepth[i], debug_);
00144     }
00145 
00146   if (gothistos==false)
00147     {
00148       if (debug_>0) std::cout <<"<HcalDigiClient::calculateProblems> Unable to get all necessary histograms to evaluate problem rate"<<std::endl;
00149       return;
00150     }
00151 
00152   for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00153     {
00154       if (ProblemCellsByDepth->depth[d]==0) continue;
00155 
00156       if (BadDigisByDepth[d]==0 || GoodDigisByDepth[d]==0) continue;
00157       totalevents=(int)GoodDigisByDepth[d]->GetBinContent(0,0);
00158       if (totalevents<minevents_ ) continue;
00159       enoughevents_=true;
00160       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00161       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00162       for (int eta=0;eta<etabins;++eta)
00163         {
00164           int ieta=CalcIeta(eta,d+1);
00165           if (ieta==-9999) continue;
00166           for (int phi=0;phi<phibins;++phi)
00167             {
00168               problemvalue=0; // problem fraction sums over all three tests
00169               if (BadDigisByDepth[d]->GetBinContent(eta+1,phi+1) > 0) // bad cells found
00170                 problemvalue=(BadDigisByDepth[d]->GetBinContent(eta+1,phi+1)*1./(BadDigisByDepth[d]->GetBinContent(eta+1,phi+1)+GoodDigisByDepth[d]->GetBinContent(eta+1,phi+1)));
00171               
00172               zside=0;
00173               if (isHF(eta,d+1)) // shift ieta by 1 for HF
00174                 ieta<0 ? zside = -1 : zside = 1;
00175               
00176               // For problem cells that exceed our allowed rate,
00177               // set the values to -1 if the cells are already marked in the status database
00178               if (problemvalue>minerrorrate_)
00179                 {
00180                   HcalSubdetector subdet=HcalEmpty;
00181                   if (isHB(eta,d+1))subdet=HcalBarrel;
00182                   else if (isHE(eta,d+1)) subdet=HcalEndcap;
00183                   else if (isHF(eta,d+1)) subdet=HcalForward;
00184                   else if (isHO(eta,d+1)) subdet=HcalOuter;
00185                   HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00186                   if (badstatusmap.find(hcalid)!=badstatusmap.end())
00187                     problemvalue=999;
00188                 }
00189               ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00190               if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00191             } // loop on phi
00192         } // loop on eta
00193     } // loop on depth
00194   
00195   if (ProblemCells==0)
00196     {
00197       if (debug_>0) std::cout <<"<HcalDigiClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00198       return;
00199     }
00200 
00201   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00202   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00203   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00204   for (int eta=0;eta<etabins;++eta)
00205     {
00206       for (int phi=0;phi<phibins;++phi)
00207         {
00208           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00209             ProblemCells->setBinContent(eta+1,phi+1,1.);
00210         }
00211     }
00212   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00213   FillUnphysicalHEHFBins(ProblemCells);
00214   return;
00215 }
00216 
00217 
00218 void HcalDigiClient::beginJob()
00219 {
00220   dqmStore_ = edm::Service<DQMStore>().operator->();
00221   if (debug_>0) 
00222     {
00223       std::cout <<"<HcalDigiClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00224       dqmStore_->showDirStructure();
00225     }
00226 }
00227 
00228 void HcalDigiClient::endJob(){}
00229 
00230 void HcalDigiClient::beginRun(void)
00231 {
00232   enoughevents_=false;
00233   if (!dqmStore_) 
00234     {
00235       if (debug_>0) std::cout <<"<HcalDigiClient::beginRun> dqmStore does not exist!"<<std::endl;
00236       return;
00237     }
00238   dqmStore_->setCurrentFolder(subdir_);
00239   problemnames_.clear();
00240   ProblemCells=dqmStore_->book2D(" ProblemDigis",
00241                                  " Problem Digi Rate for all HCAL;ieta;iphi",
00242                                  85,-42.5,42.5,
00243                                  72,0.5,72.5);
00244   problemnames_.push_back(ProblemCells->getName());
00245   if (debug_>1)
00246     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00247   dqmStore_->setCurrentFolder(subdir_+"problem_digis");
00248   ProblemCellsByDepth = new EtaPhiHists();
00249   ProblemCellsByDepth->setup(dqmStore_," Problem Digi Rate");
00250   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00251     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00252 
00253   nevts_=0;
00254 
00255   dqmStore_->setCurrentFolder(subdir_+"HFTimingStudy");
00256   HFTiming_averageTime=dqmStore_->book2D("HFTimingStudy_Average_Time","HFTimingStudy Average Time (time sample)",83,-41.5,41.5,72,0.5,72.5);
00257 }
00258 
00259 void HcalDigiClient::endRun(void){analyze();}
00260 
00261 void HcalDigiClient::setup(void){}
00262 void HcalDigiClient::cleanup(void){}
00263 
00264 bool HcalDigiClient::hasErrors_Temp(void)
00265 {
00266   if (!ProblemCells)
00267     {
00268       if (debug_>1) std::cout <<"<HcalDigiClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00269       return false;
00270     }
00271   int problemcount=0;
00272   int ieta=-9999;
00273 
00274   for (int depth=0;depth<4; ++depth)
00275     {
00276       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00277       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00278       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00279         {
00280           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00281             {
00282               ieta=CalcIeta(hist_eta,depth+1);
00283               if (ieta==-9999) continue;
00284               if (ProblemCellsByDepth->depth[depth]==0)
00285                 continue;
00286               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00287                 ++problemcount;
00288             } // for (int hist_phi=1;...)
00289         } // for (int hist_eta=1;...)
00290     } // for (int depth=0;...)
00291   
00292   if (problemcount>0) return true;
00293   return false;
00294 }
00295 
00296 bool HcalDigiClient::hasWarnings_Temp(void){return false;}
00297 bool HcalDigiClient::hasOther_Temp(void){return false;}
00298 bool HcalDigiClient::test_enabled(void){return true;}
00299 
00300 
00301 void HcalDigiClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00302 {
00303   // digi client does not alter channel status yet;
00304   // look at dead cell or hot cell clients for example code
00305 } //void HcalDigiClient::updateChannelStatus
00306 
00307