CMS 3D CMS Logo

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