CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/HcalMonitorClient/src/HcalHotCellClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalHotCellClient.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 HcalHotCellClient.cc
00013  * 
00014  * $Date: 2010/11/17 19:17:42 $
00015  * $Revision: 1.76 $
00016  * \author J. Temple
00017  * \brief Hot Cell Client class
00018  */
00019  
00020 HcalHotCellClient::HcalHotCellClient(std::string myname)
00021 {
00022   name_=myname;
00023 }
00024 
00025 HcalHotCellClient::HcalHotCellClient(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>("HotCellFolder","HotCellMonitor_Hcal/"); // HotCellMonitor_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>("HotCell_validHtmlOutput",true);
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040   badChannelStatusMask_   = ps.getUntrackedParameter<int>("HotCell_BadChannelStatusMask",
00041                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",
00042                                                                                         (1<<HcalChannelStatus::HcalCellHot))); // identify channel status values to mask
00043 
00044   minerrorrate_ = ps.getUntrackedParameter<double>("HotCell_minerrorrate",
00045                                                    ps.getUntrackedParameter<double>("minerrorrate",0.25));
00046   minevents_    = ps.getUntrackedParameter<int>("HotCell_minevents",
00047                                                 ps.getUntrackedParameter<int>("minevents",100));
00048   ProblemCellsByDepth=0;
00049   ProblemCells=0;
00050 }
00051 
00052 void HcalHotCellClient::analyze()
00053 {
00054   if (debug_>2) std::cout <<"\tHcalHotCellClient::analyze()"<<std::endl;
00055   calculateProblems();
00056 }
00057 
00058 void HcalHotCellClient::calculateProblems()
00059 {
00060   if (debug_>2) std::cout <<"\t\tHcalHotCellClient::calculateProblems()"<<std::endl;
00061   if(!dqmStore_) return;
00062   double totalevents=0;
00063   int etabins=0, phibins=0, zside=0;
00064   double problemvalue=0;
00065 
00066   // Clear away old problems
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;ProblemCellsByDepth!=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   // Get histograms that are used in testing
00084   TH2F* HotAboveThresholdByDepth[4];
00085   TH2F* HotAlwaysAboveThresholdByDepth[4];
00086   TH2F* HotAboveETThresholdByDepth[4];
00087   TH2F* HotAlwaysAboveETThresholdByDepth[4];
00088   TH2F* HotNeighborsByDepth[4];
00089 
00090   std::vector<std::string> name = HcalEtaPhiHistNames();
00091 
00092   bool neighbortest=false;
00093 
00094   MonitorElement* me;
00095   for (int i=0;i<4;++i)
00096     {
00097       // Assume histograms aren't found by default
00098       HotAboveThresholdByDepth[i]=0;
00099       HotAlwaysAboveThresholdByDepth[i]=0;
00100       HotAboveETThresholdByDepth[i]=0;
00101       HotAlwaysAboveETThresholdByDepth[i]=0;
00102       HotNeighborsByDepth[i]=0;
00103 
00104       std::string s=subdir_+"hot_rechit_above_threshold/"+name[i]+"Hot Cells Above ET Threshold";
00105       me=dqmStore_->get(s.c_str());
00106       if (me!=0)HotAboveETThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAboveETThresholdByDepth[i], debug_);
00107 
00108       s=subdir_+"hot_rechit_always_above_threshold/"+name[i]+"Hot Cells Persistently Above ET Threshold";
00109       me=dqmStore_->get(s.c_str());
00110       if (me!=0)HotAlwaysAboveETThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAlwaysAboveETThresholdByDepth[i], debug_);
00111 
00112       s=subdir_+"hot_rechit_above_threshold/"+name[i]+"Hot Cells Above Energy Threshold";
00113       me=dqmStore_->get(s.c_str());
00114       if (me!=0)HotAboveThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAboveThresholdByDepth[i], debug_);
00115 
00116       s=subdir_+"hot_rechit_always_above_threshold/"+name[i]+"Hot Cells Persistently Above Energy Threshold";
00117       me=dqmStore_->get(s.c_str());
00118       if (me!=0)HotAlwaysAboveThresholdByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotAlwaysAboveThresholdByDepth[i], debug_);
00119 
00120       s=subdir_+"hot_neighbortest/"+name[i]+"Hot Cells Failing Neighbor Test";
00121       me=dqmStore_->get(s.c_str());
00122       if (me!=0)HotNeighborsByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, HotNeighborsByDepth[i], debug_);
00123       s=subdir_+"hot_neighbortest/NeighborTestEnabled";
00124       me=dqmStore_->get(s.c_str());
00125       if (me!=0 && me->getIntValue()==1)
00126         neighbortest=true;
00127     }
00128 
00129 
00130   // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
00131   // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
00132 
00133   for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00134     {
00135       if (ProblemCellsByDepth->depth[d]==0) continue;
00136 
00137       if (HotAboveETThresholdByDepth[d]) totalevents = std::max(totalevents, HotAboveETThresholdByDepth[d]->GetBinContent(0));
00138       else if (HotAlwaysAboveETThresholdByDepth[d]) totalevents = std::max(totalevents, HotAlwaysAboveETThresholdByDepth[d]->GetBinContent(0));
00139       else if (HotAboveThresholdByDepth[d]) totalevents = std::max(totalevents, HotAboveThresholdByDepth[d]->GetBinContent(0));
00140       else if (HotAlwaysAboveThresholdByDepth[d]) totalevents = std::max(totalevents, HotAlwaysAboveThresholdByDepth[d]->GetBinContent(0));
00141       else if (neighbortest==true && HotNeighborsByDepth[d]) totalevents = std::max(totalevents, HotNeighborsByDepth[d]->GetBinContent(0));
00142       else if (debug_>0) std::cout <<"<HcalHotCellClient::calculateProblems> No evaluation histograms found; no valid hot tests enabled?" << std::endl;
00143       if (totalevents==0 || totalevents<minevents_) continue;
00144       enoughevents_=true; // kind of a hack here
00145       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00146       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00147       problemvalue=0;
00148       for (int eta=0;eta<etabins;++eta)
00149         {
00150           int ieta=CalcIeta(eta,d+1);
00151           if (ieta==-9999) continue;
00152           for (int phi=0;phi<phibins;++phi)
00153             {
00154               problemvalue=0; // problem fraction sums over all three tests
00155               // If cell is never-present in all runs, then problemvalue = event
00156               if (HotAboveETThresholdByDepth[d]!=0)
00157                 problemvalue+=HotAboveETThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
00158               if (HotAboveThresholdByDepth[d]!=0)
00159                 problemvalue+=HotAboveThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
00160               if (HotAlwaysAboveThresholdByDepth[d]!=0)
00161                 problemvalue+=HotAlwaysAboveThresholdByDepth[d]->GetBinContent(eta+1,phi+1);
00162               if (neighbortest==true && HotNeighborsByDepth[d]!=0)
00163                 problemvalue+=HotNeighborsByDepth[d]->GetBinContent(eta+1,phi+1);
00164               if (problemvalue==0) continue;
00165               problemvalue/=totalevents; // problem value is a rate; should be between 0 and 1
00166               problemvalue = std::min(1.,problemvalue);
00167               
00168               zside=0;
00169               if (isHF(eta,d+1)) // shift ieta by 1 for HF
00170                 ieta<0 ? zside = -1 : zside = 1;
00171               
00172               // For problem cells that exceed our allowed rate,
00173               // set the values to -1 if the cells are already marked in the status database
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             } // loop on phi
00188         } // loop on eta
00189     } // loop on depth
00190    
00191   if (ProblemCells==0)
00192     {
00193       if (debug_>0) std::cout <<"<HcalHotCellClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00194       return;
00195     }
00196    
00197   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
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 
00209   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00210   FillUnphysicalHEHFBins(ProblemCells);
00211   return;
00212 }
00213 
00214 
00215 void HcalHotCellClient::beginJob()
00216 {
00217   dqmStore_ = edm::Service<DQMStore>().operator->();
00218   if (debug_>0) 
00219     {
00220       std::cout <<"<HcalHotCellClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00221       dqmStore_->showDirStructure();
00222     }
00223 }
00224 
00225 void HcalHotCellClient::endJob(){}
00226 
00227 void HcalHotCellClient::beginRun(void)
00228 {
00229   enoughevents_=false;
00230   if (!dqmStore_) 
00231     {
00232       if (debug_>0) std::cout <<"<HcalHotCellClient::beginRun> dqmStore does not exist!"<<std::endl;
00233       return;
00234     }
00235   dqmStore_->setCurrentFolder(subdir_);
00236   problemnames_.clear();
00237   ProblemCells=dqmStore_->book2D(" ProblemHotCells",
00238                                  " Problem Hot Cell Rate for all HCAL;ieta;iphi",
00239                                  85,-42.5,42.5,
00240                                  72,0.5,72.5);
00241   problemnames_.push_back(ProblemCells->getName());
00242   if (debug_>1)
00243     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00244   dqmStore_->setCurrentFolder(subdir_+"problem_hotcells");
00245   ProblemCellsByDepth=new EtaPhiHists();
00246   ProblemCellsByDepth->setup(dqmStore_," Problem Hot Cell Rate");
00247   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00248     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00249 
00250   nevts_=0;
00251 }
00252 
00253 void HcalHotCellClient::endRun(void){analyze();}
00254 
00255 void HcalHotCellClient::setup(void){}
00256 void HcalHotCellClient::cleanup(void){}
00257 
00258 bool HcalHotCellClient::hasErrors_Temp(void)
00259 {
00260   if (!ProblemCells)
00261     {
00262       if (debug_>1) std::cout <<"<HcalHotCellClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00263       return false;
00264     }
00265   int problemcount=0;
00266   int ieta=-9999;
00267 
00268   for (int depth=0;depth<4; ++depth)
00269     {
00270       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00271       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00272       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00273         {
00274           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00275             {
00276               ieta=CalcIeta(hist_eta,depth+1);
00277               if (ieta==-9999) continue;
00278               if (ProblemCellsByDepth->depth[depth]==0)
00279                 continue;
00280               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00281                 ++problemcount;
00282             } // for (int hist_phi=1;...)
00283         } // for (int hist_eta=1;...)
00284     } // for (int depth=0;...)
00285 
00286   if (problemcount>0) return true;
00287   return false;
00288 }
00289 
00290 bool HcalHotCellClient::hasWarnings_Temp(void){return false;}
00291 bool HcalHotCellClient::hasOther_Temp(void){return false;}
00292 bool HcalHotCellClient::test_enabled(void){return true;}
00293 
00294 
00295 void HcalHotCellClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00296 {
00297   // This gets called by HcalMonitorClient
00298 
00299   if (nevts_<minevents_) return; // not enough events to make judgment; don't create new status file
00300 
00301   float binval;
00302   int ieta=0;
00303   int iphi=0;
00304   int etabins=0;
00305   int phibins=0;
00306   
00307   int subdet=0;
00308   if (debug_>1)
00309     {
00310       std::cout <<"<HcalHotCellClient>  Summary of Hot Cells in Run: "<<std::endl;
00311       std::cout <<"(Error rate must be >= "<<minerrorrate_*100.<<"% )"<<std::endl;  
00312     }
00313   for (int d=0;d<4;++d)
00314     {
00315       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00316       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00317       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00318         {
00319           ieta=CalcIeta(hist_eta,d+1);
00320           if (ieta==-9999) continue;
00321           for (int hist_phi=0;hist_phi<phibins;++hist_phi)
00322             {
00323               iphi=hist_phi+1;
00324               
00325               // ProblemCells have already been normalized
00326               binval=ProblemCellsByDepth->depth[d]->getBinContent(hist_eta+1,hist_phi+1);
00327               
00328               // Set subdetector labels for output
00329               if (d<2)
00330                 {
00331                   if (isHB(hist_eta,d+1)) 
00332                     subdet=HcalBarrel;
00333                   else if (isHE(hist_eta,d+1)) 
00334                     subdet=HcalEndcap;
00335                   else if (isHF(hist_eta,d+1)) 
00336                     subdet=HcalForward;
00337                 }
00338               else if (d==2) 
00339                 subdet=HcalEndcap;
00340               else if (d==3) 
00341                 subdet=HcalOuter;
00342               // Set correct depth label
00343               
00344               HcalDetId myid((HcalSubdetector)(subdet), ieta, iphi, d+1);
00345               // Need this to keep from flagging non-existent HE/HF cells
00346               if (!validDetId((HcalSubdetector)(subdet), ieta, iphi, d+1))
00347                 continue;
00348               
00349               int hotcell=0;
00350               if (binval>minerrorrate_)
00351                 hotcell=1;
00352               if (hotcell==1 && debug_>0)
00353                 std::cout <<"Hot Cell :  subdetector = "<<subdet<<" (eta,phi,depth) = ("<<ieta<<", "<<iphi<<", "<<d+1<<"):  "<<binval*100.<<"%"<<std::endl;
00354               
00355               // DetID not found in quality list; add it.  (This shouldn't happen!)
00356               if (myqual.find(myid)==myqual.end())
00357                 {
00358                   myqual[myid]=(hotcell<<HcalChannelStatus::HcalCellHot);  // 
00359                 }
00360               else
00361                 {
00362                   int mask=(1<<HcalChannelStatus::HcalCellHot);
00363                   // hot cell found; 'or' the hot cell mask with existing ID
00364                   if (hotcell==1)
00365                     myqual[myid] |=mask;
00366                   // cell is not found, 'and' the inverse of the mask with the existing ID.
00367                   // Does this work correctly?  I think so, but need to verify.
00368                   // Also, do we want to allow the client to turn off hot cell masks, or only add them?
00369                   else
00370                     myqual[myid] &=~mask;
00371                 }
00372             } // for (int hist_phi=1;hist_phi<=phibins;++hist_phi)
00373         } // for (int hist_eta=1;hist_eta<=etabins;++hist_eta)
00374     } // for (int d=0;d<4;++d)
00375 
00376 
00377 } //void HcalHotCellClient::updateChannelStatus
00378 
00379