CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgHLTTrigTools.h
Go to the documentation of this file.
1 #ifndef DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
2 #define DQMOFFLINE_TRIGGER_EGHLTTRIGTOOLS
3 
8 
10 
11 namespace egHLT {
12 
13  namespace trigTools {
14  TrigCodes::TrigBitSet getFiltersPassed(const std::vector<std::pair<std::string,int> >& filters,const trigger::TriggerEvent* trigEvt,const std::string& hltTag);
15  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 );
16  int getMinNrObjsRequiredByFilter(const std::string& filterName); //slow function, call at begin job and cache results
17 
18  //reads hlt config and works out which are the active last filters stored in trigger summary, is sorted
19  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);
20  //---Morse test--------
21  //void getPhoton30(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters);
22  //------------------
23  //filters a list of filternames removing any filters which are not in active filters, assumes active filters is sorted
24  void filterInactiveTriggers(std::vector<std::string>& namesToFilter,std::vector<std::string>& activeFilters);
25  //filters a list of filterName1:filterName2 removing any entry for which either filter is not in activeFilters, assumes active filters is sorted
26  void filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters);
27 
28  void translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths);
29  std::string getL1SeedFilterOfPath(const HLTConfigProvider& hltConfig,const std::string& path);
30 
31  //looks for string Et and then looks for a number after that (currently the standard of all E/g triggers)
32  //returns 0 if unsuccessful
33  float getEtThresFromName(const std::string& trigName);
34  float getSecondEtThresFromName(const std::string& trigName);
35  }
36 
37  //I have the horrible feeling that I'm converting into an intermediatry format and then coverting back again
38  //Okay how this works
39  //1) create a TrigBitSet for each particle set to 0 initally
40  //2) loop over each filter, for each particle that passes the filter, set the appropriate bit in the TrigBitSet
41  //3) after that, loop over each particle setting that its TrigBitSet which has been calculated
42  //4) because L1 pre-scaled paths are special, we only set those if an event wide trigger has been set
43  template <class T>
44  void trigTools::setFiltersObjPasses(std::vector<T>& particles,const std::vector<std::string>& filters,
45  const std::vector<std::pair<std::string,std::string> >& l1PreAndSeedFilters,
46  const TrigCodes::TrigBitSet& evtTrigBits,
47  const trigger::TriggerEvent* trigEvt,const std::string& hltTag)
48  {
49  std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
50  const double maxDeltaR=0.1;
51  for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
52  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
53  const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
54 
55  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
56  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
57  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
58  for(size_t partNr=0;partNr<particles.size();partNr++){
59  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
60  float trigObjEta = trigObjColl[*keyIt].eta();
61  float trigObjPhi = trigObjColl[*keyIt].phi();
62  if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
63  partTrigBits[partNr] |= filterCode;
64  }//end dR<maxDeltaR trig obj match test
65  }//end loop over all objects passing filter
66  }//end loop over particles
67  }//end check if filter is present
68  }//end loop over all filters
69 
70  //okay the first element is the key, the second is the filter that exists in trigger event
71  for(size_t l1FilterNrInVec=0;l1FilterNrInVec<l1PreAndSeedFilters.size();l1FilterNrInVec++){
72  const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(l1PreAndSeedFilters[l1FilterNrInVec].first.c_str());
73  if((filterCode&evtTrigBits)==filterCode){ //check that filter has fired in the event
74 
75  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilters[l1FilterNrInVec].second,"",hltTag).encode());
76 
77  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
78  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
79  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
80  for(size_t partNr=0;partNr<particles.size();partNr++){
81  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
82  float trigObjEta = trigObjColl[*keyIt].eta();
83  float trigObjPhi = trigObjColl[*keyIt].phi();
84  if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
85  partTrigBits[partNr] |= filterCode;
86  }//end dR<maxDeltaR trig obj match test
87  }//end loop over all objects passing filter
88  }//end loop over particles
89  }//end check if filter is present
90  }//end check if path has fired in the event
91  }//end loop over all filters
92 
93  for(size_t partNr=0;partNr<particles.size();partNr++) particles[partNr].setTrigBits(partTrigBits[partNr]);
94 
95  }
96 }
97 #endif
98 
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:27
static TrigBitSet getCode(const std::string &descript)
TrigCodes::TrigBitSet getFiltersPassed(const std::vector< std::pair< std::string, int > > &filters, const trigger::TriggerEvent *trigEvt, const std::string &hltTag)
int getMinNrObjsRequiredByFilter(const std::string &filterName)
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:106
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:118
T eta() const
std::vector< TPRegexp > filters
Definition: eve_filter.cc:25
double deltaR(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:19
int path() const
Definition: HLTadd.h:3
U second(std::pair< T, U > const &p)
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:100
std::string getL1SeedFilterOfPath(const HLTConfigProvider &hltConfig, const std::string &path)
float getEtThresFromName(const std::string &trigName)
bool first
Definition: L1TdeRCT.cc:79
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:83
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)
std::vector< size_type > Keys
void filterInactiveTriggers(std::vector< std::string > &namesToFilter, std::vector< std::string > &activeFilters)
void filterInactiveTightLooseTriggers(std::vector< std::string > &namesToFilter, const std::vector< std::string > &activeFilters)
float getSecondEtThresFromName(const std::string &trigName)
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)
void translateFiltersToPathNames(const HLTConfigProvider &hltConfig, const std::vector< std::string > &filters, std::vector< std::string > &paths)
std::bitset< maxNrBits_ > TrigBitSet
Definition: DDAxes.h:10