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 
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 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 trigger::TriggerEvent* trigEvt,const std::string& hltTag)
51  {
52  std::vector<TrigCodes::TrigBitSet> partTrigBits(particles.size());
53  const double maxDeltaR=0.1;
54  for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
55  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
56  const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
57 
58  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
59  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
60  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
61  for(size_t partNr=0;partNr<particles.size();partNr++){
62  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
63  float trigObjEta = trigObjColl[*keyIt].eta();
64  float trigObjPhi = trigObjColl[*keyIt].phi();
65  if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
66  partTrigBits[partNr] |= filterCode;
67  }//end dR<maxDeltaR trig obj match test
68  }//end loop over all objects passing filter
69  }//end loop over particles
70  }//end check if filter is present
71  }//end loop over all filters
72 
73  //okay the first element is the key, the second is the filter that exists in trigger event
74  for(size_t l1FilterNrInVec=0;l1FilterNrInVec<l1PreAndSeedFilters.size();l1FilterNrInVec++){
75  const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(l1PreAndSeedFilters[l1FilterNrInVec].first.c_str());
76  if((filterCode&evtTrigBits)==filterCode){ //check that filter has fired in the event
77 
78  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(l1PreAndSeedFilters[l1FilterNrInVec].second,"",hltTag).encode());
79 
80  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
81  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
82  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
83  for(size_t partNr=0;partNr<particles.size();partNr++){
84  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
85  float trigObjEta = trigObjColl[*keyIt].eta();
86  float trigObjPhi = trigObjColl[*keyIt].phi();
87  if (reco::deltaR(particles[partNr].eta(),particles[partNr].phi(),trigObjEta,trigObjPhi) < maxDeltaR){
88  partTrigBits[partNr] |= filterCode;
89  }//end dR<maxDeltaR trig obj match test
90  }//end loop over all objects passing filter
91  }//end loop over particles
92  }//end check if filter is present
93  }//end check if path has fired in the event
94  }//end loop over all filters
95 
96  for(size_t partNr=0;partNr<particles.size();partNr++) particles[partNr].setTrigBits(partTrigBits[partNr]);
97 
98  }
99 
100 
101  template <class T, class U>
103  U& hltData,
104  const std::vector<std::string>& filters,
105  const trigger::TriggerEvent* trigEvt,
106  const std::string& hltTag)
107 {
108  std::vector<TrigCodes::TrigBitSet> partTrigBits(1);
109  const double maxDeltaR=0.1;
110  for(size_t filterNrInVec=0;filterNrInVec<filters.size();filterNrInVec++){
111  size_t filterNrInEvt = trigEvt->filterIndex(edm::InputTag(filters[filterNrInVec],"",hltTag).encode());
112  //const TrigCodes::TrigBitSet filterCode = TrigCodes::getCode(filters[filterNrInVec].c_str());
113  if(filterNrInEvt<trigEvt->sizeFilters()){ //filter found in event, something passes it
114  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
115  const trigger::TriggerObjectCollection & trigObjColl(trigEvt->getObjects());
116  for(trigger::Keys::const_iterator keyIt=trigKeys.begin();keyIt!=trigKeys.end();++keyIt){
117  float trigObjEta = trigObjColl[*keyIt].eta();
118  float trigObjPhi = trigObjColl[*keyIt].phi();
119  float trigObjE = trigObjColl[*keyIt].energy();
120  if (reco::deltaR(particle.superCluster()->eta(),particle.superCluster()->phi(),trigObjEta,trigObjPhi) < maxDeltaR){
121  hltData.HLTeta=trigObjEta;
122  hltData.HLTphi=trigObjPhi;
123  hltData.HLTenergy=trigObjE;
124  }//end dR<maxDeltaR trig obj match test
125  }//end loop over all objects passing filter`
126  }//end check if filter is present
127  }//end check if path has fired in the event
128 }//end loop over all filters
129 
130 }//end namespace declaration
131 
132 #endif
133 
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
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: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
T eta() const
std::vector< TPRegexp > filters
Definition: eve_filter.cc:25
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:30
bool first
Definition: L1TdeRCT.cc:79
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
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 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