test
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,const TrigCodes& trigCodes);
15 
16  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 TrigCodes& trigCodes, const trigger::TriggerEvent* trigEvt,const std::string& hltTag );
17 
18  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 );
19  int getMinNrObjsRequiredByFilter(const std::string& filterName); //slow function, call at begin job and cache results
20 
21  //reads hlt config and works out which are the active last filters stored in trigger summary, is sorted
22  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);
23  //---Morse test--------
24  //void getPhoton30(const HLTConfigProvider& hltConfig,std::vector<std::string>& activeFilters);
25  //------------------
26  //filters a list of filternames removing any filters which are not in active filters, assumes active filters is sorted
27  void filterInactiveTriggers(std::vector<std::string>& namesToFilter,std::vector<std::string>& activeFilters);
28  //filters a list of filterName1:filterName2 removing any entry for which either filter is not in activeFilters, assumes active filters is sorted
29  void filterInactiveTightLooseTriggers(std::vector<std::string>& namesToFilter,const std::vector<std::string>& activeFilters);
30 
31  void translateFiltersToPathNames(const HLTConfigProvider& hltConfig,const std::vector<std::string>& filters,std::vector<std::string>& paths);
33 
34  //looks for string Et and then looks for a number after that (currently the standard of all E/g triggers)
35  //returns 0 if unsuccessful
36  float getEtThresFromName(const std::string& trigName);
37  float getSecondEtThresFromName(const std::string& trigName);
38  }
39 
40  //I have the horrible feeling that I'm converting into an intermediatry format and then coverting back again
41  //Okay how this works
42  //1) create a TrigBitSet for each particle set to 0 initally
43  //2) loop over each filter, for each particle that passes the filter, set the appropriate bit in the TrigBitSet
44  //3) after that, loop over each particle setting that its TrigBitSet which has been calculated
45  //4) because L1 pre-scaled paths are special, we only set those if an event wide trigger has been set
46  template <class T>
47  void trigTools::setFiltersObjPasses(std::vector<T>& particles,const std::vector<std::string>& filters,
48  const std::vector<std::pair<std::string,std::string> >& l1PreAndSeedFilters,
49  const TrigCodes::TrigBitSet& evtTrigBits,
50  const TrigCodes& trigCodes,
51  const trigger::TriggerEvent* trigEvt,const std::string& hltTag)
52  {
53  std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
54  const double maxDeltaR=0.1;
55  for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
56  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
57  const TrigCodes::TrigBitSet filterCode = trigCodes.getCode(filters[filterNrInVec].c_str());
58 
59  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
60  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
61  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
62  for(size_t partNr=0;partNr<particles.size();partNr++){
63  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
64  float trigObjEta = trigObjColl[*keyIt].eta();
65  float trigObjPhi = trigObjColl[*keyIt].phi();
66  if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
67  partTrigBits[partNr] |= filterCode;
68  }//end dR<maxDeltaR trig obj match test
69  }//end loop over all objects passing filter
70  }//end loop over particles
71  }//end check if filter is present
72  }//end loop over all filters
73 
74  //okay the first element is the key, the second is the filter that exists in trigger event
75  for(size_t l1FilterNrInVec=0;l1FilterNrInVec<l1PreAndSeedFilters.size();l1FilterNrInVec++){
76  const TrigCodes::TrigBitSet filterCode = trigCodes.getCode(l1PreAndSeedFilters[l1FilterNrInVec].first.c_str());
77  if((filterCode&evtTrigBits)==filterCode){ //check that filter has fired in the event
78 
79  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilters[l1FilterNrInVec].second,"",hltTag).encode());
80 
81  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
82  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
83  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
84  for(size_t partNr=0;partNr<particles.size();partNr++){
85  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
86  float trigObjEta = trigObjColl[*keyIt].eta();
87  float trigObjPhi = trigObjColl[*keyIt].phi();
88  if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
89  partTrigBits[partNr] |= filterCode;
90  }//end dR<maxDeltaR trig obj match test
91  }//end loop over all objects passing filter
92  }//end loop over particles
93  }//end check if filter is present
94  }//end check if path has fired in the event
95  }//end loop over all filters
96 
97  for(size_t partNr=0;partNr<particles.size();partNr++) particles[partNr].setTrigBits(partTrigBits[partNr]);
98 
99  }
100 
101 
102  template <class T, class U>
104  U& hltData,
105  const std::vector<std::string>& filters,
106  const trigger::TriggerEvent* trigEvt,
107  const std::string& hltTag)
108 {
109  std::vector<TrigCodes::TrigBitSet> partTrigBits(1);
110  const double maxDeltaR=0.1;
111  for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
112  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
113  //const TrigCodes::TrigBitSet filterCode = trigCodes.getCode(filters[filterNrInVec].c_str());
114  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
115  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
116  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
117  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
118  float trigObjEta = trigObjColl[*keyIt].eta();
119  float trigObjPhi = trigObjColl[*keyIt].phi();
120  float trigObjE = trigObjColl[*keyIt].energy();
121  if (reco::deltaR(particle.superCluster()->eta(),particle.superCluster()->phi(),trigObjEta,trigObjPhi) < maxDeltaR){
122  hltData.HLTeta=trigObjEta;
123  hltData.HLTphi=trigObjPhi;
124  hltData.HLTenergy=trigObjE;
125  }//end dR<maxDeltaR trig obj match test
126  }//end loop over all objects passing filter`
127  }//end check if filter is present
128  }//end check if path has fired in the event
129 }//end loop over all filters
130 
131 }//end namespace declaration
132 
133 #endif
134 
void fillHLTposition(T &obj, U &hltData, const std::vector< std::string > &filters, const trigger::TriggerEvent *trigEvt, const std::string &hltTag)
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
TrigBitSet getCode(const char *descript) const
int getMinNrObjsRequiredByFilter(const std::string &filterName)
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
std::vector< TPRegexp > filters
Definition: eve_filter.cc:22
U second(std::pair< T, U > const &p)
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
std::string getL1SeedFilterOfPath(const HLTConfigProvider &hltConfig, const std::string &path)
float getEtThresFromName(const std::string &trigName)
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
TrigCodes::TrigBitSet getFiltersPassed(const std::vector< std::pair< std::string, int > > &filters, const trigger::TriggerEvent *trigEvt, const std::string &hltTag, const TrigCodes &trigCodes)
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
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
Geom::Phi< T > phi() const
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)
long double 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 TrigCodes &trigCodes, 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