ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TreeProducer.cpp
Revision: 1.1
Committed: Fri Nov 25 16:33:01 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Log Message:
new IPHC alignment

File Contents

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