ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TreeProducer.cpp
Revision: 1.5
Committed: Thu Dec 8 10:23:04 2011 UTC (13 years, 4 months ago) by cgoetzma
Branch: MAIN
CVS Tags: TBD2011, HEAD
Changes since 1.4: +9 -1 lines
Log Message:
chris update

File Contents

# Content
1 #define TreeProducer_cxx
2 #include "TreeProducer.h"
3 #include <TH2.h>
4 #include <TStyle.h>
5 #include <TCanvas.h>
6 #include <stdlib.h>
7 #include <iostream>
8
9 TreeProducer::TreeProducer(const std::string& filename, const std::string& name)
10 {
11 TTree* tree=0;
12 TFile *f = new TFile(filename.c_str());
13 if (!f->IsOpen())
14 {
15 std::cout << "File called " << filename << " is not found" << std::endl;
16 exit(1);
17 }
18 tree = (TTree*)gDirectory->Get(name.c_str());
19 if (tree==0)
20 {
21 std::cout << "Tree called " << name << "is not found in file " << filename << std::endl;
22 exit(1);
23 }
24
25 Init(tree);
26 }
27
28
29 TreeProducer::~TreeProducer()
30 {
31 if (!fChain) return;
32 delete fChain->GetCurrentFile();
33 }
34
35 Int_t TreeProducer::GetEntry(Long64_t entry)
36 {
37 // Read contents of entry.
38 if (!fChain) return 0;
39 return fChain->GetEntry(entry);
40 }
41 Long64_t TreeProducer::LoadTree(Long64_t entry)
42 {
43 // Set the environment to read one entry
44 if (!fChain) return -5;
45 Long64_t centry = fChain->LoadTree(entry);
46 if (centry < 0) return centry;
47 if (!fChain->InheritsFrom(TChain::Class())) return centry;
48 TChain *chain = (TChain*)fChain;
49 if (chain->GetTreeNumber() != fCurrent) {
50 fCurrent = chain->GetTreeNumber();
51 Notify();
52 }
53 return centry;
54 }
55
56 void TreeProducer::Init(TTree *tree)
57 {
58 // The Init() function is called when the selector needs to initialize
59 // a new tree or chain. Typically here the branch addresses and branch
60 // pointers of the tree will be set.
61 // It is normally not necessary to make changes to the generated
62 // code, but the routine can be extended by the user if needed.
63 // Init() will be called many times when running on PROOF
64 // (once per file to be processed).
65
66 // Set branch addresses and branch pointers
67 if (!tree) return;
68 fChain = tree;
69 fCurrent = -1;
70 fChain->SetMakeClass(1);
71
72 fChain->SetBranchAddress("nTrack", &nTrack, &b_nTrack);
73 fChain->SetBranchAddress("Track_dxy", Track_dxy, &b_Track_dxy);
74 fChain->SetBranchAddress("Track_dxyError", Track_dxyError, &b_Track_dxyError);
75 fChain->SetBranchAddress("Track_dz", Track_dz, &b_Track_dz);
76 fChain->SetBranchAddress("Track_p", Track_p, &b_Track_p);
77 fChain->SetBranchAddress("Track_pt", Track_pt, &b_Track_pt);
78 fChain->SetBranchAddress("Track_px", Track_px, &b_Track_px);
79 fChain->SetBranchAddress("Track_py", Track_py, &b_Track_py);
80 fChain->SetBranchAddress("Track_pz", Track_pz, &b_Track_pz);
81 fChain->SetBranchAddress("Track_eta", Track_eta, &b_Track_eta);
82 fChain->SetBranchAddress("Track_phi", Track_phi, &b_Track_phi);
83 fChain->SetBranchAddress("Track_chi2", Track_chi2, &b_Track_chi2);
84 fChain->SetBranchAddress("Track_ndf", Track_ndf, &b_Track_ndf);
85 fChain->SetBranchAddress("Track_charge", Track_charge, &b_Track_charge);
86 fChain->SetBranchAddress("Track_nHitStrip", Track_nHitStrip, &b_Track_nHitStrip);
87 fChain->SetBranchAddress("Track_nHitPixel", Track_nHitPixel, &b_Track_nHitPixel);
88 fChain->SetBranchAddress("Track_hitIndexBegin", Track_hitIndexBegin, &b_Track_hitIndexBegin);
89 fChain->SetBranchAddress("Track_hitIndexEnd", Track_hitIndexEnd, &b_Track_hitIndexEnd);
90
91 fChain->SetBranchAddress("d0_Center", &d0_Center, &b_d0_Center);
92 fChain->SetBranchAddress("d0_BS", &d0_BS, &b_d0_BS);
93 fChain->SetBranchAddress("d0_PV", &d0_PV, &b_d0_PV);
94
95 //Alessio Plots
96 fChain->SetBranchAddress("QoverPGen", QoverPGen, &b_QoverPGen );
97 fChain->SetBranchAddress("lambdaGen", lambdaGen, &b_lambdaGen );
98 fChain->SetBranchAddress("dxyGen", dxyGen, &b_dxyGen );
99 fChain->SetBranchAddress("dszGen", dszGen, &b_dszGen );
100 fChain->SetBranchAddress("dxy0Gen", dxy0Gen, &b_dxy0Gen );
101 fChain->SetBranchAddress("dsz0Gen", dsz0Gen, &b_dsz0Gen );
102
103 fChain->SetBranchAddress("QoverP", QoverP, &b_QoverP );
104 fChain->SetBranchAddress("lambda", lambda, &b_lambda );
105 fChain->SetBranchAddress("dxy", dxy, &b_dxy);
106 fChain->SetBranchAddress("dsz", dsz, &b_dsz );
107 fChain->SetBranchAddress("dxy0", dxy0, &b_dxy0 );
108 fChain->SetBranchAddress("dsz0", dsz0, &b_dsz0 );
109
110 fChain->SetBranchAddress("QoverP_error", QoverP_error, &b_QoverP_error );
111 fChain->SetBranchAddress("lambda_error", lambda_error, &b_lambda_error );
112 fChain->SetBranchAddress("dxy_error", dxy_error, &b_dxy_error);
113 fChain->SetBranchAddress("dsz_error", dsz_error, &b_dsz_error );
114 fChain->SetBranchAddress("dxy0_error", dxy0_error, &b_dxy0_error );
115 fChain->SetBranchAddress("dsz0_error", dsz0_error, &b_dsz0_error );
116
117 //-------------
118
119
120 fChain->SetBranchAddress("BS_X", &BS_X, &b_BS_X);
121 fChain->SetBranchAddress("BS_Y", &BS_Y, &b_BS_Y);
122 fChain->SetBranchAddress("BS_Z", &BS_Z, &b_BS_Z);
123
124 fChain->SetBranchAddress("TrackGen_p", TrackGen_p, &b_TrackGen_p);
125 fChain->SetBranchAddress("TrackGen_pt", TrackGen_pt, &b_TrackGen_pt);
126 fChain->SetBranchAddress("TrackGen_px", TrackGen_px, &b_TrackGen_px);
127 fChain->SetBranchAddress("TrackGen_py", TrackGen_py, &b_TrackGen_py);
128 fChain->SetBranchAddress("TrackGen_pz", TrackGen_pz, &b_TrackGen_pz);
129 fChain->SetBranchAddress("TrackGen_eta", TrackGen_eta, &b_TrackGen_eta);
130 fChain->SetBranchAddress("TrackGen_phi", TrackGen_phi, &b_TrackGen_phi);
131 fChain->SetBranchAddress("TrackGen_charge", TrackGen_charge, &b_TrackGen_charge);
132 fChain->SetBranchAddress("TrackGen_deltaRreco", TrackGen_deltaRreco, &b_TrackGen_deltaRreco);
133 fChain->SetBranchAddress("nHit", &nHit, &b_nHit);
134 fChain->SetBranchAddress("hitXLocalPosition", &hitXLocalPosition, &b_hitXLocalPosition);
135 fChain->SetBranchAddress("hitYLocalPosition", &hitYLocalPosition, &b_hitYLocalPosition);
136 fChain->SetBranchAddress("hitZLocalPosition", &hitZLocalPosition, &b_hitZLocalPosition);
137 fChain->SetBranchAddress("hitXLocalPositionError", &hitXLocalPositionError, &b_hitXLocalPositionError);
138 fChain->SetBranchAddress("hitYLocalPositionError", &hitYLocalPositionError, &b_hitYLocalPositionError);
139 fChain->SetBranchAddress("hitZLocalPositionError", &hitZLocalPositionError, &b_hitZLocalPositionError);
140 fChain->SetBranchAddress("expectedXLocalPosition", &expectedXLocalPosition, &b_expectedXLocalPosition);
141 fChain->SetBranchAddress("expectedYLocalPosition", &expectedYLocalPosition, &b_expectedYLocalPosition);
142 fChain->SetBranchAddress("expectedZLocalPosition", &expectedZLocalPosition, &b_expectedZLocalPosition);
143 fChain->SetBranchAddress("expectedXLocalPositionError", &expectedXLocalPositionError, &b_expectedXLocalPositionError);
144 fChain->SetBranchAddress("expectedYLocalPositionError", &expectedYLocalPositionError, &b_expectedYLocalPositionError);
145 fChain->SetBranchAddress("expectedZLocalPositionError", &expectedZLocalPositionError, &b_expectedZLocalPositionError);
146 fChain->SetBranchAddress("hitXGlobalPosition", &hitXGlobalPosition, &b_hitXGlobalPosition);
147 fChain->SetBranchAddress("hitYGlobalPosition", &hitYGlobalPosition, &b_hitYGlobalPosition);
148 fChain->SetBranchAddress("hitZGlobalPosition", &hitZGlobalPosition, &b_hitZGlobalPosition);
149 fChain->SetBranchAddress("hitXGlobalPositionError", &hitXGlobalPositionError, &b_hitXGlobalPositionError);
150 fChain->SetBranchAddress("hitYGlobalPositionError", &hitYGlobalPositionError, &b_hitYGlobalPositionError);
151 fChain->SetBranchAddress("hitZGlobalPositionError", &hitZGlobalPositionError, &b_hitZGlobalPositionError);
152 fChain->SetBranchAddress("expectedXGlobalPosition", &expectedXGlobalPosition, &b_expectedXGlobalPosition);
153 fChain->SetBranchAddress("expectedYGlobalPosition", &expectedYGlobalPosition, &b_expectedYGlobalPosition);
154 fChain->SetBranchAddress("expectedZGlobalPosition", &expectedZGlobalPosition, &b_expectedZGlobalPosition);
155 fChain->SetBranchAddress("expectedXGlobalPositionError", &expectedXGlobalPositionError, &b_expectedXGlobalPositionError);
156 fChain->SetBranchAddress("expectedYGlobalPositionError", &expectedYGlobalPositionError, &b_expectedYGlobalPositionError);
157 fChain->SetBranchAddress("expectedZGlobalPositionError", &expectedZGlobalPositionError, &b_expectedZGlobalPositionError);
158 fChain->SetBranchAddress("RunNumber", &RunNumber, &b_RunNumber);
159 fChain->SetBranchAddress("EventNumber", &EventNumber, &b_EventNumber);
160 fChain->SetBranchAddress("vxtConverged", &vtxConverged, &b_vtxConverged);
161 fChain->SetBranchAddress("momConverged", &momConverged, &b_momConverged);
162 fChain->SetBranchAddress("fullConverged", &fullConverged, &b_fullConverged);
163 Notify();
164 }
165
166 Bool_t TreeProducer::Notify()
167 {
168 // The Notify() function is called when a new file is opened. This
169 // can be either for a new TTree in a TChain or when when a new TTree
170 // is started when using PROOF. It is normally not necessary to make changes
171 // to the generated code, but the routine can be extended by the
172 // user if needed. The return value is currently not used.
173
174 return kTRUE;
175 }
176
177 void TreeProducer::Show(Long64_t entry)
178 {
179 // Print contents of entry.
180 // If entry is not specified, print current entry
181 if (!fChain) return;
182 fChain->Show(entry);
183 }
184 Int_t TreeProducer::Cut(Long64_t entry)
185 {
186 // This function may be called from Loop.
187 // returns 1 if entry is accepted.
188 // returns -1 otherwise.
189 return 1;
190 }
191
192
193 void TreeProducer::Loop()
194 {
195 // In a ROOT session, you can do:
196 // Root > .L TreeProducer.C
197 // Root > TreeProducer t
198 // Root > t.GetEntry(12); // Fill t data members with entry number 12
199 // Root > t.Show(); // Show values of entry 12
200 // Root > t.Show(16); // Read and show values of entry 16
201 // Root > t.Loop(); // Loop on all entries
202 //
203
204 // This is the loop skeleton where:
205 // jentry is the global entry number in the chain
206 // ientry is the entry number in the current Tree
207 // Note that the argument to GetEntry must be:
208 // jentry for TChain::GetEntry
209 // ientry for TTree::GetEntry and TBranch::GetEntry
210 //
211 // To read only selected branches, Insert statements like:
212 // METHOD1:
213 // fChain->SetBranchStatus("*",0); // disable all branches
214 // fChain->SetBranchStatus("branchname",1); // activate branchname
215 // METHOD2: replace line
216 // fChain->GetEntry(jentry); //read all branches
217 //by b_branchname->GetEntry(ientry); //read only this branch
218 if (fChain == 0) return;
219
220 Long64_t nentries = fChain->GetEntriesFast();
221
222 Long64_t nbytes = 0, nb = 0;
223 for (Long64_t jentry=0; jentry<nentries;jentry++) {
224 Long64_t ientry = LoadTree(jentry);
225 if (ientry < 0) break;
226 nb = fChain->GetEntry(jentry); nbytes += nb;
227 // if (Cut(ientry) < 0) continue;
228 }
229 }