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("ProcessName");
66  hltConfig_.dump("GlobalTag");
67  hltConfig_.dump("TableName");
68  hltConfig_.dump("Streams");
69  hltConfig_.dump("Datasets");
70  hltConfig_.dump("PrescaleTable");
71  hltConfig_.dump("ProcessPSet");
72  }
73  } else {
74  cout << "HLTEventAnalyzerAOD::analyze:"
75  << " config extraction failure with process name "
76  << processName_ << endl;
77  }
78 }
79 
80 // ------------ method called to produce the data ------------
81 void
83 {
84  using namespace std;
85  using namespace edm;
86 
87  cout << endl;
88 
89  // get event products
92  cout << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerResults product from Event!" << endl;
93  return;
94  }
97  cout << "HLTEventAnalyzerAOD::analyze: Error in getting TriggerEvent product from Event!" << endl;
98  return;
99  }
100  // sanity check
101  assert(triggerResultsHandle_->size()==hltConfig_.size());
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 {
110  analyzeTrigger(iEvent,iSetup,triggerName_);
111  }
112 
113  return;
114 
115 }
116 
117 void HLTEventAnalyzerAOD::analyzeTrigger(const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& triggerName) {
118 
119  using namespace std;
120  using namespace edm;
121  using namespace reco;
122  using namespace trigger;
123 
124  cout << endl;
125 
126  const unsigned int n(hltConfig_.size());
127  const unsigned int triggerIndex(hltConfig_.triggerIndex(triggerName));
128  assert(triggerIndex==iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(triggerName));
129 
130  // abort on invalid trigger name
131  if (triggerIndex>=n) {
132  cout << "HLTEventAnalyzerAOD::analyzeTrigger: path "
133  << triggerName << " - not found!" << endl;
134  return;
135  }
136 
137  const std::pair<int,int> prescales(hltConfig_.prescaleValues(iEvent,iSetup,triggerName));
138  cout << "HLTEventAnalyzerAOD::analyzeTrigger: path "
139  << triggerName << " [" << triggerIndex << "] "
140  << "prescales L1T,HLT: " << prescales.first << "," << prescales.second
141  << endl;
142 
143  // modules on this trigger path
144  const unsigned int m(hltConfig_.size(triggerIndex));
145  const vector<string>& moduleLabels(hltConfig_.moduleLabels(triggerIndex));
146 
147  // Results from TriggerResults product
148  cout << " Trigger path status:"
149  << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
150  << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
151  << " Error =" << triggerResultsHandle_->error(triggerIndex)
152  << endl;
153  const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
154  cout << " Last active module - label/type: "
155  << moduleLabels[moduleIndex] << "/" << hltConfig_.moduleType(moduleLabels[moduleIndex])
156  << " [" << moduleIndex << " out of 0-" << (m-1) << " on this path]"
157  << endl;
158  assert (moduleIndex<m);
159 
160  // Results from TriggerEvent product - Attention: must look only for
161  // modules actually run in this path for this event!
162  for (unsigned int j=0; j<=moduleIndex; ++j) {
163  const string& moduleLabel(moduleLabels[j]);
164  const string moduleType(hltConfig_.moduleType(moduleLabel));
165  // check whether the module is packed up in TriggerEvent product
166  const unsigned int filterIndex(triggerEventHandle_->filterIndex(InputTag(moduleLabel,"",processName_)));
167  if (filterIndex<triggerEventHandle_->sizeFilters()) {
168  cout << " 'L3' filter in slot " << j << " - label/type " << moduleLabel << "/" << moduleType << endl;
169  const Vids& VIDS (triggerEventHandle_->filterIds(filterIndex));
170  const Keys& KEYS(triggerEventHandle_->filterKeys(filterIndex));
171  const size_type nI(VIDS.size());
172  const size_type nK(KEYS.size());
173  assert(nI==nK);
174  const size_type n(max(nI,nK));
175  cout << " " << n << " accepted 'L3' objects found: " << endl;
176  const TriggerObjectCollection& TOC(triggerEventHandle_->getObjects());
177  for (size_type i=0; i!=n; ++i) {
178  const TriggerObject& TO(TOC[KEYS[i]]);
179  cout << " " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "
180  << TO.id() << " " << TO.pt() << " " << TO.eta() << " " << TO.phi() << " " << TO.mass()
181  << endl;
182  }
183  }
184  }
185 
186  return;
187 }
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:207
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:164
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:361
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)
d&#39;tor
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:61
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::vector< int > Vids
Definition: Run.h:36