CMS 3D CMS Logo

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