DESY Hbb Analysis Framework
PileupInfo.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 #include <iostream>
16 //
17 // user include files
18 #include "FWCore/Framework/interface/Event.h"
19 #include "FWCore/ParameterSet/interface/ParameterSet.h"
20 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
22 
23 //
24 // class declaration
25 //
26 
27 using namespace analysis;
28 using namespace analysis::ntuple;
29 //
30 // constructors and destructor
31 //
33 {
34  // default constructor
35 }
36 
37 PileupInfo::PileupInfo(const edm::InputTag& tag, TTree* tree)
38 {
39  input_collection_ = tag;
40  tree_ = tree;
41 
42 }
43 
45 {
46  // do anything here that needs to be done at desctruction time
47  // (e.g. close files, deallocate resources etc.)
48 }
49 
50 
51 //
52 // member functions
53 //
54 
55 // ------------ method called for each event ------------
56 void PileupInfo::ReadFromEvent(const edm::Event& event)
57 {
58  using namespace edm;
59 
60  //
61  edm::Handle<std::vector<PileupSummaryInfo> > handler;
62  event.getByLabel(input_collection_, handler);
63 
64  std::vector<PileupSummaryInfo> pileup_infos = *(handler.product());
65 
66 // Take the first entry - should be enough
67 // for ( size_t i = 0 ; i < pileup_infos.size() ; ++i )
68 // {
69 
70  PileupSummaryInfo pileup_info = pileup_infos.at(0);
71 
72 // if ( pileup_info.getBunchCrossing() != 0 ) continue;
73 
74  n_true_pu_ = pileup_info.getTrueNumInteractions();
75  n_pu_ = pileup_info.getPU_NumInteractions();
76 
77 // break;
78 // }
79 
80 
81 }
82 
83 
85 {
86  tree_->Fill();
87 }
88 
89 void PileupInfo::Fill(const edm::Event& event)
90 {
91  ReadFromEvent(event);
92  Fill();
93 }
94 
95 // ------------ method called once each job just before starting event loop ------------
97 {
98  tree_->Branch("nTruePileup", &this->n_true_pu_, "nTruePileup/F");
99  tree_->Branch("nPileup", &this->n_pu_, "nPileup/F");
100 }
101 
edm::InputTag input_collection_
Definition: PileupInfo.h:51
void ReadFromEvent(const edm::Event &)
Definition: PileupInfo.cc:56