CMS 3D CMS Logo

HLTEventAnalyzerAOD.cc
Go to the documentation of this file.
1 
15 
16 #include <cassert>
17 
18 //
19 // constructor
20 //
22  : processName_(ps.getParameter<std::string>("processName")),
23  triggerName_(ps.getParameter<std::string>("triggerName")),
24  triggerResultsTag_(ps.getParameter<edm::InputTag>("triggerResults")),
25  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsTag_)),
26  triggerEventTag_(ps.getParameter<edm::InputTag>("triggerEvent")),
27  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventTag_)),
28  verbose_(ps.getParameter<bool>("verbose")),
29  hltPrescaleProvider_(ps, consumesCollector(), *this) {
30  LOG(logMsgType_) << logMsgType_ << " configuration:\n"
31  << " ProcessName = " << processName_ << "\n"
32  << " TriggerName = " << triggerName_ << "\n"
33  << " TriggerResultsTag = " << triggerResultsTag_.encode() << "\n"
34  << " TriggerEventTag = " << triggerEventTag_.encode();
35 }
36 
37 //
38 // member functions
39 //
42  desc.add<std::string>("processName", "HLT");
43  desc.add<std::string>("triggerName", "@")
44  ->setComment("name of trigger Path to consider (use \"@\" to consider all Paths)");
45  desc.add<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults", "", "HLT"));
46  desc.add<edm::InputTag>("triggerEvent", edm::InputTag("hltTriggerSummaryAOD", "", "HLT"));
47  desc.add<unsigned int>("stageL1Trigger", 1);
48  desc.add<bool>("verbose", true)->setComment("enable verbose mode");
49  descriptions.add("hltEventAnalyzerAODDefault", desc);
50 }
51 
52 void HLTEventAnalyzerAOD::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
53  bool changed(true);
54  if (hltPrescaleProvider_.init(iRun, iSetup, processName_, changed)) {
56 
57  if (changed) {
58  // check if trigger name in (new) config
59  if (triggerName_ != "@") { // "@" means: analyze all triggers in config
60  const unsigned int n(hltConfig.size());
61  const unsigned int triggerIndex(hltConfig.triggerIndex(triggerName_));
62  if (triggerIndex >= n) {
63  LOG(logMsgType_) << logMsgType_ << "::beginRun: TriggerName " << triggerName_
64  << " not available in (new) config!";
65  LOG(logMsgType_) << "Available TriggerNames are:";
66  hltConfig.dump("Triggers");
67  }
68  }
69  // in verbose mode, print process info to stdout
70  if (verbose_) {
71  hltConfig.dump("ProcessName");
72  hltConfig.dump("GlobalTag");
73  hltConfig.dump("TableName");
74  hltConfig.dump("Streams");
75  hltConfig.dump("Datasets");
76  hltConfig.dump("PrescaleTable");
77  hltConfig.dump("ProcessPSet");
78  }
79  }
80  } else {
81  LOG(logMsgType_) << logMsgType_ << "::beginRun: config extraction failure with process name " << processName_;
82  }
83 }
84 
86  // get event products
89  LOG(logMsgType_) << logMsgType_ << "::analyze: Error in getting TriggerResults product from Event!";
90  return;
91  }
94  LOG(logMsgType_) << logMsgType_ << "::analyze: Error in getting TriggerEvent product from Event!";
95  return;
96  }
97 
99 
100  // sanity check
102 
103  // analyze this event for the triggers requested
104  if (triggerName_ == "@") {
105  const unsigned int n(hltConfig.size());
106  for (unsigned int i = 0; i != n; ++i) {
107  analyzeTrigger(iEvent, iSetup, hltConfig.triggerName(i));
108  }
109  } else {
111  }
112 
113  return;
114 }
115 
117  const edm::EventSetup& iSetup,
118  const std::string& triggerName) {
120 
121  const unsigned int n(hltConfig.size());
122  const unsigned int triggerIndex(hltConfig.triggerIndex(triggerName));
123  assert(triggerIndex == iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(triggerName));
124 
125  // abort on invalid trigger name
126  if (triggerIndex >= n) {
127  LOG(logMsgType_) << logMsgType_ << "::analyzeTrigger: path " << triggerName << " - not found!";
128  return;
129  }
130 
131  auto const prescales = hltPrescaleProvider_.prescaleValues<double>(iEvent, iSetup, triggerName);
132 
133  LOG(logMsgType_) << logMsgType_ << "::analyzeTrigger: path " << triggerName << " [" << triggerIndex
134  << "] prescales L1T,HLT: " << prescales.first << "," << prescales.second;
135 
136  auto const prescalesInDetail = hltPrescaleProvider_.prescaleValuesInDetail<double>(iEvent, iSetup, triggerName);
137  {
138  LOG logtmp(logMsgType_);
139  logtmp << logMsgType_ << "::analyzeTrigger: path " << triggerName << " [" << triggerIndex
140  << "]\n prescales L1T: " << prescalesInDetail.first.size();
141  for (size_t idx = 0; idx < prescalesInDetail.first.size(); ++idx) {
142  logtmp << " " << idx << ":" << prescalesInDetail.first[idx].first << "/" << prescalesInDetail.first[idx].second;
143  }
144  logtmp << "\n prescale HLT: " << prescalesInDetail.second;
145  }
146 
147  // results from TriggerResults product
148  LOG(logMsgType_) << " Trigger path status:"
149  << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
150  << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
151  << " Error=" << triggerResultsHandle_->error(triggerIndex);
152 
153  // modules on this trigger path
154  const unsigned int m(hltConfig.size(triggerIndex));
155  const std::vector<std::string>& moduleLabels(hltConfig.moduleLabels(triggerIndex));
156  assert(m == moduleLabels.size());
157 
158  // skip empty Paths
159  if (m == 0) {
160  LOG(logMsgType_) << logMsgType_ << "::analyzeTrigger: path " << triggerName << " [" << triggerIndex
161  << "] is empty!";
162  return;
163  }
164 
165  // index of last module executed in this Path
166  const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
167  assert(moduleIndex < m);
168 
169  LOG(logMsgType_) << " Last active module - label/type: " << moduleLabels[moduleIndex] << "/"
170  << hltConfig.moduleType(moduleLabels[moduleIndex]) << " [" << moduleIndex << " out of 0-" << (m - 1)
171  << " on this path]";
172 
173  // results from TriggerEvent product
174  // Attention: must look only for modules actually run in this path for this event!
175  for (unsigned int j = 0; j <= moduleIndex; ++j) {
176  const std::string& moduleLabel(moduleLabels[j]);
177  const std::string moduleType(hltConfig.moduleType(moduleLabel));
178 
179  // check whether the module is packed up in TriggerEvent product
180  const unsigned int filterIndex(triggerEventHandle_->filterIndex(edm::InputTag(moduleLabel, "", processName_)));
181  if (filterIndex < triggerEventHandle_->sizeFilters()) {
182  LOG(logMsgType_) << " 'L3' filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType;
183 
184  const trigger::Vids& VIDS(triggerEventHandle_->filterIds(filterIndex));
185  const trigger::Keys& KEYS(triggerEventHandle_->filterKeys(filterIndex));
186  const trigger::size_type nI(VIDS.size());
187  const trigger::size_type nK(KEYS.size());
188  assert(nI == nK);
189 
190  LOG(logMsgType_) << " " << nI << " accepted 'L3' objects found: ";
192  for (trigger::size_type idx = 0; idx < nI; ++idx) {
193  const trigger::TriggerObject& TO(TOC[KEYS[idx]]);
194  LOG(logMsgType_) << " " << idx << " " << VIDS[idx] << "/" << KEYS[idx] << ": " << TO.id() << " " << TO.pt()
195  << " " << TO.eta() << " " << TO.phi() << " " << TO.mass();
196  }
197  }
198  }
199 
200  return;
201 }
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
bool accept() const
Has at least one path accepted the event?
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
virtual void analyzeTrigger(const edm::Event &, const edm::EventSetup &, const std::string &triggerName)
bool error() const
Has any path encountered an error (exception)
bool const verbose_
additional class data members
std::string encode() const
Definition: InputTag.cc:159
const edm::InputTag triggerResultsTag_
const edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string triggerName_
std::pair< std::vector< std::pair< std::string, TL1 > >, THLT > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
HLTConfigProvider const & hltConfigProvider() const
edm::Handle< trigger::TriggerEvent > triggerEventHandle_
const std::string processName_
module config parameters
assert(be >=bs)
uint16_t size_type
HLTPrescaleProvider hltPrescaleProvider_
bool wasrun() const
Was at least one path run?
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
unsigned int size() const
Get number of paths stored.
int iEvent
Definition: GenABIO.cc:224
const edm::InputTag triggerEventTag_
std::pair< TL1, THLT > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
static constexpr const char * logMsgType_
void beginRun(edm::Run const &, edm::EventSetup const &) override
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
int id() const
getters
Definition: TriggerObject.h:51
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
edm::Handle< edm::TriggerResults > triggerResultsHandle_
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
const Vids & filterIds(trigger::size_type index) const
Definition: TriggerEvent.h:117
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< size_type > Keys
HLTEventAnalyzerAOD(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
edm::LogVerbatim LOG
HLT enums.
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
std::vector< int > Vids
Definition: Run.h:45