ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TreeProducer.cpp
Revision: 1.3
Committed: Thu Dec 1 14:35:47 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Changes since 1.2: +3 -0 lines
Log Message:
*** empty log message ***

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