CMS 3D CMS Logo

L1TCommon.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 
7 namespace dqmoffline {
8  namespace l1t {
9 
10  std::vector<unsigned int> getTriggerIndices(const std::vector<std::string> &requestedTriggers,
11  const std::vector<std::string> &triggersInEvent) {
12  std::vector<unsigned int> triggerIndices;
13 
14  for (const auto &requestedTriggerName : requestedTriggers) {
15  std::string name(requestedTriggerName);
16  std::size_t wildcarPosition = name.find('*');
17  if (wildcarPosition != std::string::npos) {
18  // take everything up to the wildcard
19  name = name.substr(0, wildcarPosition - 1);
20  }
21 
22  unsigned int triggerIndex = 0;
23  for (const auto &triggerName : triggersInEvent) {
24  if (triggerName.find(name) != std::string::npos) {
25  triggerIndices.push_back(triggerIndex);
26  break;
27  }
28  ++triggerIndex;
29  }
30  }
31  return triggerIndices;
32  }
33 
34  std::vector<bool> getTriggerResults(const std::vector<unsigned int> &triggers,
36  std::vector<bool> results;
37  results.resize(triggers.size());
38 
39  for (unsigned int index = 0; index < triggers.size(); ++index) {
40  if (triggers[index] >= triggerResults.size()) {
41  results[index] = false;
42  continue;
43  }
44 
45  if (triggerResults.accept(triggers[index])) {
46  results[index] = true;
47  } else {
48  results[index] = false;
49  }
50  }
51  return results;
52  }
53 
54  std::vector<unsigned int> getFiredTriggerIndices(const std::vector<unsigned int> &triggers,
55  const std::vector<bool> &triggerResults) {
56  std::vector<unsigned int> results;
57  // std::copy_if instead?
58  for (unsigned int i = 0; i < triggerResults.size(); ++i) {
59  if (triggerResults[i]) {
60  results.push_back(triggers[i]);
61  }
62  }
63  return results;
64  }
65 
66  bool passesAnyTriggerFromList(const std::vector<unsigned int> &triggers,
69  if (std::count(results.begin(), results.end(), true) == 0) {
70  return false;
71  }
72  return true;
73  }
74 
75  trigger::TriggerObjectCollection getTriggerObjects(const std::vector<edm::InputTag> &hltFilters,
79 
80  for (const auto &filter : hltFilters) {
81  const unsigned filterIndex = triggerEvent.filterIndex(filter);
82 
83  if (filterIndex < triggerEvent.sizeFilters()) {
84  const trigger::Keys &triggerKeys(triggerEvent.filterKeys(filterIndex));
85  const size_t nTriggers = triggerEvent.filterIds(filterIndex).size();
86  for (size_t i = 0; i < nTriggers; ++i) {
87  results.push_back(triggerObjects[triggerKeys[i]]);
88  }
89  }
90  }
91  // sort by ET
92  typedef trigger::TriggerObject trigObj;
93  std::sort(results.begin(), results.end(), [](const trigObj &obj1, const trigObj &obj2) {
94  return obj1.et() > obj2.et();
95  });
96  return results;
97  }
98 
99  std::vector<edm::InputTag> getHLTFilters(const std::vector<unsigned int> &triggers,
101  const std::string triggerProcess) {
102  std::vector<edm::InputTag> results;
103  for (auto trigger : triggers) {
104  // For some reason various modules now come *after* "hltBoolEnd"
105  // Really just want module one index before "hltBoolEnd" - AWB 2022.09.28
106  unsigned int moduleIndex = 999999;
107  for (int ii = 0; ii < int(hltConfig.size(trigger)); ii++) {
108  if (hltConfig.moduleLabels(trigger)[ii] == "hltBoolEnd") {
109  moduleIndex = ii - 1;
110  break;
111  }
112  }
113  if (moduleIndex == 999999) {
114  edm::LogError("L1TCommon") << " Found no module label in trigger " << trigger << std::endl;
115  continue;
116  }
117  const std::vector<std::string> &modules(hltConfig.moduleLabels(trigger));
118  const std::string &module(modules[moduleIndex]);
119  edm::InputTag filterInputTag = edm::InputTag(module, "", triggerProcess);
120  results.push_back(filterInputTag);
121  }
122  return results;
123  }
124 
126  double phi,
127  double maxDeltaR,
130  typedef trigger::TriggerObject trigObj;
131  std::copy_if(
132  triggerObjects.begin(),
133  triggerObjects.end(),
134  std::back_inserter(results),
135  [eta, phi, maxDeltaR](const trigObj &obj) { return deltaR(obj.eta(), obj.phi(), eta, phi) < maxDeltaR; });
136  return results;
137  }
138 
139  } // namespace l1t
140 } // namespace dqmoffline
trigger::TriggerObjectCollection getMatchedTriggerObjects(double eta, double phi, double maxDeltaR, const trigger::TriggerObjectCollection triggerObjects)
Definition: L1TCommon.cc:125
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:26
trigger::TriggerObjectCollection getTriggerObjects(const std::vector< edm::InputTag > &hltFilters, const trigger::TriggerEvent &triggerEvent)
Definition: L1TCommon.cc:75
delete x;
Definition: CaloConfig.h:22
Log< level::Error, false > LogError
std::vector< unsigned int > getTriggerIndices(const std::vector< std::string > &requestedTriggers, const std::vector< std::string > &triggersInEvent)
Definition: L1TCommon.cc:10
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
std::vector< edm::InputTag > getHLTFilters(const std::vector< unsigned int > &triggers, const HLTConfigProvider &hltConfig, const std::string triggerProcess)
Definition: L1TCommon.cc:99
static std::string const triggerResults
Definition: EdmProvDump.cc:47
ii
Definition: cuy.py:589
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
std::vector< bool > getTriggerResults(const std::vector< unsigned int > &triggers, const edm::TriggerResults &triggerResults)
Definition: L1TCommon.cc:34
std::vector< size_type > Keys
results
Definition: mysort.py:8
std::vector< unsigned int > getFiredTriggerIndices(const std::vector< unsigned int > &triggers, const std::vector< bool > &triggerResults)
Definition: L1TCommon.cc:54
bool passesAnyTriggerFromList(const std::vector< unsigned int > &triggers, const edm::TriggerResults &triggerResults)
Definition: L1TCommon.cc:66