]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | ClassImp(AliJetParticlesReaderKine) | |
25 | ||
26 | ||
27 | /**********************************************************/ | |
28 | ||
29 | AliJetParticlesReaderKine::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 | ||
42 | AliJetParticlesReaderKine::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 | ||
54 | AliJetParticlesReaderKine::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 | ||
66 | AliJetParticlesReaderKine::~AliJetParticlesReaderKine() | |
67 | { | |
68 | //destructor | |
69 | if(fRunLoader) delete fRunLoader; | |
70 | } | |
71 | ||
72 | /**********************************************************/ | |
73 | ||
74 | void 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 | ||
85 | Int_t AliJetParticlesReaderKine::ReadNext() | |
86 | { | |
87 | //Reads Kinematics Tree | |
88 | ||
89 | if((!fOwner) || (fEventParticles == 0)) | |
90 | fEventParticles = new AliJetEventParticles(); | |
91 | ||
92 | do | |
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 | ||
125 | Int_t npart = stack->GetNprimary(); | |
126 | if(fUseTracks) | |
127 | npart = stack->GetNtrack(); | |
128 | ||
129 | fEventParticles->Reset(npart); | |
130 | for (Int_t i = 0;i<npart; i++) | |
131 | { | |
132 | TParticle *p = stack->Particle(i); | |
133 | if(!p) continue; | |
134 | if(p->GetFirstMother() >= 0) continue; | |
135 | ||
136 | if(IsAcceptedParticle(p)) //put particle in event | |
137 | fEventParticles->AddParticle(p,i); | |
138 | } | |
139 | ||
140 | fCurrentEvent++; | |
141 | fNEventsRead++; | |
142 | return kTRUE; | |
143 | } while(fCurrentDir < GetNumberOfDirs()); | |
144 | //end of loop over directories specified in fDirs Obj Array | |
145 | return kFALSE; | |
146 | } | |
147 | ||
148 | /**********************************************************/ | |
149 | ||
150 | Int_t AliJetParticlesReaderKine::OpenFile(Int_t n) | |
151 | { | |
152 | //opens file with kine tree | |
153 | ||
154 | const TString& dirname = GetDirName(n); | |
155 | if (dirname == "") | |
156 | { | |
157 | Error("OpenNextFile","Can not get directory name with index %d",n); | |
158 | return kFALSE; | |
159 | } | |
160 | ||
161 | TString filename = dirname +"/"+ fFileName; | |
162 | fRunLoader = AliRunLoader::Open(filename.Data()); | |
163 | ||
164 | if (fRunLoader == 0) | |
165 | { | |
166 | Error("OpenNextFile","Can't open session from file %s",filename.Data()); | |
167 | return kFALSE; | |
168 | } | |
169 | ||
170 | if (fRunLoader->GetNumberOfEvents() <= 0) | |
171 | { | |
172 | Error("OpenNextFile","There is no events in this directory."); | |
173 | delete fRunLoader; | |
174 | fRunLoader = 0; | |
175 | return kFALSE; | |
176 | } | |
177 | ||
178 | if (fRunLoader->LoadKinematics()) | |
179 | { | |
180 | Error("OpenNextFile","Error occured while loading kinematics."); | |
181 | return kFALSE; | |
182 | } | |
183 | ||
184 | fCurrentEvent = 0; | |
185 | return kTRUE; | |
186 | } |