ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TreeProducer.cpp
Revision: 1.4
Committed: Wed Dec 7 18:31:52 2011 UTC (13 years, 4 months ago) by cgoetzma
Branch: MAIN
Changes since 1.3: +17 -0 lines
Log Message:
chris mod

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
111
112 fChain->SetBranchAddress("BS_X", &BS_X, &b_BS_X);
113 fChain->SetBranchAddress("BS_Y", &BS_Y, &b_BS_Y);
114 fChain->SetBranchAddress("BS_Z", &BS_Z, &b_BS_Z);
115
116 fChain->SetBranchAddress("TrackGen_p", TrackGen_p, &b_TrackGen_p);
117 fChain->SetBranchAddress("TrackGen_pt", TrackGen_pt, &b_TrackGen_pt);
118 fChain->SetBranchAddress("TrackGen_px", TrackGen_px, &b_TrackGen_px);
119 fChain->SetBranchAddress("TrackGen_py", TrackGen_py, &b_TrackGen_py);
120 fChain->SetBranchAddress("TrackGen_pz", TrackGen_pz, &b_TrackGen_pz);
121 fChain->SetBranchAddress("TrackGen_eta", TrackGen_eta, &b_TrackGen_eta);
122 fChain->SetBranchAddress("TrackGen_phi", TrackGen_phi, &b_TrackGen_phi);
123 fChain->SetBranchAddress("TrackGen_charge", TrackGen_charge, &b_TrackGen_charge);
124 fChain->SetBranchAddress("TrackGen_deltaRreco", TrackGen_deltaRreco, &b_TrackGen_deltaRreco);
125 fChain->SetBranchAddress("nHit", &nHit, &b_nHit);
126 fChain->SetBranchAddress("hitXLocalPosition", &hitXLocalPosition, &b_hitXLocalPosition);
127 fChain->SetBranchAddress("hitYLocalPosition", &hitYLocalPosition, &b_hitYLocalPosition);
128 fChain->SetBranchAddress("hitZLocalPosition", &hitZLocalPosition, &b_hitZLocalPosition);
129 fChain->SetBranchAddress("hitXLocalPositionError", &hitXLocalPositionError, &b_hitXLocalPositionError);
130 fChain->SetBranchAddress("hitYLocalPositionError", &hitYLocalPositionError, &b_hitYLocalPositionError);
131 fChain->SetBranchAddress("hitZLocalPositionError", &hitZLocalPositionError, &b_hitZLocalPositionError);
132 fChain->SetBranchAddress("expectedXLocalPosition", &expectedXLocalPosition, &b_expectedXLocalPosition);
133 fChain->SetBranchAddress("expectedYLocalPosition", &expectedYLocalPosition, &b_expectedYLocalPosition);
134 fChain->SetBranchAddress("expectedZLocalPosition", &expectedZLocalPosition, &b_expectedZLocalPosition);
135 fChain->SetBranchAddress("expectedXLocalPositionError", &expectedXLocalPositionError, &b_expectedXLocalPositionError);
136 fChain->SetBranchAddress("expectedYLocalPositionError", &expectedYLocalPositionError, &b_expectedYLocalPositionError);
137 fChain->SetBranchAddress("expectedZLocalPositionError", &expectedZLocalPositionError, &b_expectedZLocalPositionError);
138 fChain->SetBranchAddress("hitXGlobalPosition", &hitXGlobalPosition, &b_hitXGlobalPosition);
139 fChain->SetBranchAddress("hitYGlobalPosition", &hitYGlobalPosition, &b_hitYGlobalPosition);
140 fChain->SetBranchAddress("hitZGlobalPosition", &hitZGlobalPosition, &b_hitZGlobalPosition);
141 fChain->SetBranchAddress("hitXGlobalPositionError", &hitXGlobalPositionError, &b_hitXGlobalPositionError);
142 fChain->SetBranchAddress("hitYGlobalPositionError", &hitYGlobalPositionError, &b_hitYGlobalPositionError);
143 fChain->SetBranchAddress("hitZGlobalPositionError", &hitZGlobalPositionError, &b_hitZGlobalPositionError);
144 fChain->SetBranchAddress("expectedXGlobalPosition", &expectedXGlobalPosition, &b_expectedXGlobalPosition);
145 fChain->SetBranchAddress("expectedYGlobalPosition", &expectedYGlobalPosition, &b_expectedYGlobalPosition);
146 fChain->SetBranchAddress("expectedZGlobalPosition", &expectedZGlobalPosition, &b_expectedZGlobalPosition);
147 fChain->SetBranchAddress("expectedXGlobalPositionError", &expectedXGlobalPositionError, &b_expectedXGlobalPositionError);
148 fChain->SetBranchAddress("expectedYGlobalPositionError", &expectedYGlobalPositionError, &b_expectedYGlobalPositionError);
149 fChain->SetBranchAddress("expectedZGlobalPositionError", &expectedZGlobalPositionError, &b_expectedZGlobalPositionError);
150 fChain->SetBranchAddress("RunNumber", &RunNumber, &b_RunNumber);
151 fChain->SetBranchAddress("EventNumber", &EventNumber, &b_EventNumber);
152 fChain->SetBranchAddress("vxtConverged", &vtxConverged, &b_vtxConverged);
153 fChain->SetBranchAddress("momConverged", &momConverged, &b_momConverged);
154 fChain->SetBranchAddress("fullConverged", &fullConverged, &b_fullConverged);
155 Notify();
156 }
157
158 Bool_t TreeProducer::Notify()
159 {
160 // The Notify() function is called when a new file is opened. This
161 // can be either for a new TTree in a TChain or when when a new TTree
162 // is started when using PROOF. It is normally not necessary to make changes
163 // to the generated code, but the routine can be extended by the
164 // user if needed. The return value is currently not used.
165
166 return kTRUE;
167 }
168
169 void TreeProducer::Show(Long64_t entry)
170 {
171 // Print contents of entry.
172 // If entry is not specified, print current entry
173 if (!fChain) return;
174 fChain->Show(entry);
175 }
176 Int_t TreeProducer::Cut(Long64_t entry)
177 {
178 // This function may be called from Loop.
179 // returns 1 if entry is accepted.
180 // returns -1 otherwise.
181 return 1;
182 }
183
184
185 void TreeProducer::Loop()
186 {
187 // In a ROOT session, you can do:
188 // Root > .L TreeProducer.C
189 // Root > TreeProducer t
190 // Root > t.GetEntry(12); // Fill t data members with entry number 12
191 // Root > t.Show(); // Show values of entry 12
192 // Root > t.Show(16); // Read and show values of entry 16
193 // Root > t.Loop(); // Loop on all entries
194 //
195
196 // This is the loop skeleton where:
197 // jentry is the global entry number in the chain
198 // ientry is the entry number in the current Tree
199 // Note that the argument to GetEntry must be:
200 // jentry for TChain::GetEntry
201 // ientry for TTree::GetEntry and TBranch::GetEntry
202 //
203 // To read only selected branches, Insert statements like:
204 // METHOD1:
205 // fChain->SetBranchStatus("*",0); // disable all branches
206 // fChain->SetBranchStatus("branchname",1); // activate branchname
207 // METHOD2: replace line
208 // fChain->GetEntry(jentry); //read all branches
209 //by b_branchname->GetEntry(ientry); //read only this branch
210 if (fChain == 0) return;
211
212 Long64_t nentries = fChain->GetEntriesFast();
213
214 Long64_t nbytes = 0, nb = 0;
215 for (Long64_t jentry=0; jentry<nentries;jentry++) {
216 Long64_t ientry = LoadTree(jentry);
217 if (ientry < 0) break;
218 nb = fChain->GetEntry(jentry); nbytes += nb;
219 // if (Cut(ientry) < 0) continue;
220 }
221 }