Realisation of AliGenReader that reads the kine tree (TreeK).
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderTreeK.cxx
CommitLineData
8020fb14 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
18*/
19#include <TFile.h>
20#include <TTree.h>
21#include <TParticle.h>
22
23#include "AliGenReaderTreeK.h"
24#include "AliStack.h"
25#include "AliHeader.h"
26#include "AliRun.h"
27
28ClassImp(AliGenReaderTreeK);
29
30
31AliGenReaderTreeK::AliGenReaderTreeK():AliGenReader()
32{
33// Default constructor
34 fFileName = NULL;
35 fStack = 0;
36 fHeader = 0;
37 fNcurrent = 0;
38 fNparticle = 0;
39 fFile = 0;
40 fBaseFile = 0;
41}
42
43void AliGenReaderTreeK::Init()
44{
45// Initialization
46// Connect base file and file to read from
47
48 TTree *ali = gAlice->TreeE();
49 if (ali) {
50 fBaseFile = ali->GetCurrentFile();
51 } else {
52 printf("\n Warning: Basefile cannot be found !\n");
53 }
54 fFile = new TFile(fFileName);
55}
56
57Int_t AliGenReaderTreeK::NextEvent()
58{
59// Read the next event
60// cd to file with old kine tree
61 if (!fBaseFile) Init();
62 if (fStack) delete fStack;
63 fStack = new AliStack(1000);
64 fFile->cd();
65// Connect treeE
66 TTree* treeE = (TTree*)gDirectory->Get("TE");
67 treeE->ls();
68 if (fHeader) delete fHeader;
69 fHeader = 0;
70 treeE->SetBranchAddress("Header", &fHeader);
71// Get next event
72 treeE->GetEntry(fNcurrent);
73 fStack = fHeader->Stack();
74 fStack->GetEvent(fNcurrent);
75
76// cd back to base file
77 fBaseFile->cd();
78//
79 fNcurrent++;
80 fNparticle = 0;
81 Int_t ntrack = fStack->GetNtrack();
82 printf("\n Next event contains %d particles", ntrack);
83
84 return ntrack;
85}
86
87TParticle* AliGenReaderTreeK::NextParticle()
88{
89// Return next particle
90 TParticle* part = fStack->Particle(fNparticle);
91 fNparticle++;
92 return part;
93}
94
95
96
97
98
99