CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQMOffline/Trigger/src/EgHLTOfflineClient.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgHLTOfflineClient.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 
00016 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00017 
00018 #include <boost/algorithm/string.hpp>
00019 
00020 #include "TGraphAsymmErrors.h"
00021 
00022 EgHLTOfflineClient::EgHLTOfflineClient(const edm::ParameterSet& iConfig):dbe_(NULL),isSetup_(false)
00023 {
00024   dbe_ = edm::Service<DQMStore>().operator->(); //only one chance to get this, if we every have another shot, remember to check isSetup is okay
00025   if (!dbe_) {
00026     edm::LogError("EgHLTOfflineClient") << "unable to get DQMStore service, upshot is no client histograms will be made";
00027   }
00028   if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00029     if(dbe_) dbe_->setVerbose(0);
00030   }
00031  
00032 
00033   eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00034   eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
00035   phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00036   phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
00037 
00038   eleN1EffVars_=iConfig.getParameter<std::vector<std::string> >("eleN1EffVars");
00039   eleSingleEffVars_ = iConfig.getParameter<std::vector<std::string> >("eleSingleEffVars");
00040   eleEffTags_ = iConfig.getParameter<std::vector<std::string> >("eleEffTags");
00041   eleTrigTPEffVsVars_ = iConfig.getParameter<std::vector<std::string> >("eleTrigTPEffVsVars");
00042   eleLooseTightTrigEffVsVars_ =  iConfig.getParameter<std::vector<std::string> >("eleLooseTightTrigEffVsVars");
00043 
00044   phoN1EffVars_=iConfig.getParameter<std::vector<std::string> >("phoN1EffVars");
00045   phoSingleEffVars_ = iConfig.getParameter<std::vector<std::string> >("phoSingleEffVars");
00046   phoEffTags_ = iConfig.getParameter<std::vector<std::string> >("phoEffTags");
00047   phoTrigTPEffVsVars_ = iConfig.getParameter<std::vector<std::string> >("phoTrigTPEffVsVars");
00048   phoLooseTightTrigEffVsVars_ =  iConfig.getParameter<std::vector<std::string> >("phoLooseTightTrigEffVsVars");
00049   
00050   runClientEndLumiBlock_ = iConfig.getParameter<bool>("runClientEndLumiBlock");
00051   runClientEndRun_ = iConfig.getParameter<bool>("runClientEndRun");
00052   runClientEndJob_ = iConfig.getParameter<bool>("runClientEndJob");
00053 
00054   
00055 
00056   dirName_=iConfig.getParameter<std::string>("DQMDirName");
00057   if(dbe_) dbe_->setCurrentFolder(dirName_);
00058  
00059 
00060   filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
00061   hltTag_ = iConfig.getParameter<std::string>("hltTag");
00062  
00063 
00064 }
00065 
00066 
00067 EgHLTOfflineClient::~EgHLTOfflineClient()
00068 { 
00069   
00070 }
00071 
00072 void EgHLTOfflineClient::beginJob()
00073 {
00074   
00075 
00076 }
00077 
00078 void EgHLTOfflineClient::endJob() 
00079 {
00080   if(runClientEndJob_) runClient_();
00081 }
00082 
00083 void EgHLTOfflineClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00084 {
00085   if(isSetup_){
00086     if(filterInactiveTriggers_){
00087       HLTConfigProvider hltConfig;
00088       bool changed=false;
00089       hltConfig.init(run,c,hltTag_,changed);
00090       std::vector<std::string> activeFilters;
00091       egHLT::trigTools::getActiveFilters(hltConfig,activeFilters);
00092       
00093       egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeFilters);
00094       egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNames_,activeFilters);
00095       egHLT::trigTools::filterInactiveTightLooseTriggers(eleTightLooseTrigNames_,activeFilters);
00096       egHLT::trigTools::filterInactiveTightLooseTriggers(phoTightLooseTrigNames_,activeFilters);
00097       
00098     }
00099     isSetup_=true;
00100   }
00101 }
00102 
00103 
00104 void EgHLTOfflineClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00105 {
00106   if(runClientEndRun_) runClient_();
00107 }
00108 
00109 //dummy analysis function
00110 void EgHLTOfflineClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00111 {
00112   
00113 }
00114 
00115 void EgHLTOfflineClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00116 { 
00117   if(runClientEndLumiBlock_)  runClient_();
00118 }
00119 
00120 void EgHLTOfflineClient::runClient_()
00121 {
00122   if(!dbe_) return; //we dont have the DQMStore so we cant do anything
00123   dbe_->setCurrentFolder(dirName_+"/Client_Histos");
00124  
00125 
00126   std::vector<std::string> regions;
00127   regions.push_back("eb");
00128   regions.push_back("ee");
00129 
00130   
00131   for(size_t filterNr=0;filterNr<eleHLTFilterNames_.size();filterNr++){
00132     for(size_t regionNr=0;regionNr<regions.size();regionNr++){
00133       for(size_t effNr=0;effNr<eleEffTags_.size();effNr++){
00134         //----Morse----
00135         dbe_->setCurrentFolder(dirName_+"/Client_Histos/"+eleHLTFilterNames_[filterNr]);
00136         //--------------
00137         createN1EffHists(eleHLTFilterNames_[filterNr],eleHLTFilterNames_[filterNr]+"_gsfEle_"+eleEffTags_[effNr],regions[regionNr],eleN1EffVars_);
00138         createSingleEffHists(eleHLTFilterNames_[filterNr],eleHLTFilterNames_[filterNr]+"_gsfEle_"+eleEffTags_[effNr],regions[regionNr],eleSingleEffVars_);
00139         createTrigTagProbeEffHists(eleHLTFilterNames_[filterNr],regions[regionNr],eleTrigTPEffVsVars_,"gsfEle");
00140       }
00141     }
00142   }
00143   //------Morse
00144   //  dbe_->setCurrentFolder(dirName_);
00145   //--------------
00146   
00147   for(size_t filterNr=0;filterNr<phoHLTFilterNames_.size();filterNr++){
00148     for(size_t regionNr=0;regionNr<regions.size();regionNr++){
00149       for(size_t effNr=0;effNr<phoEffTags_.size();effNr++){
00150         //----Morse----
00151         dbe_->setCurrentFolder(dirName_+"/Client_Histos/"+phoHLTFilterNames_[filterNr]);
00152         //createN1EffHists(eleHLTFilterNames_[filterNr]+"_pho_"+phoEffTags_[effNr],regions[regionNr],phoN1EffVars_);
00153         //createSingleEffHists(eleHLTFilterNames_[filterNr]+"_gsfEle_"+phoEffTags_[effNr],regions[regionNr],phoSingleEffVars_);
00154         createN1EffHists(phoHLTFilterNames_[filterNr],phoHLTFilterNames_[filterNr]+"_pho_"+phoEffTags_[effNr],regions[regionNr],phoN1EffVars_);
00155         createSingleEffHists(phoHLTFilterNames_[filterNr],phoHLTFilterNames_[filterNr]+"_pho_"+phoEffTags_[effNr],regions[regionNr],phoSingleEffVars_);
00156         //--------------
00157       }
00158     }
00159   }
00160   //------Morse
00161   //  dbe_->setCurrentFolder(dirName_);
00162   //--------------
00163   for(size_t regionNr=0;regionNr<regions.size();regionNr++){
00164     createLooseTightTrigEff(eleTightLooseTrigNames_,regions[regionNr],eleLooseTightTrigEffVsVars_,"gsfEle");   
00165     createLooseTightTrigEff(eleTightLooseTrigNames_,regions[regionNr],eleLooseTightTrigEffVsVars_,"gsfEle_trigCuts");
00166     createLooseTightTrigEff(phoTightLooseTrigNames_,regions[regionNr],phoLooseTightTrigEffVsVars_,"pho"); 
00167     createLooseTightTrigEff(phoTightLooseTrigNames_,regions[regionNr],phoLooseTightTrigEffVsVars_,"pho_trigCuts");
00168   }
00169   //----Morse-----
00170   dbe_->setCurrentFolder(dirName_);
00171   //----------
00172 }
00173 
00174 void EgHLTOfflineClient::createN1EffHists(const std::string& filterName,const std::string& baseName,const std::string& region,const std::vector<std::string>& varNames)
00175 { 
00176   MonitorElement* numer = dbe_->get(dirName_+"/Source_Histos/"+filterName+"/"+baseName+"_allCuts_"+region);
00177   
00178   for(size_t varNr=0;varNr<varNames.size();varNr++){
00179     MonitorElement* denom = dbe_->get(dirName_+"/Source_Histos/"+filterName+"/"+baseName+"_n1_"+varNames[varNr]+"_"+region);
00180     if(numer!=NULL && denom!=NULL){
00181       std::string effHistName(baseName+"_n1Eff_"+varNames[varNr]+"_"+region);//std::cout<<"N1:  "<<effHistName<<std::endl;
00182       //std::cout<<region<<"  ";
00183       //----Morse-----------
00184       std::string effHistTitle(effHistName);//std::cout<<effHistTitle<<std::endl;
00185       if(region=="eb" || region=="ee"){
00186         if(region=="eb") effHistTitle = "Barrel "+baseName+" N1eff "+varNames[varNr];
00187         if(region=="ee") effHistTitle = "Endcap "+baseName+" N1eff "+varNames[varNr];
00188       }//std::cout<<effHistTitle<<std::endl;
00189       //makeEffMonElemFromPassAndAll(effHistName,numer,denom);
00190       makeEffMonElemFromPassAndAll(filterName,effHistName,effHistTitle,numer,denom);
00191       //---------------------
00192     }
00193   }//end loop over varNames 
00194 }
00195 
00196 void EgHLTOfflineClient::createSingleEffHists(const std::string& filterName,const std::string& baseName,const std::string& region,const std::vector<std::string>& varNames)
00197 { 
00198   MonitorElement* denom = dbe_->get(dirName_+"/Source_Histos/"+filterName+"/"+baseName+"_noCuts_"+region);
00199   
00200   for(size_t varNr=0;varNr<varNames.size();varNr++){
00201     MonitorElement* numer = dbe_->get(dirName_+"/Source_Histos/"+filterName+"/"+baseName+"_single_"+varNames[varNr]+"_"+region);
00202     if(numer!=NULL && denom!=NULL){
00203       std::string effHistName(baseName+"_singleEff_"+varNames[varNr]+"_"+region);//std::cout<<"Si:  "<<effHistName<<std::endl;
00204       //----Morse-----------
00205       std::string effHistTitle(effHistName);//std::cout<<effHistTitle<<std::endl;
00206       if(region=="eb" || region=="ee"){
00207         if(region=="eb") effHistTitle = "Barrel "+baseName+" SingleEff "+varNames[varNr];
00208         if(region=="ee") effHistTitle = "Endcap "+baseName+" SingleEff "+varNames[varNr];
00209       }//std::cout<<effHistTitle<<std::endl;
00210       //makeEffMonElemFromPassAndAll(effHistName,numer,denom);   
00211       makeEffMonElemFromPassAndAll(filterName,effHistName,effHistTitle,numer,denom);   
00212       //--------------------
00213     }
00214   }//end loop over varNames 
00215 }
00216 
00217 void EgHLTOfflineClient::createTrigTagProbeEffHists(const std::string& filterName,const std::string& region,const std::vector<std::string>& vsVarNames,const std::string& objName)
00218 {
00219   for(size_t varNr=0;varNr<vsVarNames.size();varNr++){
00220     std::string allName(dirName_+"/Source_Histos/"+filterName+"/"+filterName+"_trigTagProbe_"+objName+"_all_"+vsVarNames[varNr]+"_"+region);
00221     MonitorElement* all = dbe_->get(allName); 
00222     if(all==NULL){
00223       //edm::LogInfo("EgHLTOfflineClient") <<" couldnt get hist "<<allName;
00224       continue;
00225     }
00226     std::string passName(dirName_+"/Source_Histos/"+filterName+"/"+filterName+"_trigTagProbe_"+objName+"_pass_"+vsVarNames[varNr]+"_"+region);
00227     MonitorElement* pass = dbe_->get(passName); 
00228     if(pass==NULL){
00229       //edm::LogInfo("EgHLTOfflineClient") <<" couldnt get hist "<<passName;
00230       continue;
00231     }
00232     //----Morse-----
00233     std::string effHistTitle(filterName+"_trigTagProbeEff_"+objName+"_vs_"+vsVarNames[varNr]+"_"+region);//std::cout<<effHistTitle<<std::endl;
00234       if(region=="eb" || region=="ee"){
00235         if(region=="eb") effHistTitle = "Barrel "+filterName+"_"+objName+" TrigTagProbeEff vs "+vsVarNames[varNr];
00236         if(region=="ee") effHistTitle = "Endcap "+filterName+"_"+objName+" TrigTagProbeEff vs "+vsVarNames[varNr];
00237       }//std::cout<<effHistTitle<<std::endl;
00238     //------------
00239       makeEffMonElemFromPassAndAll(filterName,filterName+"_trigTagProbeEff_"+objName+"_vs_"+vsVarNames[varNr]+"_"+region,effHistTitle,pass,all);
00240   }//end loop over vsVarNames
00241 }
00242 
00243 
00244 
00245 void EgHLTOfflineClient::createLooseTightTrigEff(const std::vector<std::string>&  tightLooseTrigNames,const std::string& region,const std::vector<std::string>& vsVarNames,const std::string& objName)
00246 {
00247   for(size_t varNr=0;varNr<vsVarNames.size();varNr++){
00248     for(size_t trigNr=0;trigNr<tightLooseTrigNames.size();trigNr++){
00249       std::vector<std::string> splitString;
00250       boost::split(splitString,tightLooseTrigNames[trigNr],boost::is_any_of(std::string(":")));
00251       if(splitString.size()!=2) continue; //format incorrect
00252       const std::string& tightTrig = splitString[0];
00253       const std::string& looseTrig = splitString[1];
00254       MonitorElement* fail = dbe_->get(dirName_+"/Source_Histos/"+tightTrig+"_"+looseTrig+"_"+objName+"_failTrig_"+vsVarNames[varNr]+"_"+region); 
00255       if(fail==NULL){
00256         //edm::LogInfo("EgHLTOfflineClient") <<" couldnt get hist "<<dirName_+"/"+tightTrig+"_"+looseTrig+"_"+objName+"_failTrig_"+vsVarNames[varNr]+"_"+region;
00257 
00258         continue;
00259       }
00260 
00261       MonitorElement* pass = dbe_->get(dirName_+"/Source_Histos/"+tightTrig+"_"+looseTrig+"_"+objName+"_passTrig_"+vsVarNames[varNr]+"_"+region); 
00262       if(pass==NULL){
00263 
00264         //edm::LogInfo("EgHLTOfflineClient") <<" couldnt get hist "<<dirName_+"/"+tightTrig+"_"+looseTrig+"_"+objName+"_passTrig_"+vsVarNames[varNr]+"_"+region;
00265         continue;
00266       } 
00267       const std::string newHistName(tightTrig+"_trigEffTo_"+looseTrig+"_"+objName+"_vs_"+vsVarNames[varNr]+"_"+region);
00268       //----Morse-----
00269       std::string effHistTitle(newHistName);//std::cout<<effHistTitle<<std::endl;
00270       if(region=="eb" || region=="ee"){
00271         if(region=="eb") effHistTitle = "Barrel "+tightTrig+"_TrigEffTo_"+looseTrig+"_"+objName+" vs "+vsVarNames[varNr];
00272         if(region=="ee") effHistTitle = "Endcap "+tightTrig+"_TrigEffTo_"+looseTrig+"_"+objName+" vs "+vsVarNames[varNr];
00273       }
00274       //std::cout<<effHistTitle<<std::endl;
00275       //dbe_->setCurrentFolder(dirName_+"/"+tightTrig+"_"+looseTrig);
00276       //------------
00277       makeEffMonElemFromPassAndFail("LooseTight",newHistName,effHistTitle,pass,fail);
00278     }//end loop over trigger pairs
00279   } //end loop over vsVarNames
00280   
00281 }
00282 //-----Morse-------
00283 //MonitorElement* EgHLTOfflineClient::makeEffMonElemFromPassAndAll(const std::string& name,const MonitorElement* pass,const MonitorElement* all)
00284 MonitorElement* EgHLTOfflineClient::makeEffMonElemFromPassAndAll(const std::string& filterName,const std::string& name,const std::string& title,const MonitorElement* pass,const MonitorElement* all)
00285 //-----------------
00286 {
00287   TH1F* passHist = pass->getTH1F();
00288   if(passHist->GetSumw2N()==0) passHist->Sumw2();
00289   TH1F* allHist = all->getTH1F();
00290   if(allHist->GetSumw2N()==0) allHist->Sumw2();
00291   TH1F* effHist = (TH1F*) passHist->Clone(name.c_str());
00292   effHist->Divide(passHist,allHist,1,1,"B");
00293   //----Morse---------
00294   effHist->SetTitle(title.c_str());
00295   //------------------
00296   MonitorElement* eff = dbe_->get(dirName_+"/Client_Histos/"+filterName+"/"+name);
00297   if(eff==NULL) eff= dbe_->book1D(name,effHist);
00298   else{ //I was having problems with collating the histograms, hence why I'm just resetting the histogram value
00299     *eff->getTH1F()=*effHist; 
00300     delete effHist;
00301   }
00302   return eff;
00303 }
00304 //-----Morse-------
00305 //MonitorElement* EgHLTOfflineClient::makeEffMonElemFromPassAndFail(const std::string& name,const MonitorElement* pass,const MonitorElement* fail)
00306 MonitorElement* EgHLTOfflineClient::makeEffMonElemFromPassAndFail(const std::string& filterName,const std::string& name,const std::string& title,const MonitorElement* pass,const MonitorElement* fail)
00307 //-------------
00308 {
00309   TH1F* failHist = fail->getTH1F();   
00310   if(failHist->GetSumw2N()==0) failHist->Sumw2();
00311   TH1F* passHist = pass->getTH1F();
00312   if(passHist->GetSumw2N()==0) passHist->Sumw2();
00313   
00314   TH1F* effHist = (TH1F*) passHist->Clone(name.c_str());
00315   effHist->Add(failHist);
00316   effHist->Divide(passHist,effHist,1,1,"B");
00317   //----Morse---------
00318   effHist->SetTitle(title.c_str());
00319   //------------------  
00320   MonitorElement* eff = dbe_->get(dirName_+"/Client_Histos/"+filterName+"/"+name);
00321   if(eff==NULL) eff = dbe_->book1D(name,effHist);
00322   else{ //I was having problems with collating the histograms, hence why I'm just reseting the histogram value
00323     *eff->getTH1F()=*effHist; 
00324     delete effHist;
00325   }
00326   return eff;
00327 }