CMS 3D CMS Logo

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