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