CMS 3D CMS Logo

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