CMS 3D CMS Logo

UtilFuncs.h
Go to the documentation of this file.
1 #ifndef DQMOffline_Trigger_UtilFuncs_h
2 #define DQMOffline_Trigger_UtilFuncs_h
3 
12 
13 namespace hltdqm {
14  inline bool passTrig(const float objEta,
15  float objPhi,
16  const trigger::TriggerEvent& trigEvt,
17  const std::string& filterName,
18  const std::string& processName) {
19  constexpr float kMaxDR2 = 0.1 * 0.1;
20 
21  edm::InputTag filterTag(filterName, "", processName);
22  trigger::size_type filterIndex = trigEvt.filterIndex(filterTag);
23  if (filterIndex < trigEvt.sizeFilters()) { //check that filter is in triggerEvent
24  const trigger::Keys& trigKeys = trigEvt.filterKeys(filterIndex);
25  const trigger::TriggerObjectCollection& trigObjColl(trigEvt.getObjects());
26  for (unsigned short trigKey : trigKeys) {
27  const trigger::TriggerObject& trigObj = trigObjColl[trigKey];
28  if (reco::deltaR2(trigObj.eta(), trigObj.phi(), objEta, objPhi) < kMaxDR2)
29  return true;
30  }
31  }
32  return false;
33  }
34 
35  //empty filters is auto pass
36  inline bool passTrig(const float objEta,
37  float objPhi,
38  const trigger::TriggerEvent& trigEvt,
39  const std::vector<std::string>& filterNames,
40  bool orFilters,
41  const std::string& processName) {
42  if (orFilters) {
43  if (filterNames.empty())
44  return true; //auto pass if empty filters
45  for (auto& filterName : filterNames) {
46  if (passTrig(objEta, objPhi, trigEvt, filterName, processName) == true)
47  return true;
48  }
49  return false;
50  } else {
51  for (auto& filterName : filterNames) {
52  if (passTrig(objEta, objPhi, trigEvt, filterName, processName) == false)
53  return false;
54  }
55  return true;
56  }
57  }
58 
59  //inspired by https://github.com/cms-sw/cmssw/blob/fc4f8bbe1258790e46e2d554aacea15c3e5d9afa/HLTrigger/HLTfilters/src/HLTHighLevel.cc#L124-L165
60  //triggers are ORed together
61  //empty pattern is auto pass
62  inline bool passTrig(const std::string& trigPattern,
64  const edm::TriggerResults& trigResults) {
65  if (trigPattern.empty())
66  return true;
67 
68  std::vector<std::string> trigNamesToPass;
69  if (edm::is_glob(trigPattern)) {
70  //matches is vector of string iterators
71  const auto& matches = edm::regexMatch(trigNames.triggerNames(), trigPattern);
72  for (auto& name : matches)
73  trigNamesToPass.push_back(*name);
74  } else {
75  trigNamesToPass.push_back(trigPattern); //not a pattern, much be a path
76  }
77  for (auto& trigName : trigNamesToPass) {
78  size_t pathIndex = trigNames.triggerIndex(trigName);
79  if (pathIndex < trigResults.size() && trigResults.accept(pathIndex))
80  return true;
81  }
82 
83  return false;
84  }
85 
86 } // namespace hltdqm
87 
88 #endif
trigger::TriggerObject::phi
float phi() const
Definition: TriggerObject.h:54
Handle.h
trigger::TriggerEvent::sizeFilters
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:146
trigger::TriggerEvent::filterKeys
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
trigNames
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:57
TriggerResults.h
edm::regexMatch
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
TriggerEvent.h
hltdqm
Definition: FunctionDefs.h:37
oniaPATMuonsWithTrigger_cff.matches
matches
Definition: oniaPATMuonsWithTrigger_cff.py:77
TriggerTypeDefs.h
edm::is_glob
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::HLTGlobalStatus::size
unsigned int size() const
Get number of paths stored.
Definition: HLTGlobalStatus.h:35
trigger::TriggerObject
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
EgHLTOffTrigSelection_cfi.trigName
trigName
Definition: EgHLTOffTrigSelection_cfi.py:8
deltaR.h
trigger::TriggerObjectCollection
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
TriggerNames.h
trigger::TriggerEvent::filterIndex
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:132
trigger::Keys
std::vector< size_type > Keys
Definition: TriggerTypeDefs.h:19
trigger::TriggerObject::eta
float eta() const
Definition: TriggerObject.h:53
trigger::TriggerEvent
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::TriggerEvent::getObjects
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TriggerObject.h
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
pdwgDoubleElectron_cfi.filterName
filterName
Definition: pdwgDoubleElectron_cfi.py:7
hltdqm::passTrig
bool passTrig(const float objEta, float objPhi, const trigger::TriggerEvent &trigEvt, const std::string &filterName, const std::string &processName)
Definition: UtilFuncs.h:14
edm::TriggerNames
Definition: TriggerNames.h:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::HLTGlobalStatus::accept
bool accept() const
Has at least one path accepted the event?
Definition: HLTGlobalStatus.h:49
edm::InputTag
Definition: InputTag.h:15
RegexMatch.h
edm::TriggerResults
Definition: TriggerResults.h:35