CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/HcalMonitorClient/src/HcalBeamClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalBeamClient.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 HcalBeamClient.cc
00013  * 
00014  * $Date: 2011/04/27 12:26:10 $
00015  * $Revision: 1.19 $
00016  * \author J. Temple
00017  * \brief Hcal Beam Monitor Client class
00018  */
00019 
00020 HcalBeamClient::HcalBeamClient(std::string myname)
00021 {
00022   name_=myname;
00023 }
00024 
00025 HcalBeamClient::HcalBeamClient(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>("BeamFolder","BeamMonitor_Hcal/"); // BeamMonitor_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>("Beam_validHtmlOutput",true);
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040   // known hot/dead channels blacked out on plot
00041   badChannelStatusMask_   = ps.getUntrackedParameter<int>("Beam_BadChannelStatusMask",
00042                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask", 
00043                                                                                         ((1<<HcalChannelStatus::HcalCellDead)||
00044                                                                                          (1<<HcalChannelStatus::HcalCellHot))
00045                                                                                         ));
00046                                                           
00047   minerrorrate_ = ps.getUntrackedParameter<double>("Beam_minerrorrate",
00048                                                    ps.getUntrackedParameter<double>("minerrorrate",0.05));
00049   minevents_ = ps.getUntrackedParameter<int>("Beam_minLS",1);
00050   // minevents_    = ps.getUntrackedParameter<int>("Beam_minevents",
00051   //                                            ps.getUntrackedParameter<int>("minevents",1));
00052   Online_                = ps.getUntrackedParameter<bool>("online",false);
00053 
00054   ProblemCells=0;
00055   ProblemCellsByDepth=0;
00056 }
00057 
00058 void HcalBeamClient::analyze()
00059 {
00060   if (debug_>2) std::cout <<"\tHcalBeamClient::analyze()"<<std::endl;
00061   enoughevents_=false;
00062   calculateProblems();
00063 }
00064 
00065 void HcalBeamClient::calculateProblems()
00066 {
00067   if (debug_>2) std::cout <<"\t\tHcalBeamClient::calculateProblems()"<<std::endl;
00068   if(!dqmStore_) return;
00069   double totalLumiBlocks=0;
00070   // reminder:: lumi histograms work a bit differently, counting total number of lumi blocks, not total number of events
00071   int etabins=0, phibins=0, zside=0;
00072   double problemvalue=0;
00073 
00074   // Clear away old problems
00075   if (ProblemCells!=0)
00076     {
00077       ProblemCells->Reset();
00078       (ProblemCells->getTH2F())->SetMaximum(1.05);
00079       (ProblemCells->getTH2F())->SetMinimum(0.);
00080     }
00081   for  (unsigned int d=0;ProblemCellsByDepth!=0 && d<ProblemCellsByDepth->depth.size();++d)
00082     {
00083       if (ProblemCellsByDepth->depth[d]!=0) 
00084         {
00085           ProblemCellsByDepth->depth[d]->Reset();
00086           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00087           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00088         }
00089     }
00090 
00091   // Get histograms that are used in testing
00092   // currently none used,
00093 
00094   // get the dead and hot cell lumi histograms
00095   TH2F* dead = 0;
00096   TH2F* hot  = 0;
00097   MonitorElement* me;
00098   me=dqmStore_->get(subdir_+"Lumi/HFlumi_total_deadcells");
00099   if (me!=0)
00100     dead=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,dead,debug_);
00101   else if (debug_>0) std::cout <<" <HcalBeamClient::calculateProblems> Unable to get dead cell plot 'HFlumi_total_deadcells"<<std::endl;
00102   me=dqmStore_->get(subdir_+"Lumi/HFlumi_total_hotcells");
00103   if (me!=0)
00104     hot=HcalUtilsClient::getHisto<TH2F*>(me, cloneME_,dead,debug_);
00105   else if (debug_>0) std::cout <<" <HcalBeamClient::calculateProblems> Unable to get hot cell plot 'HFlumi_total_hotcells"<<std::endl;
00106   int myieta=0;
00107   int mydepth=0;
00108   int myiphi=0;
00109 
00110   enoughevents_=true; // beam client works a little differently, counting only lumi blocks that have enough events to process.  For this reason, let client continue running regardless of lumi blocks processed
00111 
00112   if (dead!=0 || hot!=0)
00113     {
00114       if (dead!=0) 
00115         {
00116           totalLumiBlocks=dead->GetBinContent(-1,-1);
00117           etabins=dead->GetNbinsX();
00118           phibins=dead->GetNbinsY();
00119         }
00120       else 
00121         {
00122           totalLumiBlocks=hot->GetBinContent(-1,-1);
00123           etabins=hot->GetNbinsX();
00124           phibins=hot->GetNbinsY();
00125         }
00126       if (totalLumiBlocks<minevents_ || totalLumiBlocks==0)
00127         return;
00128       for (int i=0;i<etabins;++i)
00129         {
00130           i<=3 ? myieta = i-36 : myieta=i+29; // separate HFM, HFP
00131           if (abs(myieta)==33 || abs(myieta)==34)
00132             mydepth=1;
00133           else if (abs(myieta)==35 || abs(myieta)==36)
00134             mydepth=2;
00135           for (int j=0;j<phibins;++j)
00136             {
00137               problemvalue=0;
00138               myiphi=2*j+1; // lumi HF histograms only have 36 bins
00139               if (dead!=0 && dead->GetBinContent(i+1,j+1)*1./totalLumiBlocks>minerrorrate_)
00140                 {
00141                   problemvalue+=dead->GetBinContent(i+1,j+1)*1./totalLumiBlocks;
00142                   if (debug_>1) std::cout <<"<HcalBeamClient::calculateProblem>  Dead cell found at ieta = "<<myieta<<" iphi = "<<myiphi<<"  depth = "<<mydepth<<std::endl;
00143                 }
00144               if (hot!=0 &&  hot->GetBinContent(i+1,j+1)*1./totalLumiBlocks>minerrorrate_)
00145                 {
00146                   problemvalue+=hot->GetBinContent(i+1,j+1)*1./totalLumiBlocks;
00147                   if (debug_>1) std::cout <<"<HcalBeamClient::calculateProblem>  hot cell found at ieta = "<<myieta<<" iphi = "<<myiphi<<"  depth = "<<mydepth<<std::endl;
00148                 }
00149               if (problemvalue==0) continue;
00150 
00151               // Search for known bad problems in channel status db
00152               HcalDetId hcalid(HcalForward, myieta, myiphi, mydepth);
00153               if (badstatusmap.find(hcalid)!=badstatusmap.end())
00154                 problemvalue=999;       
00155               myieta<0 ?  zside=-1 : zside=1;
00156               ProblemCellsByDepth->depth[mydepth-1]->Fill(myieta+zside,myiphi,problemvalue);
00157               if (ProblemCells!=0) ProblemCells->Fill(myieta+zside,myiphi,problemvalue);
00158             }
00159         }
00160     }
00161 
00162 
00163   if (ProblemCells==0)
00164     {
00165       if (debug_>0) std::cout <<"<HcalBeamClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00166       return;
00167     }
00168 
00169   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00170   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00171   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00172   for (int eta=0;eta<etabins;++eta)
00173     {
00174       for (int phi=0;phi<phibins;++phi)
00175         {
00176           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00177             ProblemCells->setBinContent(eta+1,phi+1,1.);
00178         }
00179     }
00180   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00181   FillUnphysicalHEHFBins(ProblemCells);
00182   return;
00183 }
00184 
00185 void HcalBeamClient::beginJob()
00186 {
00187   dqmStore_ = edm::Service<DQMStore>().operator->();
00188   if (debug_>0) 
00189     {
00190       std::cout <<"<HcalBeamClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00191       dqmStore_->showDirStructure();
00192     }
00193 }
00194 void HcalBeamClient::endJob(){}
00195 
00196 void HcalBeamClient::beginRun(void)
00197 {
00198   enoughevents_=false;
00199   if (!dqmStore_) 
00200     {
00201       if (debug_>0) std::cout <<"<HcalBeamClient::beginRun> dqmStore does not exist!"<<std::endl;
00202       return;
00203     }
00204   dqmStore_->setCurrentFolder(subdir_);
00205   problemnames_.clear();
00206 
00207   // Put the appropriate name of your problem summary here
00208   if (ProblemCells==0)
00209     ProblemCells=dqmStore_->book2D(" Problem BeamMonitor",
00210                                    " Problem Beam Monitor Rate for all HCAL;ieta;iphi",
00211                                    85,-42.5,42.5,
00212                                    72,0.5,72.5);
00213   problemnames_.push_back(ProblemCells->getName());
00214   if (debug_>1)
00215     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00216   dqmStore_->setCurrentFolder(subdir_+"problem_beammonitor");
00217   nevts_=0;
00218   if (ProblemCellsByDepth!=0) return; // histograms already set up
00219   ProblemCellsByDepth = new EtaPhiHists();
00220   ProblemCellsByDepth->setup(dqmStore_," Problem BeamMonitor Rate");
00221   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00222     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00223 }
00224 
00225 void HcalBeamClient::endRun(void){analyze();}
00226 
00227 void HcalBeamClient::setup(void){}
00228 void HcalBeamClient::cleanup(void){}
00229 
00230 bool HcalBeamClient::hasErrors_Temp(void)
00231 {
00232   if (!ProblemCells)
00233     {
00234       if (debug_>1) std::cout <<"<HcalBeamClient::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 HcalBeamClient::hasWarnings_Temp(void){return false;}
00264 bool HcalBeamClient::hasOther_Temp(void){return false;}
00265 bool HcalBeamClient::test_enabled(void){return true;}
00266 
00267 
00268 void HcalBeamClient::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 HcalBeamClient::updateChannelStatus
00275 
00276