]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PWG0/AliSelector.cxx
Removed ';' from ClassImp pragmas.
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
... / ...
CommitLineData
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>
34using namespace std;
35
36ClassImp(AliSelector)
37
38AliSelector::AliSelector(TTree *) :
39 TSelector(),
40 fChain(0),
41 fESD(0),
42 fHeader(0),
43 fKineFile(0),
44 fRunLoader(0)
45{
46 //
47 // Constructor. Initialization of pointers
48 //
49}
50
51AliSelector::~AliSelector()
52{
53 //
54 // Destructor
55 //
56
57 // histograms are in the output list and deleted when the output
58 // list is deleted by the TSelector dtor
59}
60
61void AliSelector::Begin(TTree *)
62{
63 // The Begin() function is called at the start of the query.
64 // When running with PROOF Begin() is only called on the client.
65 // The tree argument is deprecated (on PROOF 0 is passed).
66}
67
68void AliSelector::SlaveBegin(TTree * tree)
69{
70 // The SlaveBegin() function is called after the Begin() function.
71 // When running with PROOF SlaveBegin() is called on each slave server.
72 // The tree argument is deprecated (on PROOF 0 is passed).
73
74 Init(tree);
75
76 printf("=======SLAVEBEGIN========\n");
77 gSystem->Exec("hostname");
78 gSystem->Exec("date");
79 TFile *f = fChain->GetCurrentFile();
80 printf("%s\n",f->GetName());
81
82 TString option = GetOption();
83}
84
85void AliSelector::Init(TTree *tree)
86{
87 // The Init() function is called when the selector needs to initialize
88 // a new tree or chain. Typically here the branch addresses of the tree
89 // will be set. It is normaly not necessary to make changes to the
90 // generated code, but the routine can be extended by the user if needed.
91 // Init() will be called many times when running with PROOF.
92
93 printf("=========Init==========\n");
94
95 // Set branch addresses
96 if (tree == 0)
97 {
98 printf("ERROR: tree argument is 0.\n");
99 return;
100 }
101
102 fChain = dynamic_cast<TChain*> (tree);
103 if (fChain == 0)
104 {
105 printf("ERROR: tree argument could not be casted to TChain.\n");
106 return;
107 }
108
109 fChain->SetBranchAddress("ESD", &fESD);
110 if (fESD != 0)
111 printf("INFO: Found ESD branch in chain.\n");
112
113 fChain->SetBranchAddress("Header", &fHeader);
114 if (fHeader != 0)
115 printf("INFO: Found event header branch in chain.\n");
116
117}
118
119Bool_t AliSelector::Notify()
120{
121 // The Notify() function is called when a new file is opened. This
122 // can be either for a new TTree in a TChain or when when a new TTree
123 // is started when using PROOF. Typically here the branch pointers
124 // will be retrieved. It is normaly not necessary to make changes
125 // to the generated code, but the routine can be extended by the
126 // user if needed.
127
128 printf("=========NOTIFY==========\n");
129 gSystem->Exec("hostname");
130 gSystem->Exec("date");
131 TFile *f = fChain->GetCurrentFile();
132 TString fileName(f->GetName());
133 printf("%s\n",fileName.Data());
134
135 DeleteKinematicsFile();
136 DeleteRunLoader();
137
138 return kTRUE;
139}
140
141Bool_t AliSelector::Process(Long64_t entry)
142{
143 // The Process() function is called for each entry in the tree (or possibly
144 // keyed object in the case of PROOF) to be processed. The entry argument
145 // specifies which entry in the currently loaded tree is to be processed.
146 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
147 // to read either all or the required parts of the data. When processing
148 // keyed objects with PROOF, the object is already loaded and is available
149 // via the fObject pointer.
150 //
151 // This function should contain the "body" of the analysis. It can contain
152 // simple or elaborate selection criteria, run algorithms on the data
153 // of the event and typically fill histograms.
154
155 // WARNING when a selector is used with a TChain, you must use
156 // the pointer to the current TTree to call GetEntry(entry).
157 // The entry is always the local entry number in the current tree.
158 // Assuming that fChain is the pointer to the TChain being processed,
159 // use fChain->GetTree()->GetEntry(entry).
160
161 printf("=========PROCESS========== Entry %lld\n", entry);
162
163 if (!fChain)
164 {
165 printf("ERROR: fChain is 0.\n");
166 return kFALSE;
167 }
168
169 fChain->GetTree()->GetEntry(entry);
170
171 if (fESD)
172 printf("ESD: We have %d tracks.\n", fESD->GetNumberOfTracks());
173
174 if (fHeader)
175 printf("Header: We have %d primaries.\n", fHeader->GetNprimary());
176
177 TTree* kinematics = GetKinematics();
178 if (kinematics)
179 printf("Kinematics from folder: We have %lld particles.\n", kinematics->GetEntries());
180
181 printf("\n");
182
183 return kTRUE;
184}
185
186void AliSelector::SlaveTerminate()
187{
188 // The SlaveTerminate() function is called after all entries or objects
189 // have been processed. When running with PROOF SlaveTerminate() is called
190 // on each slave server.
191
192 DeleteKinematicsFile();
193 DeleteRunLoader();
194}
195
196void AliSelector::Terminate()
197{
198 // The Terminate() function is the last function to be called during
199 // a query. It always runs on the client, it can be used to present
200 // the results graphically or save the results to file.
201
202 printf("=========TERMINATE==========\n");
203}
204
205TTree* AliSelector::GetKinematics()
206{
207 // Returns kinematics tree corresponding to current ESD active in fChain
208 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
209 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
210
211 if (!fKineFile)
212 {
213 if (!fChain->GetCurrentFile())
214 return 0;
215
216 TString fileName(fChain->GetCurrentFile()->GetName());
217 fileName.ReplaceAll("AliESDs", "Kinematics");
218
219 fKineFile = TFile::Open(fileName);
220 if (!fKineFile)
221 return 0;
222 }
223
224 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
225
226 /* this is if we want to get it from a TChain
227
228 define it in the header:
229
230 TChain* fKineChain;
231
232 this creates the chain:
233
234 TChain* chainKine = new TChain("TreeK");
235 for (Int_t i=0; i<20; ++i)
236 chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
237 for (Int_t i=0; i<20; ++i)
238 chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
239
240 <mainChain>->GetUserInfo()->Add(chainKine);
241
242 we retrieve it in init:
243
244 fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
245
246 and use it in process:
247
248 if (fKineChain)
249 {
250 Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
251 cout << "Entry in fKineChain: " << entryK << endl;
252 fKineChain->LoadTree(entryK);
253 TTree* kineTree = fKineChain->GetTree();
254
255 printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
256 }
257 */
258}
259
260void AliSelector::DeleteKinematicsFile()
261{
262 //
263 // Closes the kinematics file and deletes the pointer.
264 //
265
266 if (fKineFile)
267 {
268 fKineFile->Close();
269 delete fKineFile;
270 fKineFile = 0;
271 }
272}
273
274AliRun* AliSelector::GetAliRun()
275{
276 // Returns AliRun instance corresponding to current ESD active in fChain
277 // Loads galice.root, the file is identified by replacing "AliESDs" to
278 // "galice" in the file path of the ESD file. This is a hack, to be changed!
279
280 if (!fRunLoader)
281 {
282 if (!fChain->GetCurrentFile())
283 return 0;
284
285 TString fileName(fChain->GetCurrentFile()->GetName());
286 fileName.ReplaceAll("AliESDs", "galice");
287
288 fRunLoader = AliRunLoader::Open(fileName);
289 if (!fRunLoader)
290 return 0;
291
292 fRunLoader->LoadgAlice();
293 }
294
295 return fRunLoader->GetAliRun();
296}
297
298void AliSelector::DeleteRunLoader()
299{
300 //
301 // deletes the runloader
302 //
303
304 if (fRunLoader)
305 {
306 fRunLoader->Delete();
307 fRunLoader = 0;
308 }
309}