DESY Hbb Analysis Framework
Vertices.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 // user include files
17 #include "DataFormats/Provenance/interface/Provenance.h"
18 
19 #include "FWCore/Framework/interface/Event.h"
20 //
21 #include "FWCore/ParameterSet/interface/ParameterSet.h"
22 
23 #include "DataFormats/PatCandidates/interface/Jet.h"
24 
25 #include "CommonTools/Utils/interface/PtComparator.h"
26 
27 
28 
30 
31 #include "TTree.h"
32 
33 
34 //
35 // class declaration
36 //
37 
38 using namespace analysis;
39 using namespace analysis::ntuple;
40 
41 //
42 // constructors and destructor
43 //
45 {
46  // default constructor
47 }
48 
49 Vertices::Vertices(const edm::InputTag& tag, TTree* tree)
50 {
51  input_collection_ = tag;
52  tree_ = tree;
53 
54  tree_->Branch("n", &this->n_, "n/I");
55  tree_->Branch("x", this->x_, "x[n]/F");
56  tree_->Branch("y", this->y_, "y[n]/F");
57  tree_->Branch("z", this->z_, "z[n]/F");
58  tree_->Branch("xe", this->xe_, "xe[n]/F");
59  tree_->Branch("ye", this->ye_, "ye[n]/F");
60  tree_->Branch("ze", this->ze_, "ze[n]/F");
61  tree_->Branch("rho", this->rho_, "rho[n]/F");
62  tree_->Branch("chi2", this->chi2_, "chi2[n]/F");
63  tree_->Branch("ndof", this->ndof_, "ndof[n]/F");
64  tree_->Branch("fake", this->fake_, "fake[n]/O");
65 
66 }
67 
69 {
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72 }
73 
74 
75 //
76 // member functions
77 //
78 
79 // ------------ method called for each event ------------
80 void Vertices::ReadFromEvent(const edm::Event& event)
81 {
82  using namespace edm;
83 
84  edm::Handle<reco::VertexCollection> handler;
85  event.getByLabel(this->input_collection_, handler);
86  candidates_ = *(handler.product());
87 
88  int n = 0;
89  for ( size_t i = 0 ; i < candidates_.size(); ++i )
90  {
91  if ( n >= maxPVs ) break;
92 
93  this->x_[n] = candidates_[i].x();
94  this->y_[n] = candidates_[i].y();
95  this->z_[n] = candidates_[i].z();
96  this->xe_[n] = candidates_[i].xError();
97  this->ye_[n] = candidates_[i].yError();
98  this->ze_[n] = candidates_[i].zError();
99  this->fake_[n] = candidates_[i].isFake();
100  this->ndof_[n] = candidates_[i].ndof();
101  this->chi2_[n] = candidates_[i].chi2();
102  this->rho_[n] = candidates_[i].position().Rho();
103 
104  ++n;
105 
106  }
107  this->n_ = n;
108 
109 
110 }
111 
112 void Vertices::Fill(const edm::Event& event)
113 {
114  this->ReadFromEvent(event);
115  tree_->Fill();
116 }
117 
118 // ------------ method called once each job just before starting event loop ------------
float ndof_[maxPVs]
Definition: Vertices.h:71
static const int maxPVs
Definition: Vertices.h:52
reco::VertexCollection candidates_
Definition: Vertices.h:56
edm::InputTag input_collection_
Definition: Vertices.h:58
float rho_[maxPVs]
Definition: Vertices.h:72
float chi2_[maxPVs]
Definition: Vertices.h:70
void ReadFromEvent(const edm::Event &)
Definition: Vertices.cc:80
void Fill(const edm::Event &)
Definition: Vertices.cc:112