Search for new detector object only in case its loader changed
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReaderKine.cxx
CommitLineData
d7c6ab14 1// $Id$
2
3//_______________________________________________________________________
4/////////////////////////////////////////////////////////////////////////
5//
6// class AliJetParticlesReaderKine
7//
8// Reader for Kinematics
9//
10// loizides@ikf.uni-frankfurt.de
11//
12/////////////////////////////////////////////////////////////////////////
13
14#include <Riostream.h>
15#include <TString.h>
16#include <TParticle.h>
17#include <AliRunLoader.h>
18#include <AliStack.h>
19
20#include "AliJetParticle.h"
21#include "AliJetEventParticles.h"
22#include "AliJetParticlesReaderKine.h"
23
24ClassImp(AliJetParticlesReaderKine)
25
26
27/**********************************************************/
28
29AliJetParticlesReaderKine::AliJetParticlesReaderKine() :
30 AliJetParticlesReader(),
31 fFileName("galice.root"),
32 fRunLoader(0),
33 fNeutral(kTRUE),fCharged(kTRUE),fEM(kTRUE),
34 fUseTracks(kFALSE)
35{
36 //constructor
37}
38
39/**********************************************************/
40
41
42AliJetParticlesReaderKine::AliJetParticlesReaderKine(TString& fname) :
43 AliJetParticlesReader(),
44 fFileName(fname),
45 fRunLoader(0),
46 fNeutral(kTRUE),fCharged(kTRUE),fEM(kTRUE),
47 fUseTracks(kFALSE)
48{
49 //constructor
50}
51
52/**********************************************************/
53
54AliJetParticlesReaderKine::AliJetParticlesReaderKine(TObjArray* dirs, const Char_t *filename):
55 AliJetParticlesReader(dirs),
56 fFileName(filename),
57 fRunLoader(0),
58 fNeutral(kTRUE),fCharged(kTRUE),fEM(kTRUE),
59 fUseTracks(kFALSE)
60{
61 //constructor
62}
63
64/**********************************************************/
65
66AliJetParticlesReaderKine::~AliJetParticlesReaderKine()
67{
68 //destructor
69 if(fRunLoader) delete fRunLoader;
70}
71
72/**********************************************************/
73
74void AliJetParticlesReaderKine::Rewind()
75{
76 //Rewinds to the beginning
77 if(fRunLoader) delete fRunLoader;
78 fRunLoader = 0;
79 fCurrentDir = 0;
80 fNEventsRead= 0;
81}
82
83/**********************************************************/
84
85Int_t AliJetParticlesReaderKine::ReadNext()
86{
87 //Reads Kinematics Tree
88
89 if((!fOwner) || (fEventParticles == 0))
90 fEventParticles = new AliJetEventParticles();
91
b2760c9e 92 while(fCurrentDir < GetNumberOfDirs())
d7c6ab14 93 {
94 if (!OpenFile(fCurrentDir))
95 {
96 fCurrentDir++;
97 continue;
98 }
99
100 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
101 {
102 //read next directory
103 delete fRunLoader; //close current session
104 fRunLoader = 0; //assure pointer is null
105 fCurrentDir++; //go to next dir
106 continue;
107 }
108
109 //Info("ReadNext","Reading Event %d",fCurrentEvent);
110
111 fRunLoader->GetEvent(fCurrentEvent);
112 AliStack* stack = fRunLoader->Stack();
113 if (!stack)
114 {
115 Error("ReadNext","Can not get stack for event %d",fCurrentEvent);
116 continue;
117 }
118
119 //get vertex
120 const TParticle *kv = stack->Particle(0);
121 if(kv) {
122 fEventParticles->SetVertex(kv->Vx(),kv->Vy(),kv->Vz());
123 }
124
03747640 125 Int_t nprim = stack->GetNprimary();
126 Int_t npart = nprim;
d7c6ab14 127 if(fUseTracks)
128 npart = stack->GetNtrack();
129
130 fEventParticles->Reset(npart);
131 for (Int_t i = 0;i<npart; i++)
132 {
133 TParticle *p = stack->Particle(i);
134 if(!p) continue;
b2760c9e 135 Int_t child1 = p->GetFirstDaughter();
136 //Int_t child2 = p->GetLastDaughter();
137 //Int_t mother = p->GetFirstMother();
03747640 138 if((child1>=0) && (child1<nprim)) continue;
b2760c9e 139 //cout << child1 << " " << child2 << " " << mother << endl;
d7c6ab14 140
141 if(IsAcceptedParticle(p)) //put particle in event
142 fEventParticles->AddParticle(p,i);
143 }
d7c6ab14 144 fCurrentEvent++;
b2760c9e 145 fCurrentDir++;
d7c6ab14 146 fNEventsRead++;
147 return kTRUE;
b2760c9e 148 }
d7c6ab14 149 //end of loop over directories specified in fDirs Obj Array
150 return kFALSE;
151}
152
153/**********************************************************/
154
155Int_t AliJetParticlesReaderKine::OpenFile(Int_t n)
156{
157 //opens file with kine tree
158
159 const TString& dirname = GetDirName(n);
160 if (dirname == "")
161 {
162 Error("OpenNextFile","Can not get directory name with index %d",n);
163 return kFALSE;
164 }
165
166 TString filename = dirname +"/"+ fFileName;
b2760c9e 167 if(fRunLoader) delete fRunLoader;
d7c6ab14 168 fRunLoader = AliRunLoader::Open(filename.Data());
169
170 if (fRunLoader == 0)
171 {
172 Error("OpenNextFile","Can't open session from file %s",filename.Data());
173 return kFALSE;
174 }
175
176 if (fRunLoader->GetNumberOfEvents() <= 0)
177 {
178 Error("OpenNextFile","There is no events in this directory.");
179 delete fRunLoader;
180 fRunLoader = 0;
181 return kFALSE;
182 }
183
184 if (fRunLoader->LoadKinematics())
185 {
186 Error("OpenNextFile","Error occured while loading kinematics.");
187 return kFALSE;
188 }
189
190 fCurrentEvent = 0;
191 return kTRUE;
192}