ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TwoBodyDecaySpy.cpp
Revision: 1.2
Committed: Fri Nov 25 18:36:55 2011 UTC (13 years, 5 months ago) by econte
Branch: MAIN
Changes since 1.1: +11 -0 lines
Log Message:
modif dans le main.cpp

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("TrackGen_p", TrackGen_p, &b_TrackGen_p);
90 fChain->SetBranchAddress("TrackGen_pt", TrackGen_pt, &b_TrackGen_pt);
91 fChain->SetBranchAddress("TrackGen_px", TrackGen_px, &b_TrackGen_px);
92 fChain->SetBranchAddress("TrackGen_py", TrackGen_py, &b_TrackGen_py);
93 fChain->SetBranchAddress("TrackGen_pz", TrackGen_pz, &b_TrackGen_pz);
94 fChain->SetBranchAddress("TrackGen_eta", TrackGen_eta, &b_TrackGen_eta);
95 fChain->SetBranchAddress("TrackGen_phi", TrackGen_phi, &b_TrackGen_phi);
96 fChain->SetBranchAddress("TrackGen_charge", TrackGen_charge, &b_TrackGen_charge);
97 fChain->SetBranchAddress("TrackGen_deltaRreco", TrackGen_deltaRreco, &b_TrackGen_deltaRreco);
98
99 fChain->SetBranchAddress("Vtx_X", &Vtx_X, &b_Vtx_X);
100 fChain->SetBranchAddress("Vtx_Y", &Vtx_Y, &b_Vtx_Y);
101 fChain->SetBranchAddress("Vtx_Z", &Vtx_Z, &b_Vtx_Z);
102 fChain->SetBranchAddress("Cov_XX", &Cov_XX, &b_Cov_XX);
103 fChain->SetBranchAddress("Cov_XY", &Cov_XY, &b_Cov_XY);
104 fChain->SetBranchAddress("Cov_XZ", &Cov_XZ, &b_Cov_XZ);
105 fChain->SetBranchAddress("Cov_YX", &Cov_YX, &b_Cov_YX);
106 fChain->SetBranchAddress("Cov_YY", &Cov_YY, &b_Cov_YY);
107 fChain->SetBranchAddress("Cov_YZ", &Cov_YZ, &b_Cov_YZ);
108 fChain->SetBranchAddress("Cov_ZX", &Cov_ZX, &b_Cov_ZX);
109 fChain->SetBranchAddress("Cov_ZY", &Cov_ZY, &b_Cov_ZY);
110 fChain->SetBranchAddress("Cov_ZZ", &Cov_ZZ, &b_Cov_ZZ);
111 fChain->SetBranchAddress("RunNumber", &RunNumber, &b_RunNumber);
112 fChain->SetBranchAddress("EventNumber", &EventNumber, &b_EventNumber);
113 Notify();
114 }
115
116 Bool_t TwoBodyDecaySpy::Notify()
117 {
118 // The Notify() function is called when a new file is opened. This
119 // can be either for a new TTree in a TChain or when when a new TTree
120 // is started when using PROOF. It is normally not necessary to make changes
121 // to the generated code, but the routine can be extended by the
122 // user if needed. The return value is currently not used.
123
124 return kTRUE;
125 }
126
127 void TwoBodyDecaySpy::Show(Long64_t entry)
128 {
129 // Print contents of entry.
130 // If entry is not specified, print current entry
131 if (!fChain) return;
132 fChain->Show(entry);
133 }
134 Int_t TwoBodyDecaySpy::Cut(Long64_t entry)
135 {
136 // This function may be called from Loop.
137 // returns 1 if entry is accepted.
138 // returns -1 otherwise.
139 return 1;
140 }
141
142
143 void TwoBodyDecaySpy::Loop()
144 {
145 // In a ROOT session, you can do:
146 // Root > .L TwoBodyDecaySpy.C
147 // Root > TwoBodyDecaySpy t
148 // Root > t.GetEntry(12); // Fill t data members with entry number 12
149 // Root > t.Show(); // Show values of entry 12
150 // Root > t.Show(16); // Read and show values of entry 16
151 // Root > t.Loop(); // Loop on all entries
152 //
153
154 // This is the loop skeleton where:
155 // jentry is the global entry number in the chain
156 // ientry is the entry number in the current Tree
157 // Note that the argument to GetEntry must be:
158 // jentry for TChain::GetEntry
159 // ientry for TTree::GetEntry and TBranch::GetEntry
160 //
161 // To read only selected branches, Insert statements like:
162 // METHOD1:
163 // fChain->SetBranchStatus("*",0); // disable all branches
164 // fChain->SetBranchStatus("branchname",1); // activate branchname
165 // METHOD2: replace line
166 // fChain->GetEntry(jentry); //read all branches
167 //by b_branchname->GetEntry(ientry); //read only this branch
168 if (fChain == 0) return;
169
170 Long64_t nentries = fChain->GetEntriesFast();
171
172 Long64_t nbytes = 0, nb = 0;
173 for (Long64_t jentry=0; jentry<nentries;jentry++) {
174 Long64_t ientry = LoadTree(jentry);
175 if (ientry < 0) break;
176 nb = fChain->GetEntry(jentry); nbytes += nb;
177 // if (Cut(ientry) < 0) continue;
178 }
179 }