CMS 3D CMS Logo

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