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,
68  std::vector<bool> results = dqmoffline::l1t::getTriggerResults(triggers, triggerResults);
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  unsigned int hltIndexOffset(2);
105  unsigned int moduleIndex = hltConfig.size(trigger) - hltIndexOffset;
106  const std::vector<std::string> &modules(hltConfig.moduleLabels(trigger));
107  std::string module(modules[moduleIndex]);
108  edm::InputTag filterInputTag = edm::InputTag(module, "", triggerProcess);
109  results.push_back(filterInputTag);
110  }
111  return results;
112  }
113 
115  double phi,
116  double maxDeltaR,
119  typedef trigger::TriggerObject trigObj;
120  std::copy_if(
121  triggerObjects.begin(),
122  triggerObjects.end(),
123  std::back_inserter(results),
124  [eta, phi, maxDeltaR](const trigObj &obj) { return deltaR(obj.eta(), obj.phi(), eta, phi) < maxDeltaR; });
125  return results;
126  }
127 
128  } // namespace l1t
129 } // namespace dqmoffline
trigger::TriggerObjectCollection getMatchedTriggerObjects(double eta, double phi, double maxDeltaR, const trigger::TriggerObjectCollection triggerObjects)
Definition: L1TCommon.cc:114
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::TriggerObjectCollection getTriggerObjects(const std::vector< edm::InputTag > &hltFilters, const trigger::TriggerEvent &triggerEvent)
Definition: L1TCommon.cc:75
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: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:44
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
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