ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TwoBodyDecaySpy.cpp
Revision: 1.3
Committed: Thu Dec 1 13:46:25 2011 UTC (13 years, 5 months ago) by cgoetzma
Branch: MAIN
CVS Tags: TBD2011, HEAD
Changes since 1.2: +8 -0 lines
Log Message:
chris mods

File Contents

# Content
1 #define TwoBodyDecaySpy_cxx
2 #include "TwoBodyDecaySpy.h"
3 #include <TH2.h>
4 #include <TStyle.h>
5 #include <TCanvas.h>
6 #include <stdlib.h>
7 #include <iostream>
8
9
10 TwoBodyDecaySpy::TwoBodyDecaySpy(const std::string& filename, const std::string& name)
11 {
12 TTree* tree=0;
13 TFile *f = new TFile(filename.c_str());
14 if (!f->IsOpen())
15 {
16 std::cout << "File called " << filename << " is not found" << std::endl;
17 exit(1);
18 }
19 tree = (TTree*)gDirectory->Get(name.c_str());
20 if (tree==0)
21 {
22 std::cout << "Tree called " << name << "is not found in file " << filename << std::endl;
23 exit(1);
24 }
25
26 Init(tree);
27 }
28
29
30
31 TwoBodyDecaySpy::~TwoBodyDecaySpy()
32 {
33 if (!fChain) return;
34 delete fChain->GetCurrentFile();
35 }
36
37 Int_t TwoBodyDecaySpy::GetEntry(Long64_t entry)
38 {
39 // Read contents of entry.
40 if (!fChain) return 0;
41 return fChain->GetEntry(entry);
42 }
43 Long64_t TwoBodyDecaySpy::LoadTree(Long64_t entry)
44 {
45 // Set the environment to read one entry
46 if (!fChain) return -5;
47 Long64_t centry = fChain->LoadTree(entry);
48 if (centry < 0) return centry;
49 if (!fChain->InheritsFrom(TChain::Class())) return centry;
50 TChain *chain = (TChain*)fChain;
51 if (chain->GetTreeNumber() != fCurrent) {
52 fCurrent = chain->GetTreeNumber();
53 Notify();
54 }
55 return centry;
56 }
57
58 void TwoBodyDecaySpy::Init(TTree *tree)
59 {
60 // The Init() function is called when the selector needs to initialize
61 // a new tree or chain. Typically here the branch addresses and branch
62 // pointers of the tree will be set.
63 // It is normally not necessary to make changes to the generated
64 // code, but the routine can be extended by the user if needed.
65 // Init() will be called many times when running on PROOF
66 // (once per file to be processed).
67
68 // Set branch addresses and branch pointers
69 if (!tree) return;
70 fChain = tree;
71 fCurrent = -1;
72 fChain->SetMakeClass(1);
73
74 fChain->SetBranchAddress("Charge", Charge, &b_Charge);
75 fChain->SetBranchAddress("OldTrack_px", OldTrack_px, &b_OldTrack_px);
76 fChain->SetBranchAddress("OldTrack_py", OldTrack_py, &b_OldTrack_py);
77 fChain->SetBranchAddress("OldTrack_pz", OldTrack_pz, &b_OldTrack_pz);
78 fChain->SetBranchAddress("NewTrack_px", NewTrack_px, &b_NewTrack_px);
79 fChain->SetBranchAddress("NewTrack_py", NewTrack_py, &b_NewTrack_py);
80 fChain->SetBranchAddress("NewTrack_pz", NewTrack_pz, &b_NewTrack_pz);
81 fChain->SetBranchAddress("NewTrack_Edmund_p", NewTrack_Edmund_p, &b_NewTrack_Edmund_p);
82 fChain->SetBranchAddress("NewTrack_Edmund_pErr", NewTrack_Edmund_pErr, &b_NewTrack_Edmund_pErr);
83 fChain->SetBranchAddress("NewTrack_Eric_p", NewTrack_Eric_p, &b_NewTrack_Eric_p);
84 fChain->SetBranchAddress("NewTrack_Eric_pErr", NewTrack_Eric_pErr, &b_NewTrack_Eric_pErr);
85 fChain->SetBranchAddress("Zmass", &Zmass, &b_Zmass);
86 fChain->SetBranchAddress("ZmassErr", &ZmassErr, &b_ZmassErr);
87 fChain->SetBranchAddress("tbdChi2", &tbdChi2, &b_tbdChi2);
88
89 fChain->SetBranchAddress("d0_Center", &d0_Center, &b_d0_Center);
90 fChain->SetBranchAddress("d0_BS", &d0_BS, &b_d0_BS);
91 fChain->SetBranchAddress("d0_PV", &d0_PV, &b_d0_PV);
92
93 fChain->SetBranchAddress("BS_X", &BS_X, &b_BS_X);
94 fChain->SetBranchAddress("BS_Y", &BS_Y, &b_BS_Y);
95 fChain->SetBranchAddress("BS_Z", &BS_Z, &b_BS_Z);
96
97 fChain->SetBranchAddress("TrackGen_p", TrackGen_p, &b_TrackGen_p);
98 fChain->SetBranchAddress("TrackGen_pt", TrackGen_pt, &b_TrackGen_pt);
99 fChain->SetBranchAddress("TrackGen_px", TrackGen_px, &b_TrackGen_px);
100 fChain->SetBranchAddress("TrackGen_py", TrackGen_py, &b_TrackGen_py);
101 fChain->SetBranchAddress("TrackGen_pz", TrackGen_pz, &b_TrackGen_pz);
102 fChain->SetBranchAddress("TrackGen_eta", TrackGen_eta, &b_TrackGen_eta);
103 fChain->SetBranchAddress("TrackGen_phi", TrackGen_phi, &b_TrackGen_phi);
104 fChain->SetBranchAddress("TrackGen_charge", TrackGen_charge, &b_TrackGen_charge);
105 fChain->SetBranchAddress("TrackGen_deltaRreco", TrackGen_deltaRreco, &b_TrackGen_deltaRreco);
106
107 fChain->SetBranchAddress("Vtx_X", &Vtx_X, &b_Vtx_X);
108 fChain->SetBranchAddress("Vtx_Y", &Vtx_Y, &b_Vtx_Y);
109 fChain->SetBranchAddress("Vtx_Z", &Vtx_Z, &b_Vtx_Z);
110 fChain->SetBranchAddress("Cov_XX", &Cov_XX, &b_Cov_XX);
111 fChain->SetBranchAddress("Cov_XY", &Cov_XY, &b_Cov_XY);
112 fChain->SetBranchAddress("Cov_XZ", &Cov_XZ, &b_Cov_XZ);
113 fChain->SetBranchAddress("Cov_YX", &Cov_YX, &b_Cov_YX);
114 fChain->SetBranchAddress("Cov_YY", &Cov_YY, &b_Cov_YY);
115 fChain->SetBranchAddress("Cov_YZ", &Cov_YZ, &b_Cov_YZ);
116 fChain->SetBranchAddress("Cov_ZX", &Cov_ZX, &b_Cov_ZX);
117 fChain->SetBranchAddress("Cov_ZY", &Cov_ZY, &b_Cov_ZY);
118 fChain->SetBranchAddress("Cov_ZZ", &Cov_ZZ, &b_Cov_ZZ);
119 fChain->SetBranchAddress("RunNumber", &RunNumber, &b_RunNumber);
120 fChain->SetBranchAddress("EventNumber", &EventNumber, &b_EventNumber);
121 Notify();
122 }
123
124 Bool_t TwoBodyDecaySpy::Notify()
125 {
126 // The Notify() function is called when a new file is opened. This
127 // can be either for a new TTree in a TChain or when when a new TTree
128 // is started when using PROOF. It is normally not necessary to make changes
129 // to the generated code, but the routine can be extended by the
130 // user if needed. The return value is currently not used.
131
132 return kTRUE;
133 }
134
135 void TwoBodyDecaySpy::Show(Long64_t entry)
136 {
137 // Print contents of entry.
138 // If entry is not specified, print current entry
139 if (!fChain) return;
140 fChain->Show(entry);
141 }
142 Int_t TwoBodyDecaySpy::Cut(Long64_t entry)
143 {
144 // This function may be called from Loop.
145 // returns 1 if entry is accepted.
146 // returns -1 otherwise.
147 return 1;
148 }
149
150
151 void TwoBodyDecaySpy::Loop()
152 {
153 // In a ROOT session, you can do:
154 // Root > .L TwoBodyDecaySpy.C
155 // Root > TwoBodyDecaySpy t
156 // Root > t.GetEntry(12); // Fill t data members with entry number 12
157 // Root > t.Show(); // Show values of entry 12
158 // Root > t.Show(16); // Read and show values of entry 16
159 // Root > t.Loop(); // Loop on all entries
160 //
161
162 // This is the loop skeleton where:
163 // jentry is the global entry number in the chain
164 // ientry is the entry number in the current Tree
165 // Note that the argument to GetEntry must be:
166 // jentry for TChain::GetEntry
167 // ientry for TTree::GetEntry and TBranch::GetEntry
168 //
169 // To read only selected branches, Insert statements like:
170 // METHOD1:
171 // fChain->SetBranchStatus("*",0); // disable all branches
172 // fChain->SetBranchStatus("branchname",1); // activate branchname
173 // METHOD2: replace line
174 // fChain->GetEntry(jentry); //read all branches
175 //by b_branchname->GetEntry(ientry); //read only this branch
176 if (fChain == 0) return;
177
178 Long64_t nentries = fChain->GetEntriesFast();
179
180 Long64_t nbytes = 0, nb = 0;
181 for (Long64_t jentry=0; jentry<nentries;jentry++) {
182 Long64_t ientry = LoadTree(jentry);
183 if (ientry < 0) break;
184 nb = fChain->GetEntry(jentry); nbytes += nb;
185 // if (Cut(ientry) < 0) continue;
186 }
187 }