CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQMOffline/Trigger/src/EgHLTOfflineSummaryClient.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgHLTOfflineSummaryClient.h"
00002 
00003 
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013 
00014 #include "DQMOffline/Trigger/interface/EgHLTTrigTools.h"
00015 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00016 #include <boost/algorithm/string.hpp>
00017 
00018 EgHLTOfflineSummaryClient::EgHLTOfflineSummaryClient(const edm::ParameterSet& iConfig):
00019   egHLTSumHistName_("egHLTTrigSum"),isSetup_(false)
00020 {  
00021   dirName_=iConfig.getParameter<std::string>("DQMDirName"); //only one chance to get this, if we every have another shot, remember to check isSetup is okay
00022   dbe_ = edm::Service<DQMStore>().operator->();
00023   if (!dbe_) {
00024     edm::LogError("EgHLTOfflineSummaryClient") << "unable to get DQMStore service, no summary histograms will be produced";
00025   }else{
00026     if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00027       dbe_->setVerbose(0);
00028     } 
00029     dbe_->setCurrentFolder(dirName_);
00030   }
00031  
00032   eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames"); 
00033   phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00034   eleHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNamesForSumBit"); 
00035   phoHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNamesForSumBit");
00036   
00037 
00038   filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers"); 
00039   hltTag_ = iConfig.getParameter<std::string>("hltTag");
00040  
00041   usePathNames_ = iConfig.getParameter<bool>("usePathNames");
00042  
00043   
00044   //std::vector<std::string> egHLTSumQTests = iConfig.getParameter<std::vector<std::string> >("egHLTSumQTests");
00045   // splitStringsToPairs_(egHLTSumQTests,egHLTSumHistXBins_);
00046 
00047   fillQTestData_(iConfig,egHLTSumHistXBins_,"egHLTSumQTests");
00048   fillQTestData_(iConfig,eleQTestsForSumBit_,"egHLTEleQTestsForSumBit");
00049   fillQTestData_(iConfig,phoQTestsForSumBit_,"egHLTPhoQTestsForSumBit");
00050 
00051  
00052 
00053   runClientEndLumiBlock_ = iConfig.getParameter<bool>("runClientEndLumiBlock");
00054   runClientEndRun_ = iConfig.getParameter<bool>("runClientEndRun");
00055   runClientEndJob_ = iConfig.getParameter<bool>("runClientEndJob");
00056 
00057 
00058   //egHLTSumHistXBins_.push_back(std::make_pair("Ele Rel Trig Eff",&EgHLTOfflineSummaryClient::eleTrigRelEffQTestResult_));
00059   //egHLTSumHistXBins_.push_back(std::make_pair("Pho Rel Trig Eff",&EgHLTOfflineSummaryClient::phoTrigRelEffQTestResult_));
00060   //egHLTSumHistXBins_.push_back(std::make_pair("Ele T&P Trig Eff",&EgHLTOfflineSummaryClient::eleTrigTPEffQTestResult_));
00061   //egHLTSumHistXBins_.push_back(std::make_pair("Triggered Ele",&EgHLTOfflineSummaryClient::trigEleQTestResult_));
00062   //egHLTSumHistXBins_.push_back(std::make_pair("Triggered Pho",&EgHLTOfflineSummaryClient::trigPhoQTestResult_)); 
00063 }
00064 
00065 
00066 EgHLTOfflineSummaryClient::~EgHLTOfflineSummaryClient()
00067 { 
00068  
00069 }
00070 
00071 void EgHLTOfflineSummaryClient::beginJob()
00072 {
00073  
00074 
00075 }
00076 
00077 void EgHLTOfflineSummaryClient::endJob() 
00078 {
00079   if(runClientEndJob_) runClient_();
00080 }
00081 
00082 void EgHLTOfflineSummaryClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00083 {
00084   if(!isSetup_){
00085     bool changed;
00086     HLTConfigProvider hltConfig;
00087     hltConfig.init(run,c,hltTag_,changed);
00088     if(filterInactiveTriggers_){
00089       std::vector<std::string> activeFilters;
00090       
00091       egHLT::trigTools::getActiveFilters(hltConfig,activeFilters);     
00092       
00093       egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeFilters);
00094       egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNames_,activeFilters);
00095       egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNamesForSumBit_,activeFilters);
00096       egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNamesForSumBit_,activeFilters); 
00097       
00098     }
00099     getEgHLTFiltersToMon_(egHLTFiltersToMon_);
00100      
00101     if(usePathNames_) egHLT::trigTools::translateFiltersToPathNames(hltConfig,egHLTFiltersToMon_,egHLTFiltersToMonPaths_);
00102     isSetup_=true;
00103   }
00104 }
00105 
00106 
00107 void EgHLTOfflineSummaryClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00108 {
00109   if(runClientEndRun_) runClient_();
00110 }
00111 
00112 //dummy analysis function
00113 void EgHLTOfflineSummaryClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00114 {
00115   
00116 }
00117 
00118 void EgHLTOfflineSummaryClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00119 { 
00120  
00121   if(runClientEndLumiBlock_)  runClient_();
00122 }
00123 
00124 void EgHLTOfflineSummaryClient::runClient_()
00125 {
00126  
00127   MonitorElement* egHLTSumME = getEgHLTSumHist_();
00128 
00129   for(size_t filterNr=0;filterNr<egHLTFiltersToMon_.size();filterNr++){
00130     for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00131       //egHLTSumHist->setBinContent(xBinNr+1,filterNr+1,(*egHLTSumHistXBins_[xBinNr].second)(egHLTFiltersToMon_[filterNr].c_str()));
00132       egHLTSumME->setBinContent(xBinNr+1,filterNr+1,
00133                                 getQTestResults_(egHLTFiltersToMon_[filterNr],egHLTSumHistXBins_[xBinNr].qTestPatterns)); 
00134     }
00135   }
00136 
00137   MonitorElement* hltEleSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Electron");
00138   MonitorElement* hltPhoSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Photon");
00139   dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContents/");
00140   if(hltEleSumBit==NULL) hltEleSumBit = dbe_->bookFloat("HLT_Electron");
00141   if(hltPhoSumBit==NULL) hltPhoSumBit = dbe_->bookFloat("HLT_Photon");
00142 
00143   
00144   float eleSumBit=1.;
00145   for(size_t filterNr=0;filterNr<eleHLTFilterNamesForSumBit_.size() && eleSumBit==1;filterNr++){ //breaks as soon as a test fails
00146     for(size_t testNr=0;testNr<eleQTestsForSumBit_.size() && eleSumBit==1;testNr++){
00147       if(getQTestResults_(eleHLTFilterNamesForSumBit_[filterNr],eleQTestsForSumBit_[testNr].qTestPatterns)==0) eleSumBit=0;
00148       
00149     }
00150   }
00151   hltEleSumBit->Fill(eleSumBit);
00152   
00153   float phoSumBit=1.;
00154   for(size_t filterNr=0;filterNr<phoHLTFilterNamesForSumBit_.size() && phoSumBit==1;filterNr++){ //breaks as soon as a test fails
00155     for(size_t testNr=0;testNr<phoQTestsForSumBit_.size() && phoSumBit==1;testNr++){
00156       if(getQTestResults_(phoHLTFilterNamesForSumBit_[filterNr],phoQTestsForSumBit_[testNr].qTestPatterns)==0) phoSumBit=0;
00157     }
00158   }
00159   hltPhoSumBit->Fill(phoSumBit);
00160   
00161   
00162    
00163 }
00164 void EgHLTOfflineSummaryClient::splitStringsToPairs_(const std::vector<std::string>& stringsToSplit,std::vector<std::pair<std::string,std::string> >& splitStrings)
00165 {
00166   splitStrings.clear();
00167   splitStrings.reserve(stringsToSplit.size());
00168   for(size_t stringNr=0;stringNr<stringsToSplit.size();stringNr++){
00169     std::vector<std::string> tempSplitStrings;
00170     boost::split(tempSplitStrings,stringsToSplit[stringNr],boost::is_any_of(std::string(":")));
00171     if(tempSplitStrings.size()==2){
00172       splitStrings.push_back(std::make_pair(tempSplitStrings[0],tempSplitStrings[1]));
00173     }else{
00174       edm::LogWarning("EgHLTOfflineSummaryClient") <<" Error : entry "<<stringsToSplit[stringNr]<<" is not of form A:B, ignoring (ie this quailty test isnt being included in the sumamry hist) ";
00175     }
00176   }
00177 }
00178 
00179 
00180 
00181 MonitorElement* EgHLTOfflineSummaryClient::getEgHLTSumHist_()
00182 {
00183   MonitorElement* egHLTSumHist = dbe_->get(dirName_+"/"+egHLTSumHistName_);
00184   if(egHLTSumHist==NULL){
00185     TH2F* hist = new TH2F(egHLTSumHistName_.c_str(),"E/g HLT Offline Summary",egHLTSumHistXBins_.size(),0.,1.,egHLTFiltersToMon_.size(),0.,1.);
00186     for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00187       hist->GetXaxis()->SetBinLabel(xBinNr+1,egHLTSumHistXBins_[xBinNr].name.c_str());
00188     }
00189     
00190     for(size_t yBinNr=0;yBinNr<egHLTFiltersToMon_.size();yBinNr++){
00191       if(usePathNames_ && egHLTFiltersToMonPaths_.size()==egHLTFiltersToMon_.size()){
00192         hist->GetYaxis()->SetBinLabel(yBinNr+1,egHLTFiltersToMonPaths_[yBinNr].c_str());
00193       }else{
00194         hist->GetYaxis()->SetBinLabel(yBinNr+1,egHLTFiltersToMon_[yBinNr].c_str());
00195       }
00196     }
00197     for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00198       for(size_t yBinNr=0;yBinNr<egHLTFiltersToMon_.size();yBinNr++){
00199         hist->SetBinContent(xBinNr+1,yBinNr+1,-2);
00200       }
00201     }
00202  
00203     dbe_->setCurrentFolder(dirName_);
00204     egHLTSumHist = dbe_->book2D(egHLTSumHistName_,hist);
00205   }
00206   return egHLTSumHist;
00207 
00208 }
00209 
00210 //this function puts every e/g trigger monitored in a std::vector
00211 //this is *very* similar to EgHLTOfflineSource::getHLTFilterNamesUsed but 
00212 //it differs in the fact it only gets the E/g primary triggers not the backups
00213 //due to the design, to ensure we get every filter, filters will be inserted multiple times
00214 //eg electron filters will contain photon triggers which are also in the photon filters
00215 //but only want one copy in the vector
00216 //this function is intended to be called once per job so some inefficiency can can be tolerated
00217 //therefore we will use a std::set to ensure ensure that each filtername is only inserted once
00218 //and then convert to a std::vector
00219 void EgHLTOfflineSummaryClient::getEgHLTFiltersToMon_(std::vector<std::string>& filterNames)const
00220 { 
00221   std::set<std::string> filterNameSet;
00222   for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
00223   for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
00224  
00225   //right all the triggers are inserted once and only once in the set, convert to vector
00226   //very lazy, create a new vector so can use the constructor and then use swap to transfer
00227   std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
00228 }
00229 
00230 //only returns 0 or 1, 0 is bad, one is good and if the test is not found defaults to good
00231 //(this is because its a dumb algorithm, photon tests are run for electron triggers which unsurprisingly are not found)
00232 int EgHLTOfflineSummaryClient::getQTestResults_(const std::string& filterName,const std::vector<std::string>& patterns)const
00233 {
00234   int nrFail =0;
00235   int nrQTests=0;
00236   for(size_t patternNr=0;patternNr<patterns.size();patternNr++){
00237     std::vector<MonitorElement*> monElems = dbe_->getMatchingContents(dirName_+"/"+filterName+patterns[patternNr]);
00238     // std::cout <<"mon elem "<<dirName_+"/"+filterName+patterns[patternNr]<<"nr monElems "<<monElems.size()<<std::endl;
00239     for(size_t monElemNr=0;monElemNr<monElems.size();monElemNr++){
00240      
00241       std::vector<QReport*> qTests = monElems[monElemNr]->getQReports();
00242       nrQTests+=qTests.size();
00243       //  std::cout <<monElems[monElemNr]->getName()<<" "<<monElems[monElemNr]->hasError()<<" nr test "<<qTests.size()<<std::endl;
00244       if(monElems[monElemNr]->hasError()) nrFail++;
00245     }
00246   }
00247   if(nrQTests==0) return -1;
00248   else if(nrFail==0) return 1;
00249   else return 0;
00250 }
00251 
00252 
00253 void EgHLTOfflineSummaryClient::fillQTestData_(const edm::ParameterSet& iConfig,std::vector<SumHistBinData>& qTests,const std::string& label)
00254 {
00255   std::vector<edm::ParameterSet> qTestPara = iConfig.getParameter<std::vector<edm::ParameterSet> >(label);
00256   qTests.resize(qTestPara.size());
00257   for(size_t testNr=0;testNr<qTestPara.size();testNr++){
00258     qTests[testNr].name = qTestPara[testNr].getParameter<std::string>("name");
00259     qTests[testNr].qTestPatterns = qTestPara[testNr].getParameter<std::vector<std::string> >("qTestsToCheck"); 
00260   }
00261 }
00262 
00263 
00264 // int EgHLTOfflineSummaryClient::eleTrigRelEffQTestResult_(const std::string& filterName)const
00265 // {
00266  
00267 
00268 // }
00269 
00270 // int EgHLTOfflineSummaryClient::phoTrigRelEffQTestResult_(const std::string& filterName)const
00271 // {
00272   
00273 // }
00274 
00275 // int EgHLTOfflineSummaryClient::eleTrigTPEffQTestResult_(const std::string& filterName)const
00276 // {
00277   
00278 // }
00279 
00280 // int EgHLTOfflineSummaryClient::trigEleQTestResult_(const std::string& filterName)const
00281 // {
00282   
00283 // }
00284 
00285 // int EgHLTOfflineSummaryClient::trigPhoQTestResult_(const std::string& filterName)const
00286 // {
00287   
00288 // }