ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/IPHCalignment2/analysis/TwoBodyDecaySpy.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

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