CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/HcalMonitorClient/src/HcalCoarsePedestalClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalCoarsePedestalClient.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 HcalCoarsePedestalClient.cc
00013  * 
00014  * $Date: 2010/09/17 13:47:10 $
00015  * $Revision: 1.5 $
00016  * \author J. Temple
00017  * \brief CoarsePedestalClient class
00018  */
00019 
00020 HcalCoarsePedestalClient::HcalCoarsePedestalClient(std::string myname)
00021 {
00022   name_=myname;
00023 }
00024 
00025 HcalCoarsePedestalClient::HcalCoarsePedestalClient(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>("CoarsePedestalFolder","CoarsePedestalMonitor_Hcal/"); // CoarsePedestalMonitor_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>("CoarsePedestal_validHtmlOutput",true);
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040   badChannelStatusMask_   = ps.getUntrackedParameter<int>("CoarsePedestal_BadChannelStatusMask",
00041                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",
00042                                                                                         ((1<<HcalChannelStatus::HcalCellDead)|(1<<HcalChannelStatus::HcalCellHot)))); // identify channel status values to mask
00043   
00044   minerrorrate_ = ps.getUntrackedParameter<double>("CoarsePedestal_minerrorrate",
00045                                                    ps.getUntrackedParameter<double>("minerrorrate",0.05));
00046 
00047 
00048   // minevents_ canbe overwritten by monitor task value
00049   minevents_    = ps.getUntrackedParameter<int>("CoarsePedestal_minevents",
00050                                                 ps.getUntrackedParameter<int>("minevents",1));
00051 
00052   ProblemCellsByDepth=0;
00053 
00054 }
00055 
00056 void HcalCoarsePedestalClient::analyze()
00057 {
00058   if (debug_>2) std::cout <<"\tHcalCoarsePedestalClient::analyze()"<<std::endl;
00059   calculateProblems();
00060 } // void HcalCoarsePedestalClient::analyze()
00061 
00062 void HcalCoarsePedestalClient::calculateProblems()
00063 {
00064  if (debug_>2) std::cout <<"\t\tHcalCoarsePedestalClient::calculateProblems()"<<std::endl;
00065   if(!dqmStore_) return;
00066   //int totalevents=0; // events checked on a channel-by-channel basis
00067   int etabins=0, phibins=0, zside=0;
00068   double problemvalue=0;
00069 
00070   if (CoarsePedDiff!=0) CoarsePedDiff->Reset();
00071 
00072   // Clear away old problems
00073   if (ProblemCells!=0)
00074     {
00075       ProblemCells->Reset();
00076       (ProblemCells->getTH2F())->SetMaximum(1.05);
00077       (ProblemCells->getTH2F())->SetMinimum(0.);
00078       (ProblemCells->getTH2F())->SetOption("colz");
00079     }
00080   for  (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00081     {
00082       if (ProblemCellsByDepth->depth[d]!=0) 
00083         {
00084           ProblemCellsByDepth->depth[d]->Reset();
00085           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00086           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00087           (ProblemCellsByDepth->depth[d]->getTH2F())->SetOption("colz");
00088         }
00089     }
00090 
00091   // Get histograms that are used in testing
00092   TH2F* CoarsePedestalsSumByDepth[4];
00093   TH2F* CoarsePedestalsOccByDepth[4];
00094 
00095   std::vector<std::string> name = HcalEtaPhiHistNames();
00096   bool gothistos=true;
00097 
00098   MonitorElement* me;
00099   for (int i=0;i<4;++i)
00100     {
00101       std::string s=subdir_+"CoarsePedestalSumPlots/"+name[i]+"Coarse Pedestal Summed Map";
00102       me=dqmStore_->get(s.c_str());
00103       if (me==0) 
00104         {
00105           gothistos=false;
00106           if (debug_>0) std::cout <<"<HcalCoarsePedestalClient::calculateProblems> Could not get histogram with name "<<s<<std::endl;
00107         }
00108       CoarsePedestalsSumByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, CoarsePedestalsSumByDepth[i], debug_);
00109 
00110       s=subdir_+"CoarsePedestalSumPlots/"+name[i]+"Coarse Pedestal Occupancy Map";
00111       me=dqmStore_->get(s.c_str());
00112       if (me==0) 
00113         {
00114           gothistos=false;
00115           if (debug_>0) std::cout <<"<HcalCoarsePedestalClient::calculateProblems> Could not get histogram with name "<<s<<std::endl;
00116         }
00117       CoarsePedestalsOccByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, CoarsePedestalsOccByDepth[i], debug_);
00118 
00119     } // for (int i=0;i<4;++i)
00120 
00121   if (gothistos==false)
00122     {
00123       if (debug_>0) std::cout <<"<HcalCoarsePedestalClient::calculateProblems> Unable to get all necessary histograms to evaluate problem rate"<<std::endl;
00124       return;
00125     }
00126 
00127   enoughevents_=true;  // Always set this to true, so that pedestal monitoring doesn't hold up 
00128 
00129   int numevents=0;
00130   for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00131     {
00132       if (ProblemCellsByDepth->depth[d]==0) continue;
00133       if (CoarsePedestalsSumByDepth[d]==0 || 
00134           CoarsePedestalsOccByDepth[d]==0 ||
00135           DatabasePedestalsADCByDepth[d]==0) continue;
00136 
00137       if (CoarsePedestalsByDepth->depth[d]!=0)
00138         CoarsePedestalsByDepth->depth[d]->Reset();
00139 
00140       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00141       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00142       for (int eta=0;eta<etabins;++eta)
00143         {
00144           int ieta=CalcIeta(eta,d+1);
00145           if (ieta==-9999) continue;
00146           for (int phi=0;phi<phibins;++phi)
00147             {
00148               if (abs(ieta)>20 && (phi+1)%2==0)
00149                 continue;
00150               if (abs(ieta)>39 && (phi+1)%4!=3)
00151                 continue;
00152               numevents=(int)CoarsePedestalsOccByDepth[d]->GetBinContent(eta+1,phi+1);
00153               if (numevents==0 || numevents<minevents_)
00154                 {
00155                   if (debug_>1)
00156                     std::cout <<"NOT ENOUGH EVENTS for channel ("<<ieta<<", "<<phi+1<<", "<<d+1<<")  numevents = "<<numevents<<"  minevents = "<<minevents_<<std::endl;
00157                   continue;  // insufficient pedestal information available for this channel; continue on?
00158                 }
00159 
00160               problemvalue=1.*CoarsePedestalsSumByDepth[d]->GetBinContent(eta+1,phi+1)/numevents;
00161               CoarsePedestalsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00162               problemvalue=(problemvalue-DatabasePedestalsADCByDepth[d]->GetBinContent(eta+1,phi+1));
00163               CoarsePedDiff->Fill(problemvalue);
00164               problemvalue=fabs(problemvalue);
00165               // Pedestal status is cumulative (DetDiag pedestals perform resets after each calibration cycle, and save each output)
00166               // Either a channels pedestal is 'bad' (outside of allowed range) or 'good' (in range)
00167               problemvalue>ADCDiffThresh_ ? problemvalue=1 : problemvalue=0;
00168               if (debug_>0 && problemvalue==1)
00169                 std::cout <<"<HcalCoarsePedestalClient> Problem found for channel ("<<ieta<<", "<<phi+1<<", "<<d+1<<")"<<std::endl;
00170               zside=0;
00171               if (isHF(eta,d+1)) // shift ieta by 1 for HF
00172                 ieta<0 ? zside = -1 : zside = 1;
00173               // For problem cells that exceed our allowed rate,
00174               // set the values to -1 if the cells are already marked in the status database
00175               if (problemvalue>minerrorrate_)
00176                 {
00177                   HcalSubdetector subdet=HcalEmpty;
00178                   if (isHB(eta,d+1))subdet=HcalBarrel;
00179                   else if (isHE(eta,d+1)) subdet=HcalEndcap;
00180                   else if (isHF(eta,d+1)) subdet=HcalForward;
00181                   else if (isHO(eta,d+1)) subdet=HcalOuter;
00182                   HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00183                   if (badstatusmap.find(hcalid)!=badstatusmap.end())
00184                     problemvalue=999;
00185                 }
00186               ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00187               if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00188             } // loop on phi
00189         } // loop on eta
00190     } // loop on depth
00191 
00192   if (ProblemCells==0)
00193     {
00194       if (debug_>0) std::cout <<"<HcalCoarsePedestalClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00195       return;
00196     }
00197 
00198   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00199   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00200   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00201   for (int eta=0;eta<etabins;++eta)
00202     {
00203       for (int phi=0;phi<phibins;++phi)
00204         {
00205           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00206             ProblemCells->setBinContent(eta+1,phi+1,1.);
00207         }
00208     }
00209   
00210   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00211   FillUnphysicalHEHFBins(ProblemCells);
00212   FillUnphysicalHEHFBins(*CoarsePedestalsByDepth);
00213   return;
00214 }
00215 
00216 
00217 void HcalCoarsePedestalClient::beginJob()
00218 {
00219   dqmStore_ = edm::Service<DQMStore>().operator->();
00220   if (debug_>0) 
00221     {
00222       std::cout <<"<HcalCoarsePedestalClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00223       dqmStore_->showDirStructure();
00224     }
00225 }
00226 
00227 void HcalCoarsePedestalClient::endJob(){}
00228 
00229 void HcalCoarsePedestalClient::beginRun(void)
00230 {
00231   enoughevents_=false;
00232   if (!dqmStore_) 
00233     {
00234       if (debug_>0) std::cout <<"<HcalCoarsePedestalClient::beginRun> dqmStore does not exist!"<<std::endl;
00235       return;
00236     }
00237   dqmStore_->setCurrentFolder(subdir_);
00238   CoarsePedestalsByDepth = new EtaPhiHists();
00239   CoarsePedestalsByDepth->setup(dqmStore_," Coarse Pedestal Map");
00240 
00241   CoarsePedDiff=dqmStore_->book1D("PedRefDiff","(Pedestal-Reference)",200,-10,10);
00242 
00243   problemnames_.clear();
00244   ProblemCells=dqmStore_->book2D(" ProblemCoarsePedestals",
00245                                  " Problem Coarse Pedestal Rate for all HCAL;ieta;iphi",
00246                                  85,-42.5,42.5,
00247                                  72,0.5,72.5);
00248   problemnames_.push_back(ProblemCells->getName());
00249   if (debug_>1)
00250     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00251   dqmStore_->setCurrentFolder(subdir_+"problem_coarsepedestals");
00252   ProblemCellsByDepth = new EtaPhiHists();
00253   ProblemCellsByDepth->setup(dqmStore_," Problem Coarse Pedestal Rate");
00254   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00255     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00256   nevts_=0;
00257   
00258   std::vector<std::string> name = HcalEtaPhiHistNames();
00259   MonitorElement* me;
00260   for (int i=0;i<4;++i)
00261     {
00262       std::string s=prefixME_+"HcalInfo/PedestalsFromCondDB/"+name[i]+"ADC Pedestals From Conditions DB";
00263       me=dqmStore_->get(s.c_str());
00264       if (me==0) 
00265         {
00266           if (debug_>0) std::cout <<"<HcalCoarsePedestalClient::beginRun> Could not get histogram with name "<<s<<std::endl;
00267         }
00268       DatabasePedestalsADCByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, DatabasePedestalsADCByDepth[i], debug_);
00269     }
00270   std::string s=subdir_+"CoarsePedestal_parameters/ADCdiff_Problem_Threshold";
00271   me=dqmStore_->get(s.c_str());
00272   if (me==0)
00273     {
00274       if (debug_>0) 
00275         std::cout <<"<HcalCoarsePedestalClient::beginRun> Could not get value with name "<<s<<std::endl;
00276     }
00277   else 
00278     ADCDiffThresh_=me->getFloatValue();
00279   s=subdir_+"CoarsePedestal_parameters/minEventsNeededForPedestalCalculation";
00280 
00281   me=dqmStore_->get(s.c_str());
00282   int temp = 0;
00283   if (me==0) 
00284     {
00285       if (debug_>0)
00286         {
00287           std::cout <<"<HcalCoarsePedestalClient::beginRun> Could not get value with name "<<s<<"\n\t  Continuing on using default 'minevents' value of "<<minevents_<<std::endl;
00288         }
00289     }
00290   else 
00291     temp=me->getIntValue();
00292   if (temp>minevents_)
00293     {
00294       if (debug_>0)
00295         std::cout <<"<HcalCoarsePedestalClient::beginRun>  Specified client 'minevents' value of "<<minevents_<<"  is less than minimum task 'minevents' value of "<<temp<<"\n\t  Setting client 'minevents' to "<<temp<<std::endl;
00296       minevents_=temp;
00297     }
00298 } // void HcalCoarsePedestalClient::beginRun()
00299 
00300 void HcalCoarsePedestalClient::endRun(void){analyze();}
00301 
00302 void HcalCoarsePedestalClient::setup(void){}
00303 void HcalCoarsePedestalClient::cleanup(void){}
00304 
00305 bool HcalCoarsePedestalClient::hasErrors_Temp(void)
00306 {
00307   if (!ProblemCells)
00308     {
00309       if (debug_>1) std::cout <<"<HcalCoarsePedestalClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00310       return false;
00311     }
00312   int problemcount=0;
00313   int ieta=-9999;
00314 
00315   for (int depth=0;depth<4; ++depth)
00316     {
00317       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00318       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00319       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00320         {
00321           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00322             {
00323               ieta=CalcIeta(hist_eta,depth+1);
00324               if (ieta==-9999) continue;
00325               if (ProblemCellsByDepth->depth[depth]==0)
00326                   continue;
00327               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00328                 ++problemcount;
00329 
00330             } // for (int hist_phi=1;...)
00331         } // for (int hist_eta=1;...)
00332     } // for (int depth=0;...)
00333 
00334   if (problemcount>0) return true;
00335   return false;
00336 }
00337 
00338 bool HcalCoarsePedestalClient::hasWarnings_Temp(void){return false;}
00339 bool HcalCoarsePedestalClient::hasOther_Temp(void){return false;}
00340 bool HcalCoarsePedestalClient::test_enabled(void){return true;}
00341 
00342 
00343 void HcalCoarsePedestalClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00344 {
00345   // client does not alter channel status yet;
00346   // look at dead cell or hot cell clients for example code
00347 } //void HcalCoarsePedestalClient::updateChannelStatus
00348 
00349