CMS 3D CMS Logo

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