CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalTrigPrimClient.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 HcalTrigPrimClient.cc
00013  * 
00014  * $Date: 2010/09/17 13:47:10 $
00015  * $Revision: 1.20 $
00016  * \author J. Temple
00017  * \brief Hcal Trigger Primitive Client class
00018  */
00019 
00020 HcalTrigPrimClient::HcalTrigPrimClient(std::string myname)
00021 {
00022   name_=myname;
00023 }
00024 
00025 HcalTrigPrimClient::HcalTrigPrimClient(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>("TrigPrimFolder","TrigPrimMonitor_Hcal/"); // TrigPrimMonitor
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>("TrigPrim_validHtmlOutput",true);
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040   badChannelStatusMask_   = ps.getUntrackedParameter<int>("TrigPrim_BadChannelStatusMask",
00041                                                           ps.getUntrackedParameter<int>("BadChannelStatusMask",0));
00042   // Set error rate to 1%, not (earlier) value of 0.1% -- Jeff, 11 May 2010
00043   minerrorrate_ = ps.getUntrackedParameter<double>("TrigPrim_minerrorrate",
00044                                                    ps.getUntrackedParameter<double>("minerrorrate",0.01));
00045   minevents_    = ps.getUntrackedParameter<int>("TrigPrim_minevents",
00046                                                 ps.getUntrackedParameter<int>("minevents",1));
00047   ProblemCells=0;
00048   ProblemCellsByDepth=0;
00049 }
00050 
00051 void HcalTrigPrimClient::analyze()
00052 {
00053   if (debug_>2) std::cout <<"\tHcalTrigPrimClient::analyze()"<<std::endl;
00054   calculateProblems();
00055 }
00056 
00057 void HcalTrigPrimClient::calculateProblems()
00058 {
00059  if (debug_>2) std::cout <<"\t\tHcalTrigPrimClient::calculateProblems()"<<std::endl;
00060   if(!dqmStore_) return;
00061   double totalevents=0;
00062   int etabins=0, phibins=0;
00063   double problemvalue=0;
00064   enoughevents_=false;  // assume we lack sufficient events until proven otherwise
00065 
00066   // Clear away old problems
00067   if (ProblemCells!=0)
00068     {
00069       ProblemCells->Reset();
00070       (ProblemCells->getTH2F())->SetMaximum(1.05);
00071       (ProblemCells->getTH2F())->SetMinimum(0.);
00072     }
00073   for  (unsigned int d=0;d<ProblemCellsByDepth->depth.size();++d)
00074     {
00075       if (ProblemCellsByDepth->depth[d]!=0) 
00076         {
00077           ProblemCellsByDepth->depth[d]->Reset();
00078           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMaximum(1.05);
00079           (ProblemCellsByDepth->depth[d]->getTH2F())->SetMinimum(0.);
00080         }
00081     }
00082 
00083   for  (unsigned int d=0;d<ProblemsByDepthZS_->depth.size();++d)
00084     {
00085       if (ProblemsByDepthZS_->depth[d]!=0) 
00086         {
00087           ProblemsByDepthZS_->depth[d]->Reset();
00088           (ProblemsByDepthZS_->depth[d]->getTH2F())->SetMaximum(1.05);
00089           (ProblemsByDepthZS_->depth[d]->getTH2F())->SetMinimum(0.);
00090         }
00091     }
00092 
00093   for  (unsigned int d=0;d<ProblemsByDepthNZS_->depth.size();++d)
00094     {
00095       if (ProblemsByDepthNZS_->depth[d]!=0) 
00096         {
00097           ProblemsByDepthNZS_->depth[d]->Reset();
00098           (ProblemsByDepthNZS_->depth[d]->getTH2F())->SetMaximum(1.05);
00099           (ProblemsByDepthNZS_->depth[d]->getTH2F())->SetMinimum(0.);
00100         }
00101     }
00102 
00103   // Get histograms that are used in testing
00104   // currently none used,
00105 
00106   std::vector<std::string> name = HcalEtaPhiHistNames();
00107 
00108   /*
00109     // This is a sample of how to get a histogram from the task that can then be used for evaluation purposes
00110   */
00111   MonitorElement* me;
00112   TH2F *goodZS=0;
00113   TH2F *badZS=0;
00114   TH2F* goodNZS=0;
00115   TH2F* badNZS=0;
00116 
00117   me=dqmStore_->get(subdir_+"Good TPs_ZS");
00118   if (!me && debug_>0)
00119     std::cout <<"<HcalTrigPrimClient::calculateProblems>  Could not get histogram named '"<<subdir_<<"Good TPs_ZS'"<<std::endl;
00120   else goodZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, goodZS, debug_);
00121 
00122   me=dqmStore_->get(subdir_+"Bad TPs_ZS");
00123   if (!me && debug_>0)
00124     std::cout <<"<HcalTrigPrimClient::calculateProblems>  Could not get histogram named '"<<subdir_<<"Bad TPs_ZS'"<<std::endl;
00125   else badZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, badZS, debug_);
00126 
00127   me=dqmStore_->get(subdir_+"noZS/Good TPs_noZS");
00128   if (!me && debug_>0)
00129     std::cout <<"<HcalTrigPrimClient::calculateProblems>  Could not get histogram named '"<<subdir_<<"noZS/Good TPs_noZS'"<<std::endl;
00130   else goodNZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, goodNZS, debug_);
00131 
00132   me=dqmStore_->get(subdir_+"noZS/Bad TPs_noZS");
00133   if (!me && debug_>0)
00134     std::cout <<"<HcalTrigPrimClient::calculateProblems>  Could not get histogram named '"<<subdir_<<"noZS/Bad TPs_noZS'"<<std::endl;
00135   else badNZS = HcalUtilsClient::getHisto<TH2F*>(me, cloneME_, badNZS, debug_);
00136 
00137   // get bin info from good histograms
00138   if (goodZS!=0)
00139     {
00140       etabins=goodZS->GetNbinsX();
00141       phibins=goodZS->GetNbinsY();
00142       totalevents=goodNZS->GetBinContent(0);
00143     }
00144   else if (goodNZS!=0)
00145     {
00146       etabins=goodNZS->GetNbinsX();
00147       phibins=goodNZS->GetNbinsY();
00148       totalevents=goodNZS->GetBinContent(0);
00149     }
00150 
00151   if (totalevents<minevents_) 
00152     {
00153       enoughevents_=false;
00154       if (debug_>2) std::cout <<"<HcalTrigPrimClient::calculateProblems()>  Not enough events!  events = "<<totalevents<<"  minimum required = "<<minevents_<<std::endl;
00155       return;
00156     }
00157   enoughevents_=true;
00158 
00159   // got good and bad histograms; now let's loop over them
00160 
00161   int ieta=-99, iphi=-99;
00162   int badvalZS=0, goodvalZS=0;
00163   int badvalNZS=0, goodvalNZS=0;
00164   for (int eta=1;eta<=etabins;++eta)
00165     {
00166       ieta=eta-33; // Patrick's eta-phi maps starts at ieta=-32
00167       for (int phi=1;phi<=phibins;++phi)
00168         {
00169           badvalZS=0, goodvalZS=0;
00170           badvalNZS=0, goodvalNZS=0;
00171           iphi=phi;
00172           if (badZS!=0) badvalZS=(int)badZS->GetBinContent(eta,phi);
00173           if (badNZS!=0) badvalNZS=(int)badNZS->GetBinContent(eta,phi);
00174           if (badvalZS+badvalNZS==0) continue;
00175           if (goodZS!=0) goodvalZS=(int)goodZS->GetBinContent(eta,phi);
00176           if (goodNZS!=0) goodvalNZS=(int)goodNZS->GetBinContent(eta,phi);
00177 
00178           if (badvalNZS>0)
00179             {
00180               problemvalue=badvalNZS*1./(badvalNZS+goodvalNZS);
00181               if (abs(ieta)<29) 
00182                 {
00183                   ProblemsByDepthNZS_->depth[0]->Fill(ieta,iphi,problemvalue);
00184                   if (abs(ieta)==28) // TP 28 spans towers 28 and 29
00185                     ProblemsByDepthNZS_->depth[0]->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00186                 }
00187               else // HF
00188                 {
00189                   /* HF TPs:
00190                      TP29 = ieta 29-31
00191                      TP30 = ieta 32-34
00192                      TP31 = ieta 35-37
00193                      TP38 = ieta 38-41
00194                      iphi = 1, 5, ..., with 1 covering iphi=1 and iphi=71, etc.
00195                   */
00196                   int newieta=-99;
00197                   for (int i=0;i<3;++i)
00198                     {
00199                       newieta=i+29+3*(abs(ieta)-29)+1; // shift values by 1 for HF in EtaPhiHistsplot
00200                       if (ieta<0) newieta*=-1;
00201                       ProblemsByDepthNZS_->depth[0]->Fill(newieta,iphi,problemvalue);
00202                       ProblemsByDepthNZS_->depth[0]->Fill(newieta,(iphi-2+72)%72,problemvalue);
00203                     }
00204                   if (abs(ieta)==32)
00205                     {
00206                       ProblemsByDepthNZS_->depth[0]->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00207                       ProblemsByDepthNZS_->depth[0]->Fill(newieta,(iphi-2+72)%72,problemvalue);
00208                     }
00209                 }
00210             } // errors found in NZS;
00211           if (badvalZS>0)
00212             {
00213               problemvalue=badvalZS*1./(badvalZS+goodvalZS);
00214               if (abs(ieta)<29) // Make special case for ieta=16 (HB/HE overlap?)
00215                 {
00216                   ProblemsByDepthZS_->depth[0]->Fill(ieta,iphi,problemvalue);
00217                   if (abs(ieta)==28) // TP 28 spans towers 28 and 29
00218                     ProblemsByDepthZS_->depth[0]->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00219                 }
00220               else
00221                 {
00222                   int newieta=-99;
00223                   for (int i=0;i<3;++i)
00224                         {
00225                           newieta=i+29+3*(abs(ieta)-29)+1; // shift values by 1 for HF in EtaPhiHistsplot
00226                           if (ieta<0) newieta*=-1;
00227                           ProblemsByDepthZS_->depth[0]->Fill(newieta,iphi,problemvalue);
00228                           ProblemsByDepthZS_->depth[0]->Fill(newieta,(iphi-2+72)%72,problemvalue);
00229                         }
00230                   if (abs(ieta)==32)
00231                     {
00232                       ProblemsByDepthZS_->depth[0]->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00233                       ProblemsByDepthZS_->depth[0]->Fill(42*abs(ieta)/ieta,(iphi-2+72)%72,problemvalue);
00234                     }
00235                 }
00236             } // errors found in ZS
00237           if (badvalZS>0 || badvalNZS>0)
00238             {
00239               // Fill overall problem histograms with sum from both ZS & NZS, or ZS only?
00240               //problemvalue=(badvalZS+badvalNZS)*1./(badvalZS+badvalNZS+goodvalZS+goodvalNZS);
00241               
00242               // Update on 8 March -- NZS shows lots of errors; let's not include that in problem cells just yet
00243               if (badvalZS==0) continue;
00244               problemvalue=(badvalZS*1.)/(badvalZS+goodvalZS);
00245               if (abs(ieta)<29) // Make special case for ieta=16 (HB/HE overlap?)
00246                 {
00247                   ProblemCellsByDepth->depth[0]->Fill(ieta,iphi,problemvalue);
00248                   ProblemCells->Fill(ieta,iphi,problemvalue);
00249                   if (abs(ieta)==28) // TP 28 spans towers 28 and 29
00250                     {
00251                       ProblemCellsByDepth->depth[0]->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00252                       ProblemCells->Fill(ieta+abs(ieta)/ieta,iphi,problemvalue);
00253                     }
00254                 }
00255               else
00256                 {
00257                   int newieta=-99;
00258                   int newiphi=(iphi-2+72)%72;  // forward triggers combine two HF cells; *subtract* 2 to the iphi, and allow wraparound
00259                   // FIXME:
00260                   // iphi seems to start at 1 in Patrick's plots, continues mod 4;
00261                   // adjust in far-forward region, where cells start at iphi=3?  Check with Patrick.
00262                   for (int i=0;i<3;++i)
00263                         {
00264                           newieta=i+29+3*(abs(ieta)-29)+1; // shift values by 1 for HF in EtaPhiHistsplot
00265                           if (ieta<0) newieta*=-1;
00266                           ProblemCellsByDepth->depth[0]->Fill(newieta,iphi,problemvalue);
00267                           ProblemCells->Fill(newieta,iphi,problemvalue);
00268                           ProblemCellsByDepth->depth[0]->Fill(newieta,newiphi,problemvalue);
00269                           ProblemCells->Fill(newieta,newiphi,problemvalue);
00270                         }
00271                   if (abs(ieta)==32)
00272                     {
00273                       ProblemCellsByDepth->depth[0]->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00274                       ProblemCells->Fill(42*abs(ieta)/ieta,iphi,problemvalue);
00275                       ProblemCellsByDepth->depth[0]->Fill(42*abs(ieta)/ieta,newiphi,problemvalue);
00276                       ProblemCells->Fill(42*abs(ieta)/ieta,newiphi,problemvalue);
00277                     }
00278                 }
00279             }
00280         }
00281     } // for (int eta=1;eta<etabins;++eta)
00282     
00283 
00284   if (ProblemCells==0)
00285     {
00286       if (debug_>0) std::cout <<"<HcalTrigPrimClient::analyze> ProblemCells histogram does not exist!"<<std::endl;
00287       return;
00288     }
00289 
00290   // Normalization of ProblemCell plot, in the case where there are errors in multiple depths
00291   etabins=(ProblemCells->getTH2F())->GetNbinsX();
00292   phibins=(ProblemCells->getTH2F())->GetNbinsY();
00293   for (int eta=0;eta<etabins;++eta)
00294     {
00295       for (int phi=0;phi<phibins;++phi)
00296         {
00297           if (ProblemCells->getBinContent(eta+1,phi+1)>1. && ProblemCells->getBinContent(eta+1,phi+1)<999)
00298             ProblemCells->setBinContent(eta+1,phi+1,1.);
00299         }
00300     }
00301 
00302   FillUnphysicalHEHFBins(*ProblemCellsByDepth);
00303   FillUnphysicalHEHFBins(*ProblemsByDepthZS_);
00304   FillUnphysicalHEHFBins(*ProblemsByDepthNZS_);
00305   FillUnphysicalHEHFBins(ProblemCells);
00306   return;
00307 }
00308 
00309 void HcalTrigPrimClient::beginJob()
00310 {
00311   dqmStore_ = edm::Service<DQMStore>().operator->();
00312   if (debug_>0) 
00313     {
00314       std::cout <<"<HcalTrigPrimClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00315       dqmStore_->showDirStructure();
00316     }
00317 }
00318 void HcalTrigPrimClient::endJob(){}
00319 
00320 void HcalTrigPrimClient::beginRun(void)
00321 {
00322   enoughevents_=false;
00323   if (!dqmStore_) 
00324     {
00325       if (debug_>0) std::cout <<"<HcalTrigPrimClient::beginRun> dqmStore does not exist!"<<std::endl;
00326       return;
00327     }
00328   dqmStore_->setCurrentFolder(subdir_);
00329   problemnames_.clear();
00330 
00331   // Put the appropriate name of your problem summary here
00332   ProblemCells=dqmStore_->book2D(" ProblemTriggerPrimitives",
00333                                  " Problem Trigger Primitive Rate for all HCAL;ieta;iphi",
00334                                  85,-42.5,42.5,
00335                                  72,0.5,72.5);
00336   problemnames_.push_back(ProblemCells->getName());
00337   if (debug_>1)
00338     std::cout << "Tried to create ProblemCells Monitor Element in directory "<<subdir_<<"  \t  Failed?  "<<(ProblemCells==0)<<std::endl;
00339   dqmStore_->setCurrentFolder(subdir_+"problem_triggerprimitives");
00340   ProblemCellsByDepth = new EtaPhiHists();
00341   ProblemCellsByDepth->setup(dqmStore_," Problem Trigger Primitive Rate");
00342   for (unsigned int i=0; i<ProblemCellsByDepth->depth.size();++i)
00343     problemnames_.push_back(ProblemCellsByDepth->depth[i]->getName());
00344   nevts_=0;
00345 
00346   dqmStore_->setCurrentFolder(subdir_+"problem_ZS");
00347   ProblemsByDepthZS_  = new EtaPhiHists();
00348   ProblemsByDepthZS_->setup(dqmStore_,"ZS Problem Trigger Primitive Rate");
00349   dqmStore_->setCurrentFolder(subdir_+"problem_NZS");
00350   ProblemsByDepthNZS_ = new EtaPhiHists();
00351   ProblemsByDepthNZS_->setup(dqmStore_,"NZS Problem Trigger Primitive Rate");
00352 }
00353 
00354 void HcalTrigPrimClient::endRun(void){analyze();}
00355 
00356 void HcalTrigPrimClient::setup(void){}
00357 void HcalTrigPrimClient::cleanup(void){}
00358 
00359 bool HcalTrigPrimClient::hasErrors_Temp(void)
00360 {
00361   if (!ProblemCells)
00362     {
00363       if (debug_>1) std::cout <<"<HcalTrigPrimClient::hasErrors_Temp>  ProblemCells histogram does not exist!"<<std::endl;
00364       return false;
00365     }
00366   int problemcount=0;
00367   int ieta=-9999;
00368 
00369   for (int depth=0;depth<4; ++depth)
00370     {
00371       int etabins  = (ProblemCells->getTH2F())->GetNbinsX();
00372       int phibins  = (ProblemCells->getTH2F())->GetNbinsY();
00373       for (int hist_eta=0;hist_eta<etabins;++hist_eta)
00374         {
00375           for (int hist_phi=0; hist_phi<phibins;++hist_phi)
00376             {
00377               ieta=CalcIeta(hist_eta,depth+1);
00378               if (ieta==-9999) continue;
00379               if (ProblemCellsByDepth->depth[depth]==0)
00380                   continue;
00381               if (ProblemCellsByDepth->depth[depth]->getBinContent(hist_eta,hist_phi)>minerrorrate_)
00382                 ++problemcount;
00383 
00384             } // for (int hist_phi=1;...)
00385         } // for (int hist_eta=1;...)
00386     } // for (int depth=0;...)
00387 
00388   if (problemcount>0) return true;
00389   return false;
00390 }
00391 
00392 bool HcalTrigPrimClient::hasWarnings_Temp(void){return false;}
00393 bool HcalTrigPrimClient::hasOther_Temp(void){return false;}
00394 bool HcalTrigPrimClient::test_enabled(void){return true;}
00395 
00396 
00397 void HcalTrigPrimClient::updateChannelStatus(std::map<HcalDetId, unsigned int>& myqual)
00398 {
00399   // This gets called by HcalMonitorClient
00400   // trigger primitives don't yet contribute to channel status (though they could...)
00401   // see dead or hot cell code for an example
00402 
00403 } //void HcalTrigPrimClient::updateChannelStatus
00404 
00405