539b6cb4 |
1 | // The class definition in esdV0.h has been generated automatically |
2 | // by the ROOT utility TTree::MakeSelector(). This class is derived |
3 | // from the ROOT class TSelector. For more information on the TSelector |
4 | // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual. |
5 | |
6 | // The following methods are defined in this file: |
7 | // Begin(): called everytime a loop on the tree starts, |
8 | // a convenient place to create your histograms. |
9 | // SlaveBegin(): called after Begin(), when on PROOF called only on the |
10 | // slave servers. |
11 | // Process(): called for each event, in this function you decide what |
12 | // to read and fill your histograms. |
13 | // SlaveTerminate: called at the end of the loop on the tree, when on PROOF |
14 | // called only on the slave servers. |
15 | // Terminate(): called at the end of the loop on the tree, |
16 | // a convenient place to draw/fit your histograms. |
17 | // |
18 | // To use this file, try the following session on your Tree T: |
19 | // |
20 | // Root > T->Process("AliSelector.C") |
21 | // Root > T->Process("AliSelector.C","some options") |
22 | // Root > T->Process("AliSelector.C+") |
23 | // |
24 | |
25 | #include "AliSelector.h" |
26 | #include <TStyle.h> |
27 | #include <TSystem.h> |
28 | #include <TCanvas.h> |
29 | #include <TRegexp.h> |
30 | |
31 | #include <TFriendElement.h> |
32 | |
33 | #include <iostream> |
34 | using namespace std; |
35 | |
36 | ClassImp(AliSelector) |
37 | |
38 | AliSelector::AliSelector(TTree *) : |
39 | TSelector(), |
40 | fChain(0), |
41 | fESD(0), |
42 | fHeader(0), |
43 | fRunLoader(0), |
44 | fKineFile(0) |
45 | { |
46 | // Constructor. Initialization of pointers |
47 | } |
48 | |
49 | AliSelector::~AliSelector() |
50 | { |
51 | // Remove all pointers |
52 | |
53 | // histograms are in the output list and deleted when the output |
54 | // list is deleted by the TSelector dtor |
55 | } |
56 | |
57 | void AliSelector::Begin(TTree *) |
58 | { |
59 | // The Begin() function is called at the start of the query. |
60 | // When running with PROOF Begin() is only called on the client. |
61 | // The tree argument is deprecated (on PROOF 0 is passed). |
62 | |
63 | //TString option = GetOption(); |
64 | } |
65 | |
66 | void AliSelector::SlaveBegin(TTree * tree) |
67 | { |
68 | // The SlaveBegin() function is called after the Begin() function. |
69 | // When running with PROOF SlaveBegin() is called on each slave server. |
70 | // The tree argument is deprecated (on PROOF 0 is passed). |
71 | |
72 | Init(tree); |
73 | |
74 | printf("=======SLAVEBEGIN========\n"); |
75 | gSystem->Exec("hostname"); |
76 | gSystem->Exec("date"); |
77 | TFile *f = fChain->GetCurrentFile(); |
78 | printf("%s\n",f->GetName()); |
79 | |
80 | TString option = GetOption(); |
81 | } |
82 | |
83 | void AliSelector::Init(TTree *tree) |
84 | { |
85 | // The Init() function is called when the selector needs to initialize |
86 | // a new tree or chain. Typically here the branch addresses of the tree |
87 | // will be set. It is normaly not necessary to make changes to the |
88 | // generated code, but the routine can be extended by the user if needed. |
89 | // Init() will be called many times when running with PROOF. |
90 | |
91 | printf("=========Init==========\n"); |
92 | |
93 | // Set branch addresses |
94 | if (tree == 0) |
95 | { |
96 | printf("ERROR: tree argument is 0.\n"); |
97 | return; |
98 | } |
99 | |
100 | fChain = dynamic_cast<TChain*> (tree); |
101 | if (fChain == 0) |
102 | { |
103 | printf("ERROR: tree argument could not be casted to TChain.\n"); |
104 | return; |
105 | } |
106 | |
107 | fChain->SetBranchAddress("ESD", &fESD); |
108 | if (fESD != 0) |
109 | printf("INFO: Found ESD branch in chain.\n"); |
110 | |
111 | fChain->SetBranchAddress("Header", &fHeader); |
112 | if (fHeader != 0) |
113 | printf("INFO: Found event header branch in chain.\n"); |
114 | |
115 | } |
116 | |
117 | Bool_t AliSelector::Notify() |
118 | { |
119 | // The Notify() function is called when a new file is opened. This |
120 | // can be either for a new TTree in a TChain or when when a new TTree |
121 | // is started when using PROOF. Typically here the branch pointers |
122 | // will be retrieved. It is normaly not necessary to make changes |
123 | // to the generated code, but the routine can be extended by the |
124 | // user if needed. |
125 | |
126 | printf("=========NOTIFY==========\n"); |
127 | gSystem->Exec("hostname"); |
128 | gSystem->Exec("date"); |
129 | TFile *f = fChain->GetCurrentFile(); |
130 | TString fileName(f->GetName()); |
131 | printf("%s\n",fileName.Data()); |
132 | |
133 | DeleteKinematicsFile(); |
134 | DeleteRunLoader(); |
135 | |
136 | return kTRUE; |
137 | } |
138 | |
139 | Bool_t AliSelector::Process(Long64_t entry) |
140 | { |
141 | // The Process() function is called for each entry in the tree (or possibly |
142 | // keyed object in the case of PROOF) to be processed. The entry argument |
143 | // specifies which entry in the currently loaded tree is to be processed. |
144 | // It can be passed to either TTree::GetEntry() or TBranch::GetEntry() |
145 | // to read either all or the required parts of the data. When processing |
146 | // keyed objects with PROOF, the object is already loaded and is available |
147 | // via the fObject pointer. |
148 | // |
149 | // This function should contain the "body" of the analysis. It can contain |
150 | // simple or elaborate selection criteria, run algorithms on the data |
151 | // of the event and typically fill histograms. |
152 | |
153 | // WARNING when a selector is used with a TChain, you must use |
154 | // the pointer to the current TTree to call GetEntry(entry). |
155 | // The entry is always the local entry number in the current tree. |
156 | // Assuming that fChain is the pointer to the TChain being processed, |
157 | // use fChain->GetTree()->GetEntry(entry). |
158 | |
159 | printf("=========PROCESS========== Entry %lld\n", entry); |
160 | |
161 | if (!fChain) |
162 | { |
163 | printf("ERROR: fChain is 0.\n"); |
164 | return kFALSE; |
165 | } |
166 | |
167 | fChain->GetTree()->GetEntry(entry); |
168 | |
169 | if (fESD) |
170 | printf("ESD: We have %d tracks.\n", fESD->GetNumberOfTracks()); |
171 | |
172 | if (fHeader) |
173 | printf("Header: We have %d primaries.\n", fHeader->GetNprimary()); |
174 | |
175 | TTree* kinematics = GetKinematics(); |
176 | if (kinematics) |
177 | printf("Kinematics from folder: We have %lld particles.\n", kinematics->GetEntries()); |
178 | |
179 | printf("\n"); |
180 | |
181 | return kTRUE; |
182 | } |
183 | |
184 | void AliSelector::SlaveTerminate() |
185 | { |
186 | // The SlaveTerminate() function is called after all entries or objects |
187 | // have been processed. When running with PROOF SlaveTerminate() is called |
188 | // on each slave server. |
189 | |
190 | DeleteKinematicsFile(); |
191 | DeleteRunLoader(); |
192 | } |
193 | |
194 | void AliSelector::Terminate() |
195 | { |
196 | // The Terminate() function is the last function to be called during |
197 | // a query. It always runs on the client, it can be used to present |
198 | // the results graphically or save the results to file. |
199 | |
200 | printf("=========TERMINATE==========\n"); |
201 | } |
202 | |
203 | TTree* AliSelector::GetKinematics() |
204 | { |
205 | if (!fKineFile) |
206 | { |
207 | if (!fChain->GetCurrentFile()) |
208 | return 0; |
209 | |
210 | TString fileName(fChain->GetCurrentFile()->GetName()); |
211 | fileName.ReplaceAll("AliESDs", "Kinematics"); |
212 | |
213 | fKineFile = TFile::Open(fileName); |
214 | if (!fKineFile) |
215 | return 0; |
216 | } |
217 | |
218 | return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry()))); |
219 | |
220 | /* this is if we want to get it from a TChain |
221 | |
222 | define it in the header: |
223 | |
224 | TChain* fKineChain; |
225 | |
226 | this creates the chain: |
227 | |
228 | TChain* chainKine = new TChain("TreeK"); |
229 | for (Int_t i=0; i<20; ++i) |
230 | chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i)); |
231 | for (Int_t i=0; i<20; ++i) |
232 | chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i)); |
233 | |
234 | <mainChain>->GetUserInfo()->Add(chainKine); |
235 | |
236 | we retrieve it in init: |
237 | |
238 | fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK")); |
239 | |
240 | and use it in process: |
241 | |
242 | if (fKineChain) |
243 | { |
244 | Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)]; |
245 | cout << "Entry in fKineChain: " << entryK << endl; |
246 | fKineChain->LoadTree(entryK); |
247 | TTree* kineTree = fKineChain->GetTree(); |
248 | |
249 | printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries()); |
250 | } |
251 | */ |
252 | } |
253 | |
254 | void AliSelector::DeleteKinematicsFile() |
255 | { |
256 | if (fKineFile) |
257 | { |
258 | fKineFile->Close(); |
259 | delete fKineFile; |
260 | fKineFile = 0; |
261 | } |
262 | } |
263 | |
264 | AliRun* AliSelector::GetAliRun() |
265 | { |
266 | if (!fRunLoader) |
267 | { |
268 | if (!fChain->GetCurrentFile()) |
269 | return 0; |
270 | |
271 | TString fileName(fChain->GetCurrentFile()->GetName()); |
272 | fileName.ReplaceAll("AliESDs", "galice"); |
273 | |
274 | fRunLoader = AliRunLoader::Open(fileName); |
275 | if (!fRunLoader) |
276 | return 0; |
277 | |
278 | fRunLoader->LoadgAlice(); |
279 | } |
280 | |
281 | return fRunLoader->GetAliRun(); |
282 | } |
283 | |
284 | void AliSelector::DeleteRunLoader() |
285 | { |
286 | if (fRunLoader) |
287 | { |
288 | fRunLoader->Delete(); |
289 | fRunLoader = 0; |
290 | } |
291 | } |