CMS 3D CMS Logo

EgammaHLTOffline.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgammaHLTOffline.h"
00002 
00003 #include "DQMOffline/Trigger/interface/EleHLTPathMon.h"
00004 #include "DQMOffline/Trigger/interface/EleHLTFilterMon.h"
00005 #include "DQMOffline/Trigger/interface/EgHLTOffData.h"
00006 #include "DQMOffline/Trigger/interface/DebugFuncs.h"
00007 #include "DQMOffline/Trigger/interface/MonElemContainer.h"
00008 #include "DQMOffline/Trigger/interface/EgHLTDQMCut.h"
00009 #include "DQMOffline/Trigger/interface/MonElemFuncs.h"
00010 
00011 #include "DataFormats/Common/interface/Handle.h"
00012 
00013 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00014 #include "FWCore/Framework/interface/TriggerNames.h"
00015 #include "FWCore/Framework/interface/Run.h"
00016 
00017 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00018 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00019 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00020 
00021 #include "PhysicsTools/Utilities/interface/deltaR.h"
00022 
00023 EgammaHLTOffline::EgammaHLTOffline(const edm::ParameterSet& iConfig)
00024 {
00025   dbe_ = edm::Service<DQMStore>().operator->();
00026   if (!dbe_) {
00027     edm::LogInfo("EgammaHLTOffline") << "unable to get DQMStore service?";
00028   }
00029   if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00030     dbe_->setVerbose(0);
00031   }
00032   
00033   triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
00034   eleHLTPathNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTPathNames");
00035   eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00036 
00037 
00038   namesFiltersUsed_.clear();
00039   for(size_t pathNr=0;pathNr<eleHLTPathNames_.size();pathNr++){
00040     for(size_t filterNr=0;filterNr<eleHLTFilterNames_.size();filterNr++){
00041       namesFiltersUsed_.push_back(eleHLTPathNames_[pathNr]+eleHLTFilterNames_[filterNr]);
00042     }
00043   }
00044   namesFiltersUsed_.push_back("hltL1NonIsoHLTNonIsoSinglePhotonEt15TrackIsolFilter");
00045   TrigCodes::setCodes(namesFiltersUsed_);
00046 
00047   dirName_=iConfig.getParameter<std::string>("DQMDirName");//"HLT/EgammaHLTOffline_" + iConfig.getParameter<std::string>("@module_label");
00048 
00049   if(dbe_) dbe_->setCurrentFolder(dirName_);
00050  
00051   egHelper_.setup(iConfig);
00052 }
00053 
00054 
00055 EgammaHLTOffline::~EgammaHLTOffline()
00056 { 
00057   // LogDebug("EgammaHLTOffline") << "destructor called";
00058   for(size_t i=0;i<elePathMonHists_.size();i++){
00059     delete elePathMonHists_[i];
00060   }
00061 }
00062 
00063 void EgammaHLTOffline::beginJob(const edm::EventSetup& iSetup)
00064 {
00065   for(size_t i=0;i<eleHLTPathNames_.size();i++) addTrigPath(eleHLTPathNames_[i]);
00066   
00067   std::string tightTrig("hltL1NonIsoHLTNonIsoSingleElectronEt15TrackIsolFilter");
00068   // std::string looseTrig("hltL1NonIsoHLTNonIsoSingleElectronLWEt15TrackIsolFilter");
00069   std::string looseTrig("hltL1NonIsoHLTNonIsoSinglePhotonEt15TrackIsolFilter");
00070   
00071   //single electrons seeing if they pass the tighter trigger
00072   int stdCutCode = CutCodes::getCode("detEta:crack:sigmaEtaEta:hadem:dPhiIn:dEtaIn"); //will have it non hardcoded at a latter date
00073   eleMonElems_.push_back(new MonElemContainer<EgHLTOffEle>("passLooseTrig_passTightTrig","",
00074                                                            //&(*(new EgMultiCut<EgHLTOffEle>) << 
00075                                                            new EgEleTrigCut<EgHLTOffEle>(TrigCodes::getCode(tightTrig+":"+looseTrig),EgEleTrigCut<EgHLTOffEle>::AND)));//  <<
00076                                                              //new EgHLTDQMVarCut(stdCutCode,&EgHLTOffEle::cutCode))));
00077 
00078   eleMonElems_.push_back(new MonElemContainer<EgHLTOffEle>("passLooseTrig_failTightTrig","",
00079                                                            //&(*(new EgMultiCut<EgHLTOffEle>) << 
00080                                                            new EgEleTrigCut<EgHLTOffEle>(TrigCodes::getCode(looseTrig),EgEleTrigCut<EgHLTOffEle>::AND,TrigCodes::getCode(tightTrig))));//  << 
00081                                                              //new EgHLTDQMVarCut<EgHLTOffEle>(stdCutCode,&EgHLTOffEle::cutCode))));
00082   for(size_t i=0;i<eleMonElems_.size();i++){
00083     MonElemFuncs::initStdEleHists(eleMonElems_[i]->monElems(),tightTrig+"_"+eleMonElems_[i]->name());
00084   }
00085   
00086   //tag and probe trigger efficiencies
00087   //this is to do measure the trigger efficiency with respect to a fully selected offline electron
00088   //using a tag and probe technique (note: this will be different to the trigger efficiency normally calculated) 
00089   for(size_t pathNr=0;pathNr<eleHLTPathNames_.size();pathNr++){
00090     for(size_t filterNr=0;filterNr<eleHLTFilterNames_.size();filterNr++){ 
00091 
00092       std::string trigName(eleHLTPathNames_[pathNr]+eleHLTFilterNames_[filterNr]);
00093       int stdCutCode = CutCodes::getCode("detEta:crack:sigmaEtaEta:hadem:dPhiIn:dEtaIn"); //will have it non hardcoded at a latter date
00094       MonElemContainer<EgHLTOffEle>* monElemCont = new MonElemContainer<EgHLTOffEle>("trigTagProbe","Trigger Tag and Probe",new EgTrigTagProbeCut(TrigCodes::getCode(trigName),stdCutCode,&EgHLTOffEle::cutCode));
00095       MonElemFuncs::initStdEleCutHists(monElemCont->cutMonElems(),trigName+"_"+monElemCont->name()+"_all",new EgGreaterCut<EgHLTOffEle,float>(15.,&EgHLTOffEle::etSC));
00096       MonElemFuncs::initStdEleCutHists(monElemCont->cutMonElems(),trigName+"_"+monElemCont->name()+"_pass",&(*(new EgMultiCut<EgHLTOffEle>) << new EgGreaterCut<EgHLTOffEle,float>(15.,&EgHLTOffEle::etSC) << new EgEleTrigCut<EgHLTOffEle>(TrigCodes::getCode(trigName),EgEleTrigCut<EgHLTOffEle>::AND)));
00097       eleMonElems_.push_back(monElemCont);
00098     } //end filter names
00099   }//end path names
00100   //namesFiltersUsed_.clear();
00101   //filterNamesUsed(namesFiltersUsed_);
00102 
00103  //defines which bits are assoicated to which filter
00104  
00105   // TrigCodes::printCodes();
00106 
00107 }
00108 
00109 void EgammaHLTOffline::endJob() 
00110 {
00111   //  LogDebug("EgammaHLTOffline") << "ending job";
00112 }
00113 
00114 void EgammaHLTOffline::beginRun(const edm::Run& run, const edm::EventSetup& c)
00115 {
00116   //LogDebug("EgammaHLTOffline") << "beginRun, run " << run.id();
00117 }
00118 
00119 
00120 void EgammaHLTOffline::endRun(const edm::Run& run, const edm::EventSetup& c)
00121 {
00122   //LogDebug("EgammaHLTOffline") << "endRun, run " << run.id();
00123 }
00124 
00125 
00126 void EgammaHLTOffline::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00127 {
00128   const double weight=1.;
00129 
00130   //debugging info, commented out for prod
00131   //int nrProducts = debug::listAllProducts<reco::CaloJetCollection>(iEvent,"EgammaHLTOffline");
00132   //  edm::LogInfo("EgammaHLTOffline")<<" nr of jet obs "<<nrProducts;
00133 
00134   edm::Handle<trigger::TriggerEvent> triggerObj;
00135   iEvent.getByLabel(triggerSummaryLabel_,triggerObj); 
00136   if(!triggerObj.isValid()) { 
00137     edm::LogInfo("EgammaHLTOffline") << "Summary HLT objects not found, skipping event"; 
00138     return;
00139   }
00140 
00141   edm::Handle<reco::PixelMatchGsfElectronCollection> gsfElectrons;
00142   iEvent.getByLabel("pixelMatchGsfElectrons",gsfElectrons); 
00143   if(!gsfElectrons.isValid()) { 
00144     edm::LogInfo("EgammaHLTOffline") << "gsfElectrons not found,skipping event"; 
00145     return;
00146   }  
00147 
00148   egHelper_.getHandles(iEvent,iSetup);
00149 
00150   std::vector<EgHLTOffEle> egHLTOffEles;
00151   egHelper_.fillEgHLTOffEleVec(gsfElectrons,egHLTOffEles);
00152 
00153   std::vector<std::vector<int> > filtersElePasses;
00154   TrigCodes::TrigBitSet evtTrigBits = setFiltersElePasses(egHLTOffEles,namesFiltersUsed_,triggerObj);
00155  
00156   EgHLTOffData evtData;
00157   evtData.trigEvt = triggerObj;
00158   evtData.eles = &egHLTOffEles;
00159   evtData.filtersElePasses = &filtersElePasses;
00160   evtData.evtTrigBits = evtTrigBits;
00161   evtData.jets = egHelper_.jets();
00162   
00163 //   edm::LogInfo ("EgammaHLTOffline") << "starting event "<<iEvent.id().run()<<" "<<iEvent.id().event();
00164 
00165   //edm::LogInfo ("EgammaHLTOffline") << "nr filters in event "<<triggerObj->sizeFilters();
00166      //for(size_t i=0;i<triggerObj->sizeFilters();i++){
00167      //edm::LogInfo("EgammaHLTOffline")<<" in event filter "<<triggerObj->filterTag(i);
00168      //}
00169 
00170   for(size_t pathNr=0;pathNr<elePathMonHists_.size();pathNr++){
00171     elePathMonHists_[pathNr]->fill(evtData,weight);
00172   }
00173 
00174   for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
00175     const std::vector<EgHLTOffEle>& eles = *evtData.eles;
00176     for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00177       eleMonElems_[monElemNr]->fill(eles[eleNr],evtData,weight);
00178     }
00179   }
00180 }
00181 
00182 
00183 void EgammaHLTOffline::addTrigPath(const std::string& name)
00184 {
00185   EleHLTPathMon* pathMon = new EleHLTPathMon(name);
00186   pathMon->addFilters(eleHLTFilterNames_);
00187   elePathMonHists_.push_back(pathMon);
00188   std::sort(elePathMonHists_.begin(),elePathMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTPathMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
00189 }
00190 
00191 //I have the horrible feeling that I'm converting into an intermediatry format and then coverting back again
00192 //Okay how this works
00193 //1) create a TrigBitSet for each electron set to 0 initally
00194 //2) loop over each filter, for each electron that passes the filter, set the appropriate bit in the TrigBitSet
00195 //3) after that, loop over each electron setting the its TrigBitSet which has been calculated
00196 //4) a crowbar hack now has it also create a bitset for all the triggers which fired in the event (which are in the filters vector). Note these dont have to be electron triggers
00197 TrigCodes::TrigBitSet EgammaHLTOffline::setFiltersElePasses(std::vector<EgHLTOffEle>& eles,const std::vector<std::string>& filters,edm::Handle<trigger::TriggerEvent> trigEvt)
00198 {
00199   TrigCodes::TrigBitSet evtTrigs;
00200   std::vector<TrigCodes::TrigBitSet> eleTrigBits(eles.size());
00201   const double maxDeltaR=0.3;
00202   for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00203     size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"","HLT").encode());
00204     const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
00205 
00206     if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
00207       evtTrigs |=filterCode; //if something passes it add to the event trigger bits
00208       const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
00209       const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00210       for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00211         for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00212           float trigObjEta = trigObjColl[*keyIt].eta();
00213           float trigObjPhi = trigObjColl[*keyIt].phi();
00214           if (reco::deltaR(eles[eleNr].eta(),eles[eleNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00215             eleTrigBits[eleNr] |= filterCode;
00216           }//end dR<0.3 trig obj match test
00217         }//end loop over all objects passing filter
00218       }//end loop over electrons
00219     }//end check if filter is present
00220   }//end loop over all filters
00221 
00222   for(size_t eleNr=0;eleNr<eles.size();eleNr++) eles[eleNr].setTrigBits(eleTrigBits[eleNr]);
00223 
00224   return evtTrigs;
00225 
00226 }
00227 
00228 
00229 
00230 //TriggerEvent will for each filter name tell you the index it has in the event
00231 //I can then use this to get a list of candidates which pass the trigger and I do a deltaR match
00232 //to figure out if it corrsponds to the vincity of my electron (there *must* be a better way) 
00233 //eles: list of electrons in event
00234 //filters: list of filter names I want to check if the electron passes eg hltL1NonIsoHLTNonIsoSingleElectronEt15TrackIsolFilter
00235 //trigEvt : the handle to the TriggerEvent
00236 //filtersElePasses: a series of vectors, each vector corresponding to an electron. Each vector has a list of filter names the electron passes
00237 void EgammaHLTOffline::obtainFiltersElePasses(const std::vector<EgHLTOffEle>& eles,const std::vector<std::string>& filters,edm::Handle<trigger::TriggerEvent> trigEvt,std::vector<std::vector<int> >& filtersElePasses)
00238 {
00239   //the swap trick to quickly allocate the vector elements
00240   std::vector<std::vector<int> > dummyVec(eles.size());
00241   filtersElePasses.swap(dummyVec);
00242 
00243   const double maxDeltaR=0.3;
00244   for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00245     size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"","HLT").encode());
00246     
00247     if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
00248       const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);  //trigger::Keys is actually a vector<uint16_t> holding the position of trigger objects in the trigger collection passing the filter
00249       const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00250       for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00251         for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00252           float trigObjEta = trigObjColl[*keyIt].eta();
00253           float trigObjPhi = trigObjColl[*keyIt].phi();
00254           if (reco::deltaR(eles[eleNr].eta(),eles[eleNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00255             filtersElePasses[eleNr].push_back(filterNrInEvt);
00256           }//end dR<0.3 trig obj match test
00257         }//end loop over all objects passing filter
00258       }//end loop over electrons
00259     }//end check if filter is present
00260   }//end loop over all filters
00261   
00262   //now we need to sort the list of trigger numbers that each electron passes
00263   for(size_t i=0;i<filtersElePasses.size();i++) std::sort(filtersElePasses[i].begin(),filtersElePasses[i].end());
00264 }
00265 
00266 void EgammaHLTOffline::filterNamesUsed(std::vector<std::string>& filterNames)
00267 {
00268   filterNames.clear();
00269   for(size_t pathNr=0;pathNr<elePathMonHists_.size();pathNr++){
00270     std::vector<std::string> pathFilters = elePathMonHists_[pathNr]->getFilterNames();
00271     for(size_t i=0;i<pathFilters.size();i++) filterNames.push_back(pathFilters[i]);
00272   }
00273 }

Generated on Tue Jun 9 17:34:09 2009 for CMSSW by  doxygen 1.5.4