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  triggerEventTag_(ps.getParameter<edm::InputTag>("triggerEvent"))
25 {
26  using namespace std;
27  using namespace edm;
28 
29  cout << "HLTEventAnalyzerAOD configuration: " << endl
30  << " ProcessName = " << processName_ << endl
31  << " TriggerName = " << triggerName_ << endl
32  << " TriggerResultsTag = " << triggerResultsTag_.encode() << endl
33  << " TriggerEventTag = " << triggerEventTag_.encode() << endl;
34 
35 }
36 
38 {
39 }
40 
41 //
42 // member functions
43 //
44 void
46 {
47  using namespace std;
48  using namespace edm;
49 
50  bool changed(true);
51  if (hltConfig_.init(iRun,iSetup,processName_,changed)) {
52  if (changed) {
53  // check if trigger name in (new) config
54  if (triggerName_!="@") { // "@" means: analyze all triggers in config
55  const unsigned int n(hltConfig_.size());
56  const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName_));
57  if (triggerIndex>=n) {
58  cout << "HLTEventAnalyzerAOD::analyze:"
59  << " TriggerName " << triggerName_
60  << " not available in (new) config!" << endl;
61  cout << "Available TriggerNames are: " << endl;
62  hltConfig_.dump("Triggers");
63  }
64  }
65  hltConfig_.dump("Streams");
66  hltConfig_.dump("Datasets");
67  hltConfig_.dump("PrescaleTable");
68  hltConfig_.dump("ProcessPSet");
69  }
70  } else {
71  cout << "HLTEventAnalyzerAOD::analyze:"
72  << " config extraction failure with process name "
73  << processName_ << endl;
74  }
75 }
76 
77 // ------------ method called to produce the data ------------
78 void
80 {
81  using namespace std;
82  using namespace edm;
83 
84  cout << endl;
85 
86  // get event products
89  cout << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerResults product from Event!" << endl;
90  return;
91  }
94  cout << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerEvent product from Event!" << endl;
95  return;
96  }
97  // sanity check
98  assert(triggerResultsHandle_->size()==hltConfig_.size());
99 
100  // analyze this event for the triggers requested
101  if (triggerName_=="@") {
102  const unsigned int n(hltConfig_.size());
103  for (unsigned int i=0; i!=n; ++i) {
104  analyzeTrigger(iEvent,iSetup,hltConfig_.triggerName(i));
105  }
106  } else {
107  analyzeTrigger(iEvent,iSetup,triggerName_);
108  }
109 
110  return;
111 
112 }
113 
114 void HLTEventAnalyzerAOD::analyzeTrigger(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& triggerName) {
115 
116  using namespace std;
117  using namespace edm;
118  using namespace reco;
119  using namespace trigger;
120 
121  cout << endl;
122 
123  const unsigned int n(hltConfig_.size());
124  const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName));
125  assert(triggerIndex==iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(triggerName));
126 
127  // abort on invalid trigger name
128  if (triggerIndex>=n) {
129  cout << "HLTEventAnalyzerAOD::analyzeTrigger: path "
130  << triggerName << " - not found!" << endl;
131  return;
132  }
133 
134  const std::pair<int,int> prescales(hltConfig_.prescaleValues(iEvent,iSetup,triggerName));
135  cout << "HLTEventAnalyzerAOD::analyzeTrigger: path "
136  << triggerName << " [" << triggerIndex << "] "
137  << "prescales L1T,HLT: " << prescales.first << "," << prescales.second
138  << endl;
139 
140  // modules on this trigger path
141  const unsigned int m(hltConfig_.size(triggerIndex));
142  const vector<string>& moduleLabels(hltConfig_.moduleLabels(triggerIndex));
143 
144  // Results from TriggerResults product
145  cout << " Trigger path status:"
146  << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
147  << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
148  << " Error =" << triggerResultsHandle_->error(triggerIndex)
149  << endl;
150  const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
151  cout << " Last active module - label/type: "
152  << moduleLabels[moduleIndex] << "/" << hltConfig_.moduleType(moduleLabels[moduleIndex])
153  << " [" << moduleIndex << " out of 0-" << (m-1) << " on this path]"
154  << endl;
155  assert (moduleIndex<m);
156 
157  // Results from TriggerEvent product - Attention: must look only for
158  // modules actually run in this path for this event!
159  for (unsigned int j=0; j<=moduleIndex; ++j) {
160  const string& moduleLabel(moduleLabels[j]);
161  const string moduleType(hltConfig_.moduleType(moduleLabel));
162  // check whether the module is packed up in TriggerEvent product
163  const unsigned int filterIndex(triggerEventHandle_->filterIndex(InputTag(moduleLabel,"",processName_)));
164  if (filterIndex<triggerEventHandle_->sizeFilters()) {
165  cout << " 'L3' filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType << endl;
166  const Vids& VIDS (triggerEventHandle_->filterIds(filterIndex));
167  const Keys& KEYS(triggerEventHandle_->filterKeys(filterIndex));
168  const size_type nI(VIDS.size());
169  const size_type nK(KEYS.size());
170  assert(nI==nK);
171  const size_type n(max(nI,nK));
172  cout << " " << n << " accepted 'L3' objects found: " << endl;
173  const TriggerObjectCollection& TOC(triggerEventHandle_->getObjects());
174  for (size_type i=0; i!=n; ++i) {
175  const TriggerObject& TO(TOC[KEYS[i]]);
176  cout << " " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "
177  << TO.id() << " " << TO.pt() << " " << TO.eta() << " " << TO.phi() << " " << TO.mass()
178  << endl;
179  }
180  }
181  }
182 
183  return;
184 }
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:57
const std::string & triggerName(unsigned int triggerIndex) const
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
float phi() const
Definition: TriggerObject.h:60
edm::InputTag triggerEventTag_
edm::Handle< trigger::TriggerEvent > triggerEventHandle_
float eta() const
Definition: TriggerObject.h:59
uint16_t size_type
std::string encode() const
Definition: InputTag.cc:72
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:24
int iEvent
Definition: GenABIO.cc:243
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::InputTag triggerResultsTag_
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
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:83
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)
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:41
float mass() const
Definition: TriggerObject.h:61
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::vector< int > Vids
Definition: Run.h:32
const std::string * moduleLabel() const
Definition: HLTadd.h:40