CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DQM/HcalMonitorClient/src/HcalDetDiagNoiseMonitorClient.cc

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