00001 #ifndef DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
00002 #define DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
00003
00004 #include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"
00005 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "DataFormats/Math/interface/deltaR.h"
00008
00009 class HLTConfigProvider;
00010
00011 namespace egHLT {
00012
00013 namespace trigTools {
00014 TrigCodes::TrigBitSet getFiltersPassed(const std::vector<std::pair<std::string,int> >& filters,const trigger::TriggerEvent* trigEvt,const std::string& hltTag);
00015
00016 template<class T> void setFiltersObjPasses(std::vector<T>& objs,const std::vector<std::string>& filters,const std::vector<std::pair<std::string,std::string> >& l1PreAndSeedFilters,const TrigCodes::TrigBitSet& evtTrigBits,const trigger::TriggerEvent* trigEvt,const std::string& hltTag );
00017
00018 template<class T, class U> void fillHLTposition(T& obj,U& hltData,const std::vector<std::string>& filters,const trigger::TriggerEvent* trigEvt,const std::string& hltTag );
00019 int getMinNrObjsRequiredByFilter(const std::string& filterName);
00020
00021
00022 void getActiveFilters(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters,std::vector<std::string>& activeEleFilters,std::vector<std::string>& activeEle2LegFilters,std::vector<std::string>& activePhoFilters,std::vector<std::string>& activePho2LegFilters);
00023
00024
00025
00026
00027 void filterInactiveTriggers(std::vector<std::string>& namesToFilter,std::vector<std::string>& activeFilters);
00028
00029 void filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters);
00030
00031 void translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths);
00032 std::string getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig,const std::string& path);
00033
00034
00035
00036 float getEtThresFromName(const std::string& trigName);
00037 float getSecondEtThresFromName(const std::string& trigName);
00038 }
00039
00040
00041
00042
00043
00044
00045
00046 template <class T>
00047 void trigTools::setFiltersObjPasses(std::vector<T>& particles,const std::vector<std::string>& filters,
00048 const std::vector<std::pair<std::string,std::string> >& l1PreAndSeedFilters,
00049 const TrigCodes::TrigBitSet& evtTrigBits,
00050 const trigger::TriggerEvent* trigEvt,const std::string& hltTag)
00051 {
00052 std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
00053 const double maxDeltaR=0.1;
00054 for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00055 size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
00056 const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
00057
00058 if(filterNrInEvt<trigEvt->sizeFilters()){
00059 const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
00060 const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00061 for(size_t partNr=0;partNr<particles.size();partNr++){
00062 for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00063 float trigObjEta = trigObjColl[*keyIt].eta();
00064 float trigObjPhi = trigObjColl[*keyIt].phi();
00065 if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00066 partTrigBits[partNr] |= filterCode;
00067 }
00068 }
00069 }
00070 }
00071 }
00072
00073
00074 for(size_t l1FilterNrInVec=0;l1FilterNrInVec<l1PreAndSeedFilters.size();l1FilterNrInVec++){
00075 const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(l1PreAndSeedFilters[l1FilterNrInVec].first.c_str());
00076 if((filterCode&evtTrigBits)==filterCode){
00077
00078 size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilters[l1FilterNrInVec].second,"",hltTag).encode());
00079
00080 if(filterNrInEvt<trigEvt->sizeFilters()){
00081 const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
00082 const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00083 for(size_t partNr=0;partNr<particles.size();partNr++){
00084 for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00085 float trigObjEta = trigObjColl[*keyIt].eta();
00086 float trigObjPhi = trigObjColl[*keyIt].phi();
00087 if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00088 partTrigBits[partNr] |= filterCode;
00089 }
00090 }
00091 }
00092 }
00093 }
00094 }
00095
00096 for(size_t partNr=0;partNr<particles.size();partNr++) particles[partNr].setTrigBits(partTrigBits[partNr]);
00097
00098 }
00099
00100
00101 template <class T, class U>
00102 void trigTools::fillHLTposition(T& particle,
00103 U& hltData,
00104 const std::vector<std::string>& filters,
00105 const trigger::TriggerEvent* trigEvt,
00106 const std::string& hltTag)
00107 {
00108 std::vector<TrigCodes::TrigBitSet> partTrigBits(1);
00109 const double maxDeltaR=0.1;
00110 for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
00111 size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
00112
00113 if(filterNrInEvt<trigEvt->sizeFilters()){
00114 const trigger::Keys& trigKeys = trigEvt->filterKeys(filterNrInEvt);
00115 const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
00116 for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
00117 float trigObjEta = trigObjColl[*keyIt].eta();
00118 float trigObjPhi = trigObjColl[*keyIt].phi();
00119 float trigObjE = trigObjColl[*keyIt].energy();
00120 if (reco::deltaR(particle.superCluster()->eta(),particle.superCluster()->phi(),trigObjEta,trigObjPhi) < maxDeltaR){
00121 hltData.HLTeta=trigObjEta;
00122 hltData.HLTphi=trigObjPhi;
00123 hltData.HLTenergy=trigObjE;
00124 }
00125 }
00126 }
00127 }
00128 }
00129
00130 }
00131
00132 #endif
00133