CMS 3D CMS Logo

HLTEventAnalyzerAOD.cc
Go to the documentation of this file.
1 
16 
17 #include <cassert>
18 
19 //
20 // constructors and destructor
21 //
23  processName_(ps.getParameter<std::string>("processName")),
24  triggerName_(ps.getParameter<std::string>("triggerName")),
25  triggerResultsTag_(ps.getParameter<edm::InputTag>("triggerResults")),
26  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsTag_)),
27  triggerEventTag_(ps.getParameter<edm::InputTag>("triggerEvent")),
28  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventTag_)),
29  hltPrescaleProvider_(ps, consumesCollector(), *this)
30 {
31  using namespace std;
32  using namespace edm;
33 
34  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD configuration: " << endl
35  << " ProcessName = " << processName_ << endl
36  << " TriggerName = " << triggerName_ << endl
37  << " TriggerResultsTag = " << triggerResultsTag_.encode() << endl
38  << " TriggerEventTag = " << triggerEventTag_.encode() << endl;
39 
40 }
41 
43 
44 //
45 // member functions
46 //
47 void
50  desc.add<std::string>("processName","HLT");
51  desc.add<std::string>("triggerName","@");
52  desc.add<edm::InputTag>("triggerResults",edm::InputTag("TriggerResults","","HLT"));
53  desc.add<edm::InputTag>("triggerEvent",edm::InputTag("hltTriggerSummaryAOD","","HLT"));
54  descriptions.add("hltEventAnalyzerAOD", desc);
55 }
56 
57 void
58 HLTEventAnalyzerAOD::endRun(edm::Run const & iRun, edm::EventSetup const& iSetup) {}
59 
60 void
62 {
63  using namespace std;
64  using namespace edm;
65 
66  bool changed(true);
67  if (hltPrescaleProvider_.init(iRun,iSetup,processName_,changed)) {
68 
70 
71  if (changed) {
72  // check if trigger name in (new) config
73  if (triggerName_!="@") { // "@" means: analyze all triggers in config
74  const unsigned int n(hltConfig.size());
75  const unsigned int triggerIndex(hltConfig.triggerIndex(triggerName_));
76  if (triggerIndex>=n) {
77  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyze:"
78  << " TriggerName " << triggerName_
79  << " not available in (new) config!" << endl;
80  LogVerbatim("HLTEventAnalyzerAOD") << "Available TriggerNames are: " << endl;
81  hltConfig.dump("Triggers");
82  }
83  }
84  hltConfig.dump("ProcessName");
85  hltConfig.dump("GlobalTag");
86  hltConfig.dump("TableName");
87  hltConfig.dump("Streams");
88  hltConfig.dump("Datasets");
89  hltConfig.dump("PrescaleTable");
90  hltConfig.dump("ProcessPSet");
91  }
92  } else {
93  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyze:"
94  << " config extraction failure with process name "
95  << processName_ << endl;
96  }
97 }
98 
99 // ------------ method called to produce the data ------------
100 void
102 {
103  using namespace std;
104  using namespace edm;
105 
106  LogVerbatim("HLTEventAnalyzerAOD") << endl;
107 
108  // get event products
111  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerResults product from Event!" << endl;
112  return;
113  }
115  if (!triggerEventHandle_.isValid()) {
116  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerEvent product from Event!" << endl;
117  return;
118  }
119 
121 
122  // sanity check
123  assert(triggerResultsHandle_->size()==hltConfig.size());
124 
125  // analyze this event for the triggers requested
126  if (triggerName_=="@") {
127  const unsigned int n(hltConfig.size());
128  for (unsigned int i=0; i!=n; ++i) {
129  analyzeTrigger(iEvent,iSetup,hltConfig.triggerName(i));
130  }
131  } else {
132  analyzeTrigger(iEvent,iSetup,triggerName_);
133  }
134 
135  return;
136 
137 }
138 
139 void HLTEventAnalyzerAOD::analyzeTrigger(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& triggerName) {
140 
141  using namespace std;
142  using namespace edm;
143  using namespace reco;
144  using namespace trigger;
145 
146  LogVerbatim("HLTEventAnalyzerAOD") << endl;
147 
149 
150  const unsigned int n(hltConfig.size());
151  const unsigned int triggerIndex(hltConfig.triggerIndex(triggerName));
152  assert(triggerIndex==iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(triggerName));
153 
154  // abort on invalid trigger name
155  if (triggerIndex>=n) {
156  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyzeTrigger: path "
157  << triggerName << " - not found!" << endl;
158  return;
159  }
160 
161  const std::pair<int,int> prescales(hltPrescaleProvider_.prescaleValues(iEvent,iSetup,triggerName));
162  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyzeTrigger: path "
163  << triggerName << " [" << triggerIndex << "] "
164  << "prescales L1T,HLT: " << prescales.first << "," << prescales.second
165  << endl;
166  const std::pair<std::vector<std::pair<std::string,int> >,int> prescalesInDetail(hltPrescaleProvider_.prescaleValuesInDetail(iEvent,iSetup,triggerName));
167  std::ostringstream message;
168  for (unsigned int i=0; i<prescalesInDetail.first.size(); ++i) {
169  message << " " << i << ":" << prescalesInDetail.first[i].first << "/" << prescalesInDetail.first[i].second;
170  }
171  LogVerbatim("HLTEventAnalyzerAOD") << "HLTEventAnalyzerAOD::analyzeTrigger: path "
172  << triggerName << " [" << triggerIndex << "] "
173  << endl
174  << "prescales L1T: " << prescalesInDetail.first.size() << message.str()
175  << endl
176  << " prescale HLT: " << prescalesInDetail.second
177  << endl;
178 
179  // modules on this trigger path
180  const unsigned int m(hltConfig.size(triggerIndex));
181  const vector<string>& moduleLabels(hltConfig.moduleLabels(triggerIndex));
182 
183  // Results from TriggerResults product
184  LogVerbatim("HLTEventAnalyzerAOD") << " Trigger path status:"
185  << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
186  << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
187  << " Error =" << triggerResultsHandle_->error(triggerIndex)
188  << endl;
189  const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
190  LogVerbatim("HLTEventAnalyzerAOD") << " Last active module - label/type: "
191  << moduleLabels[moduleIndex] << "/" << hltConfig.moduleType(moduleLabels[moduleIndex])
192  << " [" << moduleIndex << " out of 0-" << (m-1) << " on this path]"
193  << endl;
194  assert (moduleIndex<m);
195 
196  // Results from TriggerEvent product - Attention: must look only for
197  // modules actually run in this path for this event!
198  for (unsigned int j=0; j<=moduleIndex; ++j) {
199  const string& moduleLabel(moduleLabels[j]);
200  const string moduleType(hltConfig.moduleType(moduleLabel));
201  // check whether the module is packed up in TriggerEvent product
202  const unsigned int filterIndex(triggerEventHandle_->filterIndex(InputTag(moduleLabel,"",processName_)));
203  if (filterIndex<triggerEventHandle_->sizeFilters()) {
204  LogVerbatim("HLTEventAnalyzerAOD") << " 'L3' filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType << endl;
205  const Vids& VIDS (triggerEventHandle_->filterIds(filterIndex));
206  const Keys& KEYS(triggerEventHandle_->filterKeys(filterIndex));
207  const size_type nI(VIDS.size());
208  const size_type nK(KEYS.size());
209  assert(nI==nK);
210  const size_type n(max(nI,nK));
211  LogVerbatim("HLTEventAnalyzerAOD") << " " << n << " accepted 'L3' objects found: " << endl;
213  for (size_type i=0; i!=n; ++i) {
214  const TriggerObject& TO(TOC[KEYS[i]]);
215  LogVerbatim("HLTEventAnalyzerAOD") << " " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "
216  << TO.id() << " " << TO.pt() << " " << TO.eta() << " " << TO.phi() << " " << TO.mass()
217  << endl;
218  }
219  }
220  }
221 
222  return;
223 }
unsigned int size() const
number of trigger paths in trigger table
void dump(const std::string &what) const
Dumping config info to cout.
bool wasrun() const
Was at least one path run?
virtual void analyzeTrigger(const edm::Event &, const edm::EventSetup &, const std::string &triggerName)
std::pair< std::vector< std::pair< std::string, int > >, int > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
const std::string moduleType(const std::string &module) const
C++ class name of module.
int id() const
getters
Definition: TriggerObject.h:55
const std::string & triggerName(unsigned int triggerIndex) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
float phi() const
Definition: TriggerObject.h:58
const edm::InputTag triggerResultsTag_
const edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
const std::string triggerName_
edm::Handle< trigger::TriggerEvent > triggerEventHandle_
float eta() const
Definition: TriggerObject.h:57
const std::string processName_
module config parameters
uint16_t size_type
std::string encode() const
Definition: InputTag.cc:166
HLTPrescaleProvider hltPrescaleProvider_
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
const Vids & filterIds(trigger::size_type index) const
Definition: TriggerEvent.h:110
int iEvent
Definition: GenABIO.cc:230
const edm::InputTag triggerEventTag_
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
unsigned int size() const
Get number of paths stored.
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
void beginRun(edm::Run const &, edm::EventSetup const &) override
bool error() const
Has any path encountered an error (exception)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
bool isValid() const
Definition: HandleBase.h:74
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
edm::Handle< edm::TriggerResults > triggerResultsHandle_
additional class data memebers
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
~HLTEventAnalyzerAOD() override
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< size_type > Keys
HLTEventAnalyzerAOD(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::pair< int, int > 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.
HLTConfigProvider const & hltConfigProvider() const
fixed size matrix
HLT enums.
float mass() const
Definition: TriggerObject.h:59
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:301
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
std::vector< int > Vids
Definition: Run.h:43