CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/HcalMonitorClient/src/HcalDetDiagTimingClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalDetDiagTimingClient.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 HcalDetDiagTimingClient.cc
00013  * 
00014  * $Date: 2012/06/18 08:23:10 $
00015  * $Revision: 1.6 $
00016  * \author J. Temple
00017  * \brief Hcal DetDiagTiming Client class
00018  */
00019 
00020 HcalDetDiagTimingClient::HcalDetDiagTimingClient(std::string myname)
00021 {
00022   name_=myname;
00023 }
00024 
00025 HcalDetDiagTimingClient::HcalDetDiagTimingClient(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>("DetDiagTimingFolder","DetDiagTimingMonitor_Hcal/"); // DetDiagTiming_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>("DetDiagTiming_validHtmlOutput",true);
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040   badChannelStatusMask_   = ps.getUntrackedParameter<int>("DetDiagTiming_BadChannelStatusMask",
00041                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",0));
00042   
00043   minerrorrate_ = ps.getUntrackedParameter<double>("DetDiagTiming_minerrorrate",
00044                                                    ps.getUntrackedParameter<double>("minerrorrate",0.05));
00045   minevents_    = ps.getUntrackedParameter<int>("DetDiagTiming_minevents",
00046                                                 ps.getUntrackedParameter<int>("minevents",1));
00047   Online_                = ps.getUntrackedParameter<bool>("online",false);
00048 
00049   ProblemCells=0;
00050   ProblemCellsByDepth=0;
00051 }
00052 
00053 void HcalDetDiagTimingClient::analyze()
00054 {
00055   if (debug_>2) std::cout <<"\tHcalDetDiagTimingClient::analyze()"<<std::endl;
00056   calculateProblems();
00057 }
00058 
00059 void HcalDetDiagTimingClient::calculateProblems()
00060 {
00061  if (debug_>2) std::cout <<"\t\tHcalDetDiagTimingClient::calculateProblems()"<<std::endl;
00062   if(!dqmStore_) return;
00063   //double totalevents=0;
00064   int etabins=0, phibins=0, zside=0;
00065   double problemvalue=0;
00066 
00067   // Clear away old problems
00068   if (ProblemCells!=0)
00069     {
00070       ProblemCells->Reset();
00071       (ProblemCells->getTH2F())->SetMaximum(1.05);
00072       (ProblemCells->getTH2F())->SetMinimum(0.);
00073     }
00074   for  (unsigned int d=0;d<ProblemCellsByDepth->depth.size();++d)
00075     {
00076       if (ProblemCellsByDepth->depth[d]!=0) 
00077         {
00078           ProblemCellsByDepth->depth[d]->Reset();
00079           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00080           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00081         }
00082     }
00083   enoughevents_=true;
00084   // Get histograms that are used in testing
00085   // currently none used,
00086 
00087   std::vector<std::string> name = HcalEtaPhiHistNames();
00088 
00089   // This is a sample of how to get a histogram from the task that can then be used for evaluation purposes
00090   /*
00091   TH2F* BadTiming[4];
00092   TH2F* BadEnergy[4];
00093   MonitorElement* me;
00094   for (int i=0;i<4;++i)
00095     {
00096       std::string s=subdir_+name[i]+" Problem Bad Laser Timing";
00097       me=dqmStore_->get(s.c_str());
00098       if (me!=0) BadTiming[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadTiming[i], debug_);
00099       else if (debug_>0) std::cout <<"<HcalDetDiagTimingClient::analyze> could not get histogram '"<<s<<"'"<<std::endl;
00100       s=subdir_+name[i]+" Problem Bad Laser Energy";
00101       me=dqmStore_->get(s.c_str());
00102       if (me!=0) BadEnergy[i]=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, BadEnergy[i], debug_);
00103       else if (debug_>0) std::cout <<"<HcalDetDiagTimingClient::analyze> could not get histogram '"<<s<<"'"<<std::endl;
00104     }      
00105   */
00106 
00107   // Because we're clearing and re-forming the problem cell histogram here, we don't need to do any cute
00108   // setting of the underflow bin to 0, and we can plot results as a raw rate between 0-1.
00109   
00110   for (unsigned int d=0;d<ProblemCellsByDepth->depth.size();++d)
00111     {
00112       if (ProblemCellsByDepth->depth[d]==0) continue;
00113     
00114       //totalevents=DigiPresentByDepth[d]->GetBinContent(0);
00115       //totalevents=0;
00116       // Check underflow bins for events processed
00117       /*
00118       if (BadTiming[d]!=0) totalevents = BadTiming[d]->GetBinContent(0);
00119       else if (BadEnergy[d]!=0) totalevents = BadEnergy[d]->GetBinContent(0);
00120       */
00121       //if (totalevents==0 || totalevents<minevents_) continue;
00122       
00123       //totalevents=1; // temporary value pending removal of histogram normalization from tasks
00124 
00125       etabins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsX();
00126       phibins=(ProblemCellsByDepth->depth[d]->getTH2F())->GetNbinsY();
00127       for (int eta=0;eta<etabins;++eta)
00128         {
00129           int ieta=CalcIeta(eta,d+1);
00130           if (ieta==-9999) continue;
00131           for (int phi=0;phi<phibins;++phi)
00132             {
00133               problemvalue=0;
00134               /*
00135               if (BadTiming[d]!=0) problemvalue += BadTiming[d]->GetBinContent(eta+1,phi+1)*1./totalevents;
00136               else if (BadEnergy[d]!=0) problemvalue += BadEnergy[d]->GetBinContent(eta+1,phi+1)*1./totalevents;
00137               */
00138               if (problemvalue==0) continue;
00139               // problem value is a rate; we can normalize it here
00140               problemvalue = std::min(1.,problemvalue);
00141               
00142               zside=0;
00143               if (isHF(eta,d+1)) // shift ieta by 1 for HF
00144                 ieta<0 ? zside = -1 : zside = 1;
00145 
00146               // For problem cells that exceed our allowed rate,
00147               // set the values to -1 if the cells are already marked in the status database
00148               if (problemvalue>minerrorrate_)
00149                 {
00150                   HcalSubdetector subdet=HcalEmpty;
00151                   if (isHB(eta,d+1))subdet=HcalBarrel;
00152                   else if (isHE(eta,d+1)) subdet=HcalEndcap;
00153                   else if (isHF(eta,d+1)) subdet=HcalForward;
00154                   else if (isHO(eta,d+1)) subdet=HcalOuter;
00155                   HcalDetId hcalid(subdet, ieta, phi+1, (int)(d+1));
00156                   if (badstatusmap.find(hcalid)!=badstatusmap.end())
00157                     problemvalue=999;           
00158                 }
00159 
00160               ProblemCellsByDepth->depth[d]->setBinContent(eta+1,phi+1,problemvalue);
00161               if (ProblemCells!=0) ProblemCells->Fill(ieta+zside,phi+1,problemvalue);
00162             } // loop on phi
00163         } // loop on eta
00164     } // loop on depth
00165 
00166   if (ProblemCells==0)
00167     {
00168       if (debug_>0) std::cout <<"<HcalDetDiagTimingClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00169       return;
00170     }
00171 
00172   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00173   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00174   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00175   for (int eta=0;eta<etabins;++eta)
00176     {
00177       for (int phi=0;phi<phibins;++phi)
00178         {
00179           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00180             ProblemCells->setBinContent(eta+1,phi+1,1.);
00181         }
00182     }
00183 
00184   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00185   FillUnphysicalHEHFBins(ProblemCells);
00186   return;
00187 }
00188 
00189 void HcalDetDiagTimingClient::beginJob()
00190 {
00191   dqmStore_ = edm::Service<DQMStore>().operator->();
00192   if (debug_>0) 
00193     {
00194       std::cout <<"<HcalDetDiagTimingClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00195       dqmStore_->showDirStructure();
00196     }
00197 }
00198 void HcalDetDiagTimingClient::endJob(){}
00199 
00200 void HcalDetDiagTimingClient::beginRun(void)
00201 {
00202   enoughevents_=false;
00203   if (!dqmStore_) 
00204     {
00205       if (debug_>0) std::cout <<"<HcalDetDiagTimingClient::beginRun> dqmStore does not exist!"<<std::endl;
00206       return;
00207     }
00208   dqmStore_->setCurrentFolder(subdir_);
00209   problemnames_.clear();
00210 
00211   // Put the appropriate name of your problem summary here
00212   ProblemCells=dqmStore_->book2D(" ProblemDetDiagTiming",
00213                                  " Problem DetDiagTiming Rate for all HCAL;ieta;iphi",
00214                                  85,-42.5,42.5,
00215                                  72,0.5,72.5);
00216   problemnames_.push_back(ProblemCells->getName());
00217   if (debug_>1)
00218     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00219   dqmStore_->setCurrentFolder(subdir_+"problem_DetDiagTiming");
00220   ProblemCellsByDepth = new EtaPhiHists();
00221   ProblemCellsByDepth->setup(dqmStore_," Problem DetDiagTiming Rate");
00222   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00223     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00224   nevts_=0;
00225 }
00226 
00227 void HcalDetDiagTimingClient::endRun(void){analyze();}
00228 
00229 void HcalDetDiagTimingClient::setup(void){}
00230 void HcalDetDiagTimingClient::cleanup(void){}
00231 
00232 bool HcalDetDiagTimingClient::hasErrors_Temp(void)
00233 {
00234   if (!ProblemCells)
00235     {
00236       if (debug_>1) std::cout <<"<HcalDetDiagTimingClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00237       return false;
00238     }
00239   int problemcount=0;
00240   int ieta=-9999;
00241 
00242   for (int depth=0;depth<4; ++depth)
00243     {
00244       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00245       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00246       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00247         {
00248           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00249             {
00250               ieta=CalcIeta(hist_eta,depth+1);
00251               if (ieta==-9999) continue;
00252               if (ProblemCellsByDepth->depth[depth]==0)
00253                   continue;
00254               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00255                 ++problemcount;
00256 
00257             } // for (int hist_phi=1;...)
00258         } // for (int hist_eta=1;...)
00259     } // for (int depth=0;...)
00260 
00261   if (problemcount>0) return true;
00262   return false;
00263 }
00264 
00265 bool HcalDetDiagTimingClient::hasWarnings_Temp(void){return false;}
00266 bool HcalDetDiagTimingClient::hasOther_Temp(void){return false;}
00267 bool HcalDetDiagTimingClient::test_enabled(void){return true;}
00268 
00269 
00270 void HcalDetDiagTimingClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00271 {
00272   // This gets called by HcalMonitorClient
00273   // trigger primitives don't yet contribute to channel status (though they could...)
00274   // see dead or hot cell code for an example
00275 
00276 } //void HcalDetDiagTimingClient::updateChannelStatus
00277 
00278 HcalDetDiagTimingClient::~HcalDetDiagTimingClient()
00279 {}