]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/AliSelector.cxx
o) adding log tags to all files
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
CommitLineData
dc740de4 1/* $Id$ */
2
539b6cb4 3// The class definition in esdV0.h has been generated automatically
4// by the ROOT utility TTree::MakeSelector(). This class is derived
5// from the ROOT class TSelector. For more information on the TSelector
6// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
7
8// The following methods are defined in this file:
9// Begin(): called everytime a loop on the tree starts,
10// a convenient place to create your histograms.
11// SlaveBegin(): called after Begin(), when on PROOF called only on the
12// slave servers.
13// Process(): called for each event, in this function you decide what
14// to read and fill your histograms.
15// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
16// called only on the slave servers.
17// Terminate(): called at the end of the loop on the tree,
18// a convenient place to draw/fit your histograms.
19//
20// To use this file, try the following session on your Tree T:
21//
22// Root > T->Process("AliSelector.C")
23// Root > T->Process("AliSelector.C","some options")
24// Root > T->Process("AliSelector.C+")
25//
26
27#include "AliSelector.h"
b8e8168f 28
539b6cb4 29#include <TStyle.h>
30#include <TSystem.h>
31#include <TCanvas.h>
32#include <TRegexp.h>
b8e8168f 33#include <TTime.h>
4dd2ad81 34#include <TParticle.h>
35#include <TParticlePDG.h>
dc740de4 36#include <TFriendElement.h>
539b6cb4 37
b8e8168f 38#include <AliLog.h>
539b6cb4 39
40ClassImp(AliSelector)
41
ee998961 42AliSelector::AliSelector() :
539b6cb4 43 TSelector(),
44 fChain(0),
45 fESD(0),
dc740de4 46 fCountFiles(0),
47 fKineFile(0),
48 fHeaderFile(0),
49 fHeaderTree(0),
50 fHeader(0)
539b6cb4 51{
79ab56b9 52 //
539b6cb4 53 // Constructor. Initialization of pointers
79ab56b9 54 //
539b6cb4 55}
56
57AliSelector::~AliSelector()
58{
79ab56b9 59 //
60 // Destructor
61 //
539b6cb4 62
63 // histograms are in the output list and deleted when the output
64 // list is deleted by the TSelector dtor
65}
66
67void AliSelector::Begin(TTree *)
68{
69 // The Begin() function is called at the start of the query.
70 // When running with PROOF Begin() is only called on the client.
71 // The tree argument is deprecated (on PROOF 0 is passed).
539b6cb4 72}
73
74void AliSelector::SlaveBegin(TTree * tree)
75{
76 // The SlaveBegin() function is called after the Begin() function.
77 // When running with PROOF SlaveBegin() is called on each slave server.
78 // The tree argument is deprecated (on PROOF 0 is passed).
79
80 Init(tree);
81
b8e8168f 82 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
83 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
84 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
539b6cb4 85
86 TString option = GetOption();
87}
88
89void AliSelector::Init(TTree *tree)
90{
91 // The Init() function is called when the selector needs to initialize
92 // a new tree or chain. Typically here the branch addresses of the tree
93 // will be set. It is normaly not necessary to make changes to the
94 // generated code, but the routine can be extended by the user if needed.
95 // Init() will be called many times when running with PROOF.
96
b8e8168f 97 AliDebug(AliLog::kDebug, "=========Init==========");
539b6cb4 98
99 // Set branch addresses
100 if (tree == 0)
101 {
b8e8168f 102 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
539b6cb4 103 return;
104 }
105
106 fChain = dynamic_cast<TChain*> (tree);
107 if (fChain == 0)
108 {
b8e8168f 109 AliDebug(AliLog::kDebug, "ERROR: tree argument could not be casted to TChain.");
539b6cb4 110 return;
111 }
112
113 fChain->SetBranchAddress("ESD", &fESD);
114 if (fESD != 0)
b8e8168f 115 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
539b6cb4 116
dc740de4 117 /*fChain->SetBranchAddress("Header", &fHeader);
539b6cb4 118 if (fHeader != 0)
dc740de4 119 AliDebug(AliLog::kInfo, "INFO: Found event header branch in chain.");*/
539b6cb4 120}
121
122Bool_t AliSelector::Notify()
123{
124 // The Notify() function is called when a new file is opened. This
125 // can be either for a new TTree in a TChain or when when a new TTree
126 // is started when using PROOF. Typically here the branch pointers
127 // will be retrieved. It is normaly not necessary to make changes
128 // to the generated code, but the routine can be extended by the
129 // user if needed.
130
b8e8168f 131 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
132 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
133 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
ee998961 134
dc740de4 135 ++fCountFiles;
539b6cb4 136 TFile *f = fChain->GetCurrentFile();
dc740de4 137 AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
539b6cb4 138
139 DeleteKinematicsFile();
dc740de4 140 DeleteHeaderFile();
141
142 /*TChain* headerChain = dynamic_cast<TChain*> (((TFriendElement*) fChain->GetListOfFriends()->First())->GetTree());
143 AliDebug(AliLog::kInfo, Form("Header File: %s", headerChain->GetCurrentFile()->GetName()));*/
539b6cb4 144
145 return kTRUE;
146}
147
148Bool_t AliSelector::Process(Long64_t entry)
149{
150 // The Process() function is called for each entry in the tree (or possibly
151 // keyed object in the case of PROOF) to be processed. The entry argument
152 // specifies which entry in the currently loaded tree is to be processed.
153 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
154 // to read either all or the required parts of the data. When processing
155 // keyed objects with PROOF, the object is already loaded and is available
156 // via the fObject pointer.
157 //
158 // This function should contain the "body" of the analysis. It can contain
159 // simple or elaborate selection criteria, run algorithms on the data
160 // of the event and typically fill histograms.
161
162 // WARNING when a selector is used with a TChain, you must use
163 // the pointer to the current TTree to call GetEntry(entry).
164 // The entry is always the local entry number in the current tree.
165 // Assuming that fChain is the pointer to the TChain being processed,
166 // use fChain->GetTree()->GetEntry(entry).
167
b8e8168f 168 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
539b6cb4 169
170 if (!fChain)
171 {
b8e8168f 172 AliDebug(AliLog::kError, "ERROR: fChain is 0.");
539b6cb4 173 return kFALSE;
174 }
175
176 fChain->GetTree()->GetEntry(entry);
177
dc740de4 178 /*
179 // debugging
539b6cb4 180 if (fESD)
b8e8168f 181 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
539b6cb4 182
183 if (fHeader)
b8e8168f 184 AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
539b6cb4 185
186 TTree* kinematics = GetKinematics();
187 if (kinematics)
b8e8168f 188 AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
dc740de4 189 */
539b6cb4 190
191 return kTRUE;
192}
193
194void AliSelector::SlaveTerminate()
195{
196 // The SlaveTerminate() function is called after all entries or objects
197 // have been processed. When running with PROOF SlaveTerminate() is called
198 // on each slave server.
199
200 DeleteKinematicsFile();
dc740de4 201 DeleteHeaderFile();
539b6cb4 202}
203
204void AliSelector::Terminate()
205{
206 // The Terminate() function is the last function to be called during
207 // a query. It always runs on the client, it can be used to present
208 // the results graphically or save the results to file.
209
b8e8168f 210 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
539b6cb4 211}
212
213TTree* AliSelector::GetKinematics()
214{
79ab56b9 215 // Returns kinematics tree corresponding to current ESD active in fChain
216 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
217 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
218
539b6cb4 219 if (!fKineFile)
220 {
221 if (!fChain->GetCurrentFile())
222 return 0;
223
224 TString fileName(fChain->GetCurrentFile()->GetName());
225 fileName.ReplaceAll("AliESDs", "Kinematics");
226
dc740de4 227 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
228
539b6cb4 229 fKineFile = TFile::Open(fileName);
230 if (!fKineFile)
231 return 0;
232 }
233
234 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
235
236 /* this is if we want to get it from a TChain
237
238 define it in the header:
239
240 TChain* fKineChain;
241
242 this creates the chain:
243
244 TChain* chainKine = new TChain("TreeK");
245 for (Int_t i=0; i<20; ++i)
246 chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
247 for (Int_t i=0; i<20; ++i)
248 chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
249
250 <mainChain>->GetUserInfo()->Add(chainKine);
251
252 we retrieve it in init:
253
254 fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
255
256 and use it in process:
257
258 if (fKineChain)
259 {
260 Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
261 cout << "Entry in fKineChain: " << entryK << endl;
262 fKineChain->LoadTree(entryK);
263 TTree* kineTree = fKineChain->GetTree();
264
265 printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
266 }
267 */
268}
269
270void AliSelector::DeleteKinematicsFile()
271{
79ab56b9 272 //
273 // Closes the kinematics file and deletes the pointer.
274 //
275
539b6cb4 276 if (fKineFile)
277 {
278 fKineFile->Close();
279 delete fKineFile;
280 fKineFile = 0;
281 }
282}
283
dc740de4 284AliHeader* AliSelector::GetHeader()
285{
286 // Returns header corresponding to current ESD active in fChain
287 // Loads the header from galice.root, the file is identified by replacing "AliESDs" to
288 // "galice" in the file path of the ESD file. This is a hack, to be changed!
289
290 if (!fHeaderFile || !fHeaderTree)
291 {
292 if (!fChain->GetCurrentFile())
293 return 0;
294
295 TString fileName(fChain->GetCurrentFile()->GetName());
296 fileName.ReplaceAll("AliESDs", "galice");
297
298 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
299
300 fHeaderFile = TFile::Open(fileName);
301 if (!fHeaderFile)
302 return 0;
303
304 fHeaderTree = dynamic_cast<TTree*> (fHeaderFile->Get("TE"));
305 if (!fHeaderTree)
306 return 0;
307
308 fHeaderTree->SetBranchAddress("Header", &fHeader);
309 }
310
311 fHeaderTree->GetEntry(fChain->GetTree()->GetReadEntry());
312
313 return fHeader;
314}
315
316void AliSelector::DeleteHeaderFile()
317{
318 //
319 // Closes the kinematics file and deletes the pointer.
320 //
321
322 if (fHeaderFile)
323 {
324 fHeaderFile->Close();
325 delete fHeaderFile;
326 fHeaderTree = 0;
327 fHeader = 0;
328 }
329}
330
4dd2ad81 331Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
332{
333 //
334 // Returns if the given particle is a primary particle
335 // This function or a equivalent should be available in some common place of AliRoot
336 //
337
338 // if the particle has a daughter primary, we do not want to count it
339 if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
dc740de4 340 {
341 AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries.");
4dd2ad81 342 return kFALSE;
dc740de4 343 }
4dd2ad81 344
345 Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
346
347 // skip quarks and gluon
348 if (pdgCode <= 10 || pdgCode == 21)
dc740de4 349 {
350 AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon.");
4dd2ad81 351 return kFALSE;
dc740de4 352 }
4dd2ad81 353
354 if (strcmp(aParticle->GetName(),"XXX") == 0)
355 {
356 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
357 return kFALSE;
358 }
359
360 TParticlePDG* pdgPart = aParticle->GetPDG();
361
362 if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
363 {
364 AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
365 return kFALSE;
366 }
367
368 if (pdgPart->Charge() == 0)
dc740de4 369 {
4dd2ad81 370 return kFALSE;
dc740de4 371 AliDebug(AliLog::kDebug+1, "Dropping particle because it is not charged.");
372 }
4dd2ad81 373
374 return kTRUE;
375}