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>
11 getTriggerIndices(const std::vector<std::string> &requestedTriggers,
12  const std::vector<std::string> &triggersInEvent) {
13  std::vector<unsigned int> triggerIndices;
14 
15  for (auto requestedTriggerName : requestedTriggers) {
16  std::string name(requestedTriggerName);
17  std::size_t wildcarPosition = name.find("*");
18  if (wildcarPosition != std::string::npos) {
19  // take everything up to the wildcard
20  name = name.substr(0, wildcarPosition - 1);
21  }
22 
23  unsigned int triggerIndex = 0;
24  for (auto triggerName : triggersInEvent) {
25  if (triggerName.find(name) != std::string::npos) {
26  triggerIndices.push_back(triggerIndex);
27  break;
28  }
29  ++triggerIndex;
30  }
31  }
32  return triggerIndices;
33 }
34 
35 std::vector<bool> getTriggerResults(const std::vector<unsigned int> &triggers,
37  std::vector<bool> results;
38  results.resize(triggers.size());
39 
40  for (unsigned int index = 0; index < triggers.size(); ++index) {
41 
42  if (triggers[index] >= triggerResults.size()) {
43  results[index] = false;
44  continue;
45  }
46 
47  if (triggerResults.accept(triggers[index])) {
48  results[index] = true;
49  } else {
50  results[index] = false;
51  }
52  }
53  return results;
54 }
55 
56 std::vector<unsigned int>
57 getFiredTriggerIndices(const std::vector<unsigned int> &triggers,
58  const std::vector<bool> &triggerResults) {
59  std::vector<unsigned int> results;
60  // std::copy_if instead?
61  for (unsigned int i = 0; i < triggerResults.size(); ++i) {
62  if (triggerResults[i]) {
63  results.push_back(triggers[i]);
64  }
65  }
66  return results;
67 }
68 
69 bool passesAnyTriggerFromList(const std::vector<unsigned int> &triggers,
71  std::vector<bool> results =
72  dqmoffline::l1t::getTriggerResults(triggers, triggerResults);
73  if (std::count(results.begin(), results.end(), true) == 0) {
74  return false;
75  }
76  return true;
77 }
78 
80 getTriggerObjects(const std::vector<edm::InputTag> &hltFilters,
81  const trigger::TriggerEvent &triggerEvent) {
84 
85  for (auto filter : hltFilters) {
86  const unsigned filterIndex = triggerEvent.filterIndex(filter);
87 
88  if (filterIndex < triggerEvent.sizeFilters()) {
89  const trigger::Keys triggerKeys(triggerEvent.filterKeys(filterIndex));
90  const size_t nTriggers = triggerEvent.filterIds(filterIndex).size();
91  for (size_t i = 0; i < nTriggers; ++i) {
92  results.push_back(triggerObjects[triggerKeys[i]]);
93  }
94  }
95  }
96  // sort by ET
97  typedef trigger::TriggerObject trigObj;
98  std::sort(results.begin(), results.end(),
99  [](const trigObj &obj1, const trigObj &obj2) {
100  return obj1.et() > obj2.et();
101  });
102  return results;
103 }
104 
105 std::vector<edm::InputTag>
106 getHLTFilters(const std::vector<unsigned int> &triggers,
107  const HLTConfigProvider &hltConfig,
108  const std::string triggerProcess) {
109  std::vector<edm::InputTag> results;
110  for (auto trigger : triggers) {
111  unsigned int hltIndexOffset(2);
112  unsigned int moduleIndex = hltConfig.size(trigger) - hltIndexOffset;
113  const std::vector<std::string> modules(hltConfig.moduleLabels(trigger));
114  std::string module(modules[moduleIndex]);
115  edm::InputTag filterInputTag = edm::InputTag(module, "", triggerProcess);
116  results.push_back(filterInputTag);
117  }
118  return results;
119 }
120 
122  double eta, double phi, double maxDeltaR,
125  typedef trigger::TriggerObject trigObj;
126  std::copy_if(triggerObjects.begin(), triggerObjects.end(),
127  std::back_inserter(results),
128  [eta, phi, maxDeltaR](const trigObj &obj) {
129  return deltaR(obj.eta(), obj.phi(), eta, phi) < maxDeltaR;
130  });
131  return results;
132 }
133 
134 } // l1t
135 } // dqmoffline
unsigned int size() const
number of trigger paths in trigger table
trigger::TriggerObjectCollection getMatchedTriggerObjects(double eta, double phi, double maxDeltaR, const trigger::TriggerObjectCollection triggerObjects)
Definition: L1TCommon.cc:121
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
bool accept() const
Has at least one path accepted the event?
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
trigger::TriggerObjectCollection getTriggerObjects(const std::vector< edm::InputTag > &hltFilters, const trigger::TriggerEvent &triggerEvent)
Definition: L1TCommon.cc:80
delete x;
Definition: CaloConfig.h:22
std::vector< unsigned int > getTriggerIndices(const std::vector< std::string > &requestedTriggers, const std::vector< std::string > &triggersInEvent)
Definition: L1TCommon.cc:11
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
const Vids & filterIds(trigger::size_type index) const
Definition: TriggerEvent.h:110
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
unsigned int size() const
Get number of paths stored.
std::vector< edm::InputTag > getHLTFilters(const std::vector< unsigned int > &triggers, const HLTConfigProvider &hltConfig, const std::string triggerProcess)
Definition: L1TCommon.cc:106
static std::string const triggerResults
Definition: EdmProvDump.cc:41
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
std::vector< bool > getTriggerResults(const std::vector< unsigned int > &triggers, const edm::TriggerResults &triggerResults)
Definition: L1TCommon.cc:35
std::vector< size_type > Keys
std::vector< unsigned int > getFiredTriggerIndices(const std::vector< unsigned int > &triggers, const std::vector< bool > &triggerResults)
Definition: L1TCommon.cc:57
bool passesAnyTriggerFromList(const std::vector< unsigned int > &triggers, const edm::TriggerResults &triggerResults)
Definition: L1TCommon.cc:69