CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQMOffline/Trigger/src/EgHLTOfflineSource.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgHLTOfflineSource.h"
00002 
00003 #include "DQMOffline/Trigger/interface/EgHLTEleHLTFilterMon.h"
00004 #include "DQMOffline/Trigger/interface/EgHLTPhoHLTFilterMon.h"
00005 
00006 #include "DQMOffline/Trigger/interface/EgHLTDebugFuncs.h"
00007 #include "DQMOffline/Trigger/interface/EgHLTDQMCut.h"
00008 #include "DQMOffline/Trigger/interface/EgHLTMonElemFuncs.h"
00009 #include "DQMOffline/Trigger/interface/EgHLTTrigTools.h"
00010 
00011 #include "DQMServices/Core/interface/MonitorElement.h"
00012 
00013 #include "FWCore/Framework/interface/Run.h"
00014 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00015 
00016 #include <boost/algorithm/string.hpp>
00017 
00018 //#include "DQMOffline/Trigger/interface/EgHLTCutCodes.h"
00019 #include "DataFormats/TrackReco/interface/Track.h"
00020 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00021 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00022 using namespace egHLT;
00023 
00024 EgHLTOfflineSource::EgHLTOfflineSource(const edm::ParameterSet& iConfig):
00025   nrEventsProcessed_(0),isSetup_(false)
00026 {
00027   dbe_ = edm::Service<DQMStore>().operator->(); //only one chance to get this, if we ever have another shot, remember to check isSetup is okay
00028   if (!dbe_) {
00029     //our one and only error message ever logged
00030     edm::LogInfo("EgHLTOfflineSource") << "unable to get DQMStore service?";
00031   }
00032   if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00033     dbe_->setVerbose(0);
00034   }
00035 
00036  
00037   binData_.setup(iConfig.getParameter<edm::ParameterSet>("binData"));
00038   cutMasks_.setup(iConfig.getParameter<edm::ParameterSet>("cutMasks"));
00039   eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00040   eleHLTFilterNames2Leg_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames2Leg");
00041   phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00042   eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
00043   diEleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diEleTightLooseTrigNames"); 
00044   phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
00045   diPhoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diPhoTightLooseTrigNames"); 
00046 
00047   filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
00048   hltTag_ = iConfig.getParameter<std::string>("hltTag");
00049  
00050   
00051   dirName_=iConfig.getParameter<std::string>("DQMDirName");//"HLT/EgHLTOfflineSource_" + iConfig.getParameter<std::string>("@module_label");
00052 
00053  
00054   offEvtHelper_.setup(iConfig);
00055 
00056 }
00057 
00058 
00059 EgHLTOfflineSource::~EgHLTOfflineSource()
00060 { 
00061   // LogDebug("EgHLTOfflineSource") << "destructor called";
00062   for(size_t i=0;i<eleFilterMonHists_.size();i++){
00063     delete eleFilterMonHists_[i];
00064   } 
00065   for(size_t i=0;i<phoFilterMonHists_.size();i++){
00066     delete phoFilterMonHists_[i];
00067   }
00068   for(size_t i=0;i<eleMonElems_.size();i++){
00069     delete eleMonElems_[i];
00070   } 
00071   for(size_t i=0;i<phoMonElems_.size();i++){
00072     delete phoMonElems_[i];
00073   }
00074 }
00075 
00076 void EgHLTOfflineSource::beginJob()
00077 {
00078   if(dbe_) {
00079     dbe_->setCurrentFolder(dirName_);
00080     //the one monitor element the source fills directly
00081     dqmErrsMonElem_ =dbe_->book1D("dqmErrors","EgHLTOfflineSource Errors",101,-0.5,100.5);
00082     nrEventsProcessedMonElem_ = dbe_->bookInt("nrEventsProcessed");
00083   }
00084 }
00085 
00086 void EgHLTOfflineSource::endJob() 
00087 {
00088   //  LogDebug("EgHLTOfflineSource") << "ending job";
00089 }
00090 
00091 //due to changes in HLTConfigProvider to be called at beginRun rather then beginJob, I moved everything from beginJob here and ensure that it is only called once
00092 //if the HLTConfig changes during the job, the results are "un predictable" but in practice should be fine
00093 //the HLTConfig is used for working out which triggers are active, working out which filternames correspond to paths and L1 seeds
00094 //assuming those dont change for E/g it *should* be fine 
00095 void EgHLTOfflineSource::beginRun(const edm::Run& run, const edm::EventSetup& c)
00096 {
00097   if(dbe_ && !isSetup_){
00098     HLTConfigProvider hltConfig;
00099     bool changed=false;
00100     hltConfig.init(run,c,hltTag_,changed);
00101     if(filterInactiveTriggers_) filterTriggers(hltConfig);
00102 
00103     std::vector<std::string> hltFiltersUsed;
00104     getHLTFilterNamesUsed(hltFiltersUsed);
00105     TrigCodes::setCodes(hltFiltersUsed);
00106    
00107     offEvtHelper_.setupTriggers(hltConfig,hltFiltersUsed);
00108 
00109     //now book ME's
00110     dbe_->setCurrentFolder(dirName_+"/Source_Histos");
00111     //each trigger path with generate object distributions and efficiencies (BUT not trigger efficiencies...)
00112     for(size_t i=0;i<eleHLTFilterNames_.size();i++){dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]);  addEleTrigPath(eleHLTFilterNames_[i]);}
00113     for(size_t i=0;i<phoHLTFilterNames_.size();i++){dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]);  addPhoTrigPath(phoHLTFilterNames_[i]);}
00114     //efficiencies of one trigger path relative to another
00115     MonElemFuncs::initTightLooseTrigHists(eleMonElems_,eleTightLooseTrigNames_,binData_,"gsfEle");
00116     //new EgHLTDQMVarCut<OffEle>(cutMasks_.stdEle,&OffEle::cutCode)); 
00117     //MonElemFuncs::initTightLooseTrigHistsTrigCuts(eleMonElems_,eleTightLooseTrigNames_,binData_);
00118       
00119    
00120     MonElemFuncs::initTightLooseTrigHists(phoMonElems_,phoTightLooseTrigNames_,binData_,"pho");
00121     //  new EgHLTDQMVarCut<OffPho>(cutMasks_.stdPho,&OffPho::cutCode)); 
00122     //MonElemFuncs::initTightLooseTrigHistsTrigCuts(phoMonElems_,phoTightLooseTrigNames_,binData_);
00123       
00124     //di-object triggers
00125     MonElemFuncs::initTightLooseTrigHists(eleMonElems_,diEleTightLooseTrigNames_,binData_,"gsfEle");
00126     //  new EgDiEleCut(cutMasks_.stdEle,&OffEle::cutCode));
00127     MonElemFuncs::initTightLooseTrigHists(phoMonElems_,diPhoTightLooseTrigNames_,binData_,"pho");
00128     //                          new EgDiPhoCut(cutMasks_.stdPho,&OffPho::cutCode));
00129     
00130     MonElemFuncs::initTightLooseDiObjTrigHistsTrigCuts(eleMonElems_,diEleTightLooseTrigNames_,binData_);
00131     MonElemFuncs::initTightLooseDiObjTrigHistsTrigCuts(phoMonElems_,diPhoTightLooseTrigNames_,binData_);
00132 
00133     
00134     //tag and probe trigger efficiencies
00135     //this is to do measure the trigger efficiency with respect to a fully selected offline electron
00136     //using a tag and probe technique (note: this will be different to the trigger efficiency normally calculated) 
00137     bool doTrigTagProbeEff=false;
00138     if(doTrigTagProbeEff){
00139       for(size_t i=0;i<eleHLTFilterNames_.size();i++){
00140         dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]);
00141         MonElemFuncs::initTrigTagProbeHist(eleMonElems_,eleHLTFilterNames_[i],cutMasks_.trigTPEle,binData_);
00142       }
00143       for(size_t i=0;i<phoHLTFilterNames_.size();i++){
00144         dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]);
00145         MonElemFuncs::initTrigTagProbeHist(phoMonElems_,phoHLTFilterNames_[i],cutMasks_.trigTPPho,binData_);
00146       }
00147       for(size_t i=0;i<eleHLTFilterNames2Leg_.size();i++){
00148         dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2));
00149         //std::cout<<"FilterName: "<<eleHLTFilterNames2Leg_[i]<<std::endl;
00150         //std::cout<<"Folder: "<<eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2)<<std::endl;
00151         MonElemFuncs::initTrigTagProbeHist_2Leg(eleMonElems_,eleHLTFilterNames2Leg_[i],cutMasks_.trigTPEle,binData_);
00152       }
00153       //tag and probe not yet implimented for photons (attemping to see if it makes sense first)
00154       // MonElemFuncs::initTrigTagProbeHists(phoMonElems,phoHLTFilterNames_);
00155     }
00156     isSetup_=true;
00157     
00158     dbe_->setCurrentFolder(dirName_);
00159   }
00160 }
00161 
00162 
00163 void EgHLTOfflineSource::endRun(const edm::Run& run, const edm::EventSetup& c)
00164 {
00165   //LogDebug("EgHLTOfflineSource") << "endRun, run " << run.id();
00166 }
00167 
00168 
00169 void EgHLTOfflineSource::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00170 { 
00171   //debugging info, commented out for prod
00172   //  int nrProducts = debug::listAllProducts<edm::ValueMap<double> >(iEvent,"EgHLTOfflineSource");
00173   //edm::LogInfo("EgHLTOfflineSource")<<" HERE ";
00174   // std::cout <<"here"<<std::endl;
00175   if(!dbe_) return;
00176    
00177  
00178  
00179 
00180 
00181   const double weight=1.; //we have the ability to weight but its disabled for now - maybe use this for prescales?
00182   nrEventsProcessed_++;
00183   nrEventsProcessedMonElem_->Fill(nrEventsProcessed_);
00184   int errCode = offEvtHelper_.makeOffEvt(iEvent,iSetup,offEvt_);
00185   if(errCode!=0){
00186     dqmErrsMonElem_->Fill(errCode);
00187     return;
00188   }
00189 
00190 
00191   for(size_t pathNr=0;pathNr<eleFilterMonHists_.size();pathNr++){
00192     eleFilterMonHists_[pathNr]->fill(offEvt_,weight);
00193   } 
00194   for(size_t pathNr=0;pathNr<phoFilterMonHists_.size();pathNr++){
00195     phoFilterMonHists_[pathNr]->fill(offEvt_,weight);
00196   }
00197 
00198   for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
00199     const std::vector<OffEle>& eles = offEvt_.eles();
00200     for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00201       eleMonElems_[monElemNr]->fill(eles[eleNr],offEvt_,weight);
00202     }
00203   }
00204 
00205   for(size_t monElemNr=0;monElemNr<phoMonElems_.size();monElemNr++){
00206     const std::vector<OffPho>& phos = offEvt_.phos();
00207     for(size_t phoNr=0;phoNr<phos.size();phoNr++){
00208       phoMonElems_[monElemNr]->fill(phos[phoNr],offEvt_,weight);
00209     }
00210   }
00211 }
00212 
00213 
00214 void EgHLTOfflineSource::addEleTrigPath(const std::string& name)
00215 {
00216   EleHLTFilterMon* filterMon = new EleHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);  
00217   eleFilterMonHists_.push_back(filterMon);
00218   std::sort(eleFilterMonHists_.begin(),eleFilterMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTFilterMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
00219 }
00220 
00221 void EgHLTOfflineSource::addPhoTrigPath(const std::string& name)
00222 {
00223   PhoHLTFilterMon* filterMon = new PhoHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
00224   phoFilterMonHists_.push_back(filterMon);
00225   std::sort(phoFilterMonHists_.begin(),phoFilterMonHists_.end(),PhoHLTFilterMon::ptrLess<PhoHLTFilterMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
00226 }
00227 
00228 //this function puts every filter name used in a std::vector
00229 //due to the design, to ensure we get every filter, filters will be inserted multiple times
00230 //eg electron filters will contain photon triggers which are also in the photon filters
00231 //but only want one copy in the vector
00232 //this function is intended to be called once per job so some inefficiency can can be tolerated
00233 //therefore we will use a std::set to ensure that each filtername is only inserted once
00234 //and then convert to a std::vector
00235 void EgHLTOfflineSource::getHLTFilterNamesUsed(std::vector<std::string>& filterNames)const
00236 { 
00237   std::set<std::string> filterNameSet;
00238   for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
00239   for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
00240   //here we are little more complicated as entries are of the form "tightTrig:looseTrig" 
00241   //so we need to split them first
00242   for(size_t tightLooseNr=0;tightLooseNr<eleTightLooseTrigNames_.size();tightLooseNr++){
00243     std::vector<std::string> trigNames;
00244     boost::split(trigNames,eleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00245     if(trigNames.size()!=2) continue; //format incorrect
00246     filterNameSet.insert(trigNames[0]);
00247     filterNameSet.insert(trigNames[1]);
00248   }
00249   for(size_t tightLooseNr=0;tightLooseNr<diEleTightLooseTrigNames_.size();tightLooseNr++){
00250     std::vector<std::string> trigNames;
00251     boost::split(trigNames,diEleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00252     if(trigNames.size()!=2) continue; //format incorrect
00253     filterNameSet.insert(trigNames[0]);
00254     filterNameSet.insert(trigNames[1]);
00255   }
00256   for(size_t tightLooseNr=0;tightLooseNr<phoTightLooseTrigNames_.size();tightLooseNr++){
00257     std::vector<std::string> trigNames;
00258     boost::split(trigNames,phoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00259     if(trigNames.size()!=2) continue; //format incorrect
00260     filterNameSet.insert(trigNames[0]);
00261     filterNameSet.insert(trigNames[1]);
00262   } 
00263   for(size_t tightLooseNr=0;tightLooseNr<diPhoTightLooseTrigNames_.size();tightLooseNr++){
00264     std::vector<std::string> trigNames;
00265     boost::split(trigNames,diPhoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00266     if(trigNames.size()!=2) continue; //format incorrect
00267     filterNameSet.insert(trigNames[0]);
00268     filterNameSet.insert(trigNames[1]);
00269   }
00270   //right all the triggers are inserted once and only once in the set, convert to vector
00271   //very lazy, create a new vector so can use the constructor and then use swap to transfer
00272   std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
00273 }
00274 
00275 void EgHLTOfflineSource::filterTriggers(const HLTConfigProvider& hltConfig)
00276 {
00277   
00278   std::vector<std::string> activeFilters;
00279   std::vector<std::string> activeEleFilters;
00280   std::vector<std::string> activeEle2LegFilters;
00281   std::vector<std::string> activePhoFilters;
00282   std::vector<std::string> activePho2LegFilters;
00283   
00284   trigTools::getActiveFilters(hltConfig,activeFilters,activeEleFilters,activeEle2LegFilters,activePhoFilters,activePho2LegFilters);
00285   
00286   trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeEleFilters);
00287   trigTools::filterInactiveTriggers(phoHLTFilterNames_,activePhoFilters);
00288   trigTools::filterInactiveTriggers(eleHLTFilterNames2Leg_,activeEle2LegFilters);
00289   trigTools::filterInactiveTightLooseTriggers(eleTightLooseTrigNames_,activeEleFilters);
00290   trigTools::filterInactiveTightLooseTriggers(diEleTightLooseTrigNames_,activeEleFilters);
00291   trigTools::filterInactiveTightLooseTriggers(phoTightLooseTrigNames_,activePhoFilters);
00292   trigTools::filterInactiveTightLooseTriggers(diPhoTightLooseTrigNames_,activePhoFilters);      
00293 }