DESY Hbb Analysis Framework
EventInfo.cc
Go to the documentation of this file.
1 
8 //
9 // Original Author: Roberval Walsh Bastos Rangel
10 // Created: Mon, 20 Oct 2014 14:24:08 GMT
11 //
12 //
13 
14 // system include files
15 //
16 #include <iostream>
17 
18 
19 // user include files
20 #include "FWCore/Framework/interface/Event.h"
21 //
22 #include "FWCore/ParameterSet/interface/ParameterSet.h"
23 
25 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
26 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
27 #include "DataFormats/Scalers/interface/LumiScalers.h"
28 
29 
30 //
31 // class declaration
32 //
33 
34 using namespace analysis;
35 using namespace analysis::ntuple;
36 
37 //
38 // constructors and destructor
39 //
41 {
42  // default constructor
43 }
44 
45 EventInfo::EventInfo(edm::Service<TFileService> & fs)
46 {
47  std::string name = "EventInfo";
48  tree_ = fs->make<TTree>(name.c_str(),name.c_str());
49 
50  // event output info
51  tree_->Branch("event", &event_, "event/I");
52  tree_->Branch("run" , &run_ , "run/I");
53  tree_->Branch("lumisection" , &lumi_ , "lumisection/I");
54  tree_->Branch("bx" , &bx_ , "bx/I");
55  tree_->Branch("orbit", &orbit_, "orbit/I");
56 
57  do_pu_ = false;
58  do_gen_ = false;
59  do_lumi_ = false;
60  do_rho_ = false;
61 
62 
63 }
64 
65 EventInfo::EventInfo(TFileDirectory & dir)
66 {
67  std::string name = "EventInfo";
68  tree_ = dir.make<TTree>(name.c_str(),name.c_str());
69 
70  // event output info
71  tree_->Branch("event", &event_, "event/I");
72  tree_->Branch("run" , &run_ , "run/I");
73  tree_->Branch("lumisection" , &lumi_ , "lumisection/I");
74  tree_->Branch("bx" , &bx_ , "bx/I");
75  tree_->Branch("orbit", &orbit_, "orbit/I");
76 
77  do_pu_ = false;
78  do_gen_ = false;
79  do_lumi_ = false;
80 
81 }
82 
84 {
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 }
88 
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called for each event ------------
95 void EventInfo::Fill(const edm::Event& event)
96 {
97  using namespace edm;
98 
99  const edm::EventAuxiliary evt = event.eventAuxiliary();
100 
101  event_ = evt.event();
102  run_ = evt.run();
103  lumi_ = evt.luminosityBlock();
104  orbit_ = evt.orbitNumber();
105  bx_ = evt.bunchCrossing();
106 
107  if ( do_pu_ )
108  {
109  ReadPileupInfo(event);
110  }
111  else
112  {
113  n_pu_ = -1;
114  n_true_pu_ = -1;
115  }
116 
117  if ( do_gen_ )
118  {
119  ReadGenEventInfo(event);
120  }
121  else
122  {
123  genWeight_ = -1.;
124  genScale_ = -1.;
125  pdfid1_ = 0;
126  pdfid2_ = 0;
127  pdfx1_ = -1.;
128  pdfx2_ = -1.;
129 
130  }
131 
132  if ( do_lumi_ )
133  {
134  ReadLumiScalers(event);
135  }
136 
137  if ( do_rho_ )
138  {
139  ReadFixedGridRhoInfo(event);
140  }
141 
142  tree_ -> Fill();
143 
144 
145 }
146 
147 // ------------ method called once each job just before starting event loop ------------
149 {
150 }
151 
152 // ------------ other methods ----------------
154 {
155  return tree_;
156 }
157 
158 void EventInfo::PileupInfo(const edm::InputTag& tag)
159 {
160  do_pu_ = true;
161 
162  puInfo_ = tag;
163 
164  tree_->Branch("nPileup" , &n_pu_ , "nPileup/I");
165  tree_->Branch("nTruePileup" , &n_true_pu_, "nTruePileup/F");
166 
167 }
168 
169 void EventInfo::ReadPileupInfo(const edm::Event& event)
170 {
171  using namespace edm;
172 
173  //
174  edm::Handle<std::vector<PileupSummaryInfo> > handler;
175  event.getByLabel(puInfo_, handler);
176 
177  std::vector<PileupSummaryInfo> pileup_infos = *(handler.product());
178 
179 // Take the first entry - should be enough
180  PileupSummaryInfo pileup_info = pileup_infos.at(0);
181  n_true_pu_ = pileup_info.getTrueNumInteractions();
182  n_pu_ = pileup_info.getPU_NumInteractions();
183 
184 
185 }
186 
187 // GenEventInfoProduct
188 void EventInfo::GenEventInfo(const edm::InputTag& tag)
189 {
190  do_gen_ = true;
191 
192  genInfo_ = tag;
193 
194  tree_->Branch("genWeight" , &genWeight_ , "genWeight/D");
195  tree_->Branch("genScale" , &genScale_ , "genScale/D");
196  tree_->Branch("pdfid1" , &pdfid1_ , "pdfid1/I");
197  tree_->Branch("pdfid2" , &pdfid2_ , "pdfid2/I");
198  tree_->Branch("pdfx1" , &pdfx1_ , "pdfx1/D");
199  tree_->Branch("pdfx2" , &pdfx2_ , "pdfx2/D");
200 
201 }
202 
203 void EventInfo::ReadGenEventInfo(const edm::Event& event)
204 {
205  using namespace edm;
206 
207  //
208  edm::Handle<GenEventInfoProduct> hepmc;
209  event.getByLabel(genInfo_, hepmc);
210 
211  if ( hepmc.isValid() )
212  {
213  genWeight_ = hepmc -> weight();
214  genScale_ = hepmc -> qScale();
215  pdfid1_ = hepmc -> pdf() -> id.first;
216  pdfid2_ = hepmc -> pdf() -> id.second;
217  pdfx1_ = hepmc -> pdf() -> x.first;
218  pdfx2_ = hepmc -> pdf() -> x.second;
219  }
220 
221 
222 }
223 
224 void EventInfo::LumiScalersInfo(const edm::InputTag& tag)
225 {
226  do_lumi_ = true;
227 
228  lumiScalers_ = tag;
229 
230  // lumiScalers
231  tree_->Branch("instantLumi", &instLumi_,"instantLumi/F");
232  tree_->Branch("lumiPileup", &lumiPU_,"lumiPileup/F");
233 }
234 
235 void EventInfo::ReadLumiScalers(const edm::Event& event)
236 {
237  edm::Handle<LumiScalersCollection> lumis;
238  event.getByLabel(lumiScalers_, lumis);
239 
240  instLumi_ = lumis -> begin() -> instantLumi();
241  lumiPU_ = lumis -> begin() -> pileup();
242 
243 }
244 
245 void EventInfo::FixedGridRhoInfo(const edm::InputTag& tag)
246 {
247  do_rho_ = true;
248  rho_collection_ = tag;
249 
250  tree_->Branch("rho",&rho_,"rho/D");
251 
252 }
253 
254 void EventInfo::ReadFixedGridRhoInfo(const edm::Event& event)
255 {
256  edm::Handle<double> rhoHandler;
257  event.getByLabel(rho_collection_, rhoHandler);
258  rho_ = *(rhoHandler.product());
259 
260 }
void ReadGenEventInfo(const edm::Event &)
Definition: EventInfo.cc:203
void ReadLumiScalers(const edm::Event &)
Definition: EventInfo.cc:235
void ReadFixedGridRhoInfo(const edm::Event &)
Definition: EventInfo.cc:254
void ReadPileupInfo(const edm::Event &)
Definition: EventInfo.cc:169
edm::InputTag lumiScalers_
Definition: EventInfo.h:94
void Fill(const edm::Event &)
Definition: EventInfo.cc:95
void PileupInfo(const edm::InputTag &)
Definition: EventInfo.cc:158
void LumiScalersInfo(const edm::InputTag &)
Definition: EventInfo.cc:224
void GenEventInfo(const edm::InputTag &)
Definition: EventInfo.cc:188
edm::InputTag rho_collection_
Definition: EventInfo.h:100
edm::InputTag genInfo_
Definition: EventInfo.h:83
void FixedGridRhoInfo(const edm::InputTag &)
Definition: EventInfo.cc:245