CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/HcalMonitorClient/src/HcalDeadCellClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalDeadCellClient.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 HcalDeadCellClient.cc
00013  * 
00014  * $Date: 2010/11/17 19:17:42 $
00015  * $Revision: 1.72 $
00016  * \author J. Temple
00017  * \brief Dead Cell Client class
00018  */
00019 
00020 HcalDeadCellClient::HcalDeadCellClient(std::string myname)
00021 {
00022   name_=myname;
00023 }
00024 
00025 HcalDeadCellClient::HcalDeadCellClient(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>("DeadCellFolder","DeadCellMonitor_Hcal/"); // DeadCellMonitor_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>("DeadCell_validHtmlOutput",true);
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040   badChannelStatusMask_   = ps.getUntrackedParameter<int>("DeadCell_BadChannelStatusMask",
00041                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",
00042                                                                                         (1<<HcalChannelStatus::HcalCellDead)));  // identify channel status values to mask
00043   
00044   minerrorrate_ = ps.getUntrackedParameter<double>("DeadCell_minerrorrate",
00045                                                    ps.getUntrackedParameter<double>("minerrorrate",0.25));
00046   minevents_    = ps.getUntrackedParameter<int>("DeadCell_minevents",
00047                                                 ps.getUntrackedParameter<int>("minevents",1000));
00048   ProblemCellsByDepth=0;
00049   ProblemCells=0;
00050 
00051 }
00052 
00053 void HcalDeadCellClient::analyze()
00054 {
00055   if (debug_>2) std::cout <<"\tHcalDeadCellClient::analyze()"<<std::endl;
00056   calculateProblems();
00057 }
00058 
00059 void HcalDeadCellClient::calculateProblems()
00060 {
00061   if (debug_>2) std::cout <<"\t\tHcalDeadCellClient::calculateProblems()"<<std::endl;
00062   if(!dqmStore_) return;
00063 
00064   MonitorElement* temp_present;
00065 
00066   // Don't fill histograms if nothing from Hcal is present
00067   if (HBpresent_!=1)
00068     {
00069       temp_present=dqmStore_->get(prefixME_+"HcalInfo/HBpresent");
00070       if (temp_present!=0)
00071         HBpresent_=temp_present->getIntValue();
00072     }
00073   if (HEpresent_!=1)
00074     {
00075       temp_present=dqmStore_->get(prefixME_+"HcalInfo/HEpresent");
00076       if (temp_present!=0)
00077         HEpresent_=temp_present->getIntValue();
00078     }
00079   if (HOpresent_!=1)
00080     {
00081       temp_present=dqmStore_->get(prefixME_+"HcalInfo/HOpresent");
00082       if (temp_present!=0)
00083         HOpresent_=temp_present->getIntValue();
00084     }
00085   if (HFpresent_!=1)
00086     {
00087       temp_present=dqmStore_->get(prefixME_+"HcalInfo/HFpresent");
00088       if (temp_present!=0)
00089         HFpresent_=temp_present->getIntValue();
00090     }
00091   // Never saw any data from any Hcal FED; don't count as dead.
00092   if (HBpresent_==-1 && HEpresent_==-1 && HOpresent_==-1 && HFpresent_==-1)
00093     return;
00094   double totalevents=0;
00095   int etabins=0, phibins=0, zside=0;
00096   double problemvalue=0;
00097 
00098   // Clear away old problems
00099   if (ProblemCells!=0)
00100     {
00101       ProblemCells->Reset();
00102       (ProblemCells->getTH2F())->SetMaximum(1.05);
00103       (ProblemCells->getTH2F())->SetMinimum(0.);
00104     }
00105   for  (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00106     {
00107       if (ProblemCellsByDepth->depth[d]!=0) 
00108         {
00109           ProblemCellsByDepth->depth[d]->Reset();
00110           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00111           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00112         }
00113     }
00114   
00115   // Get histograms that are used in testing
00116   TH2F* DigiPresentByDepth[4];
00117   TH2F* RecentMissingDigisByDepth[4];
00118   TH2F* RecHitsPresentByDepth[4];
00119   TH2F* RecentMissingRecHitsByDepth[4];
00120 
00121   std::vector<std::string> name = HcalEtaPhiHistNames();
00122 
00123   MonitorElement* me;
00124   for (int i=0;i<4;++i)
00125     {
00126       // Assume that histograms can't be found
00127       DigiPresentByDepth[i]=0;
00128       RecentMissingDigisByDepth[i]=0;
00129       RecHitsPresentByDepth[i]=0;
00130       RecentMissingRecHitsByDepth[i]=0;
00131       
00132       std::string s=subdir_+"dead_digi_never_present/"+name[i]+"Digi Present At Least Once";
00133       me=dqmStore_->get(s.c_str());
00134       if (me!=0) DigiPresentByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, DigiPresentByDepth[i], debug_);
00135       
00136       s=subdir_+"dead_digi_often_missing/"+name[i]+"Dead Cells with No Digis";
00137       me=dqmStore_->get(s.c_str());
00138       if (me!=0) RecentMissingDigisByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecentMissingDigisByDepth[i], debug_);
00139      
00140       s=subdir_+"dead_rechit_never_present/"+name[i]+"RecHit Above Threshold At Least Once";
00141       me=dqmStore_->get(s.c_str());
00142       if (me!=0) RecHitsPresentByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecHitsPresentByDepth[i], debug_);
00143 
00144        s=subdir_+"dead_rechit_often_missing/"+name[i]+"RecHits Failing Energy Threshold Test";
00145       me=dqmStore_->get(s.c_str());
00146       if (me!=0)RecentMissingRecHitsByDepth[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, RecentMissingRecHitsByDepth[i], debug_);
00147 
00148     }
00149 
00150   // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
00151   // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
00152   
00153   for (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00154     {
00155       if (ProblemCellsByDepth->depth[d]==0) continue;
00156 
00157       if (DigiPresentByDepth[d]==0) continue;
00158       // Get number of entries from DigiPresent histogram 
00159       // (need to do this for offline DQM combinations of output)
00160       totalevents=DigiPresentByDepth[d]->GetBinContent(0);
00161       if (totalevents==0 || totalevents<minevents_) continue;
00162       enoughevents_=true; // kind of a hack here
00163       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00164       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00165       problemvalue=0;
00166       for (int eta=0;eta<etabins;++eta)
00167         {
00168           int ieta=CalcIeta(eta,d+1);
00169           if (ieta==-9999) continue;
00170           for (int phi=0;phi<phibins;++phi)
00171             {
00172               problemvalue=0;
00173 
00174               // Never-present histogram is a boolean, with underflow bin = 1 (for each instance)
00175               // Offline DQM adds up never-present histograms from multiple outputs
00176               // For now, we want offline DQM to show LS-based 'occupancies', rather than simple boolean on/off
00177               // May change in the future?
00178               
00179               // If cell is never-present in all runs, then problemvalue = event
00180               if (DigiPresentByDepth[d]!=0 && DigiPresentByDepth[d]->GetBinContent(eta+1,phi+1)==0) 
00181                 problemvalue=totalevents;
00182               // Rec Hit presence test
00183               else if (RecHitsPresentByDepth[d]!=0)
00184                 {
00185                   if (RecHitsPresentByDepth[d]->GetBinContent(eta+1,phi+1)==0)
00186                     problemvalue=totalevents;
00187                   else if (RecHitsPresentByDepth[d]->GetBinContent(eta+1,phi+1)>1)
00188                     RecHitsPresentByDepth[d]->SetBinContent(eta+1,phi+1,1);
00189                 }
00190               else
00191                 {
00192                   if (RecentMissingDigisByDepth[d]!=0)
00193                     problemvalue+=RecentMissingDigisByDepth[d]->GetBinContent(eta+1,phi+1);
00194                   if (RecentMissingRecHitsByDepth[d]!=0)
00195                     problemvalue+=RecentMissingRecHitsByDepth[d]->GetBinContent(eta+1,phi+1);
00196                 }
00197               if (problemvalue==0) continue;
00198               problemvalue/=totalevents; // problem value is a rate; should be between 0 and 1
00199               problemvalue = std::min(1.,problemvalue);
00200               
00201               zside=0;
00202               if (isHF(eta,d+1)) // shift ieta by 1 for HF
00203                 ieta<0 ? zside = -1 : zside = 1;
00204               
00205               // For problem cells that exceed our allowed rate,
00206               // set the values to -1 if the cells are already marked in the status database
00207               if (problemvalue>minerrorrate_)
00208                 {
00209                   HcalSubdetector subdet=HcalEmpty;
00210                   if (isHB(eta,d+1))subdet=HcalBarrel;
00211                   else if (isHE(eta,d+1)) subdet=HcalEndcap;
00212                   else if (isHF(eta,d+1)) subdet=HcalForward;
00213                   else if (isHO(eta,d+1)) subdet=HcalOuter;
00214                   HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00215                   if (badstatusmap.find(hcalid)!=badstatusmap.end())
00216                     problemvalue=999;
00217                 }
00218               ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00219               if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00220               
00221             } // loop on phi
00222         } // loop on eta
00223     } // loop on depth
00224 
00225   if (ProblemCells==0)
00226     {
00227       if (debug_>0) std::cout <<"<HcalDeadCellClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00228       return;
00229     }
00230 
00231   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00232   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00233   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00234   for (int eta=0;eta<etabins;++eta)
00235     {
00236       for (int phi=0;phi<phibins;++phi)
00237         {
00238           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00239             ProblemCells->setBinContent(eta+1,phi+1,1.);
00240         }
00241     }
00242 
00243   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00244   FillUnphysicalHEHFBins(ProblemCells);
00245   return;
00246 }
00247 
00248 void HcalDeadCellClient::beginJob()
00249 {
00250   dqmStore_ = edm::Service<DQMStore>().operator->();
00251   if (debug_>0) 
00252     {
00253       std::cout <<"<HcalDeadCellClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00254       dqmStore_->showDirStructure();
00255     }
00256 }
00257 void HcalDeadCellClient::endJob(){}
00258 
00259 void HcalDeadCellClient::beginRun(void)
00260 {
00261   enoughevents_=false;
00262   HBpresent_=-1;
00263   HEpresent_=-1;
00264   HOpresent_=-1;
00265   HFpresent_=-1;
00266   if (!dqmStore_) 
00267     {
00268       if (debug_>0) std::cout <<"<HcalDeadCellClient::beginRun> dqmStore does not exist!"<<std::endl;
00269       return;
00270     }
00271   dqmStore_->setCurrentFolder(subdir_);
00272   problemnames_.clear();
00273   ProblemCells=dqmStore_->book2D(" ProblemDeadCells",
00274                                  " Problem Dead Cell Rate for all HCAL;ieta;iphi",
00275                                  85,-42.5,42.5,
00276                                  72,0.5,72.5);
00277   problemnames_.push_back(ProblemCells->getName());
00278   if (debug_>1)
00279     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00280   dqmStore_->setCurrentFolder(subdir_+"problem_deadcells");
00281   ProblemCellsByDepth = new EtaPhiHists();
00282   ProblemCellsByDepth->setup(dqmStore_," Problem Dead Cell Rate");
00283   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00284     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00285 
00286   nevts_=0;
00287 }
00288 
00289 void HcalDeadCellClient::endRun(void){analyze();}
00290 
00291 void HcalDeadCellClient::setup(void){}
00292 void HcalDeadCellClient::cleanup(void){}
00293 
00294 bool HcalDeadCellClient::hasErrors_Temp(void)
00295 {
00296   if (!ProblemCells)
00297     {
00298       if (debug_>1) std::cout <<"<HcalDeadCellClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00299       return false;
00300     }
00301   int problemcount=0;
00302   int ieta=-9999;
00303 
00304   for (int depth=0;depth<4; ++depth)
00305     {
00306       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00307       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00308       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00309         {
00310           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00311             {
00312               ieta=CalcIeta(hist_eta,depth+1);
00313               if (ieta==-9999) continue;
00314               if (ProblemCellsByDepth->depth[depth]==0)
00315                 continue;
00316               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00317                 ++problemcount;
00318             } // for (int hist_phi=1;...)
00319         } // for (int hist_eta=1;...)
00320     } // for (int depth=0;...)
00321   
00322   if (problemcount>0) return true;
00323   return false;
00324 }
00325 
00326 bool HcalDeadCellClient::hasWarnings_Temp(void){return false;}
00327 bool HcalDeadCellClient::hasOther_Temp(void){return false;}
00328 bool HcalDeadCellClient::test_enabled(void){return true;}
00329 
00330 
00331 
00332 void HcalDeadCellClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00333 {
00334   // This gets called by HcalMonitorClient
00335 
00336   if (enoughevents_==false) return; // not enough events to make judgment; don't create new status file
00337 
00338   float binval;
00339   int ieta=0;
00340   int iphi=0;
00341   int etabins=0;
00342   int phibins=0;
00343   
00344   int subdet=0;
00345   if (debug_>1)
00346     {
00347       std::cout <<"<HcalDeadCellClient>  Summary of Dead Cells in Run: "<<std::endl;
00348       std::cout <<"(Error rate must be >= "<<minerrorrate_*100.<<"% )"<<std::endl;  
00349     }
00350   for (int d=0;d<4;++d)
00351     {
00352       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00353       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00354       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00355         {
00356           ieta=CalcIeta(hist_eta,d+1);
00357           if (ieta==-9999) continue;
00358           for (int hist_phi=0;hist_phi<phibins;++hist_phi)
00359             {
00360               iphi=hist_phi+1;
00361               
00362               // ProblemCells have already been normalized
00363               binval=ProblemCellsByDepth->depth[d]->getBinContent(hist_eta+1,hist_phi+1);
00364               
00365               // Set subdetector labels for output
00366               if (d<2)
00367                 {
00368                   if (isHB(hist_eta,d+1)) 
00369                     subdet=HcalBarrel;
00370                   else if (isHE(hist_eta,d+1)) 
00371                     subdet=HcalEndcap;
00372                   else if (isHF(hist_eta,d+1)) 
00373                     subdet=HcalForward;
00374                 }
00375               else if (d==2) 
00376                 subdet=HcalEndcap;
00377               else if (d==3) 
00378                 subdet=HcalOuter;
00379               // Set correct depth label
00380               
00381               HcalDetId myid((HcalSubdetector)(subdet), ieta, iphi, d+1);
00382               // Need this to keep from flagging non-existent HE/HF cells
00383               if (!validDetId((HcalSubdetector)(subdet), ieta, iphi, d+1))
00384                 continue;
00385               
00386               int deadcell=0;
00387               if (binval>minerrorrate_)
00388                 deadcell=1;
00389               if (deadcell==1 && debug_>0)
00390                 std::cout <<"Dead Cell :  subdetector = "<<subdet<<" (eta,phi,depth) = ("<<ieta<<", "<<iphi<<", "<<d+1<<"):  "<<binval*100.<<"%"<<std::endl;
00391               
00392               // DetID not found in quality list; add it.  
00393               if (myqual.find(myid)==myqual.end())
00394                 myqual[myid]=(deadcell<<HcalChannelStatus::HcalCellDead);  // deadcell shifted to bit 6
00395               else
00396                 {
00397                   int mask=(1<<HcalChannelStatus::HcalCellDead);
00398                   // dead cell found; 'or' the dead cell mask with existing ID
00399                   if (deadcell==1)
00400                     myqual[myid] |=mask;
00401                   // cell is not found, 'and' the inverse of the mask with the existing ID.
00402                   // Does this work correctly?  I think so, but need to verify.
00403                   // Also, do we want to allow the client to turn off dead cell masks, or only add them?
00404                   else
00405                     myqual[myid] &=~mask;
00406                 }
00407             } // for (int hist_phi=1;hist_phi<=phibins;++hist_phi)
00408         } // for (int hist_eta=1;hist_eta<=etabins;++hist_eta)
00409     } // for (int d=0;d<4;++d)
00410   
00411   
00412 } //void HcalDeadCellClient::updateChannelStatus
00413 
00414