]>
Commit | Line | Data |
---|---|---|
dd2b6810 | 1 | #include "AliAOD.h" |
a5556ea5 | 2 | /************************************************************************** |
3 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
4 | * * | |
5 | * Author: The ALICE Off-line Project. * | |
6 | * Contributors are mentioned in the code where appropriate. * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
17 | /* $Id$ */ | |
18 | ||
19 | ///////////////////////////////////////////////////////////// | |
20 | // | |
21 | // base class for AOD containers | |
22 | // | |
23 | ///////////////////////////////////////////////////////////// | |
24 | ||
7f03938c | 25 | #include <TROOT.h> |
a5556ea5 | 26 | #include <TParticle.h> |
dd2b6810 | 27 | #include <TClass.h> |
28 | #include <TString.h> | |
afa8b37b | 29 | #include "AliAODParticle.h" |
0d8a4589 | 30 | #include "AliTrackPoints.h" |
a5556ea5 | 31 | |
32 | ClassImp(AliAOD) | |
33 | ||
0d8a4589 | 34 | AliAOD::AliAOD(): |
dd2b6810 | 35 | fParticles(0x0), |
0d8a4589 | 36 | fIsRandomized(kFALSE), |
37 | fPrimaryVertexX(0.0), | |
38 | fPrimaryVertexY(0.0), | |
dd2b6810 | 39 | fPrimaryVertexZ(0.0), |
40 | fParticleClass(0x0) | |
0d8a4589 | 41 | { |
42 | //ctor | |
dd2b6810 | 43 | // Info("AliAOD()","Entered"); |
44 | // SetOwner(kTRUE); | |
45 | // Info("AliAOD()","Exited"); | |
46 | } | |
47 | /**************************************************************************/ | |
48 | ||
efdb0cc9 | 49 | AliAOD::AliAOD(const AliAOD& in): |
50 | TObject(in), | |
51 | fParticles((TClonesArray*)in.fParticles->Clone()), | |
52 | fIsRandomized(in.fIsRandomized), | |
53 | fPrimaryVertexX(fPrimaryVertexX), | |
54 | fPrimaryVertexY(in.fPrimaryVertexY), | |
55 | fPrimaryVertexZ(in.fPrimaryVertexZ), | |
56 | fParticleClass(in.fParticleClass) | |
57 | { | |
58 | //copy constructor | |
59 | } | |
60 | /**************************************************************************/ | |
61 | ||
62 | AliAOD& AliAOD::operator=(const AliAOD& in) | |
63 | { | |
64 | //assigment operator | |
65 | ||
66 | if (this == &in ) return *this; | |
67 | ||
68 | delete fParticles; | |
69 | fParticles = (TClonesArray*)in.fParticles->Clone(); | |
70 | fIsRandomized = in.fIsRandomized ; | |
71 | fPrimaryVertexX = in.fPrimaryVertexX ; | |
72 | fPrimaryVertexY = in.fPrimaryVertexY ; | |
73 | fPrimaryVertexZ = in.fPrimaryVertexZ ; | |
74 | fParticleClass = in.fParticleClass ; //althought it is pointer, this points to object in class list of gROOT | |
75 | return *this; | |
76 | } | |
77 | ||
78 | /**************************************************************************/ | |
79 | ||
dd2b6810 | 80 | AliAOD::~AliAOD() |
81 | { | |
82 | //Destructor | |
83 | //fParticleClass does not belong to AliAOD -> Do not delete it | |
84 | delete fParticles; | |
85 | ||
86 | } | |
87 | /**************************************************************************/ | |
88 | ||
efdb0cc9 | 89 | void AliAOD::CopyData(AliAOD* aod) |
90 | { | |
91 | //Copys all data from aod, but leaves local type of particles | |
92 | if (aod == 0x0) return; | |
93 | if (aod == this) return; | |
94 | ||
95 | AliAOD& in = *this; | |
96 | ||
97 | fIsRandomized = in.fIsRandomized ; | |
98 | fPrimaryVertexX = in.fPrimaryVertexX ; | |
99 | fPrimaryVertexY = in.fPrimaryVertexY ; | |
100 | fPrimaryVertexZ = in.fPrimaryVertexZ ; | |
101 | fParticleClass = in.fParticleClass ; //althought it is pointer, this points to object in class list of gROOT | |
102 | ||
103 | ||
104 | if (in.fParticles == 0x0) | |
105 | {//if in obj has null fParticles we delete ours | |
106 | delete fParticles; | |
107 | fParticles = 0x0; | |
108 | } | |
109 | else | |
110 | { | |
111 | if (fParticles) | |
112 | { //if ours particles were already created | |
113 | if (fParticles->GetClass() != in.fParticles->GetClass()) | |
114 | {//if in obj has | |
115 | delete fParticles; | |
116 | fParticles = (TClonesArray*)in.fParticles->Clone(); | |
117 | } | |
118 | else | |
119 | { | |
120 | //it should be faster than cloning | |
121 | Int_t inentr = in.fParticles->GetEntriesFast(); | |
122 | Int_t curentr = fParticles->GetEntriesFast(); | |
123 | ||
124 | TClonesArray& arr = *fParticles; | |
125 | ||
126 | //we have to take care about different sizes of arrays | |
127 | if ( curentr < inentr ) | |
128 | { | |
129 | for (Int_t i = 0; i < curentr; i++) | |
130 | { | |
131 | TObject& inobj = *(in.fParticles->At(i)); | |
132 | TObject& obj = *(fParticles->At(i)); | |
133 | obj = inobj; | |
134 | } | |
135 | ||
136 | for (Int_t i = curentr; i < inentr; i++) | |
137 | { | |
138 | TObject& inobj = *(in.fParticles->At(i)); | |
139 | TObject& obj = *((TObject*)(fParticleClass->New(arr[i]))); | |
140 | obj = inobj; | |
141 | } | |
142 | } | |
143 | else | |
144 | { | |
145 | for (Int_t i = 0; i < inentr; i++) | |
146 | { | |
147 | TObject& inobj = *(in.fParticles->At(i)); | |
148 | TObject& obj = *(fParticles->At(i)); | |
149 | obj = inobj; | |
150 | } | |
151 | ||
152 | for (Int_t i = curentr ; i >= inentr ; i--) | |
153 | { | |
154 | fParticles->RemoveAt(i); | |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
159 | else | |
160 | { | |
161 | fParticles = (TClonesArray*)in.fParticles->Clone(); | |
162 | } | |
163 | } | |
164 | ||
165 | } | |
166 | /**************************************************************************/ | |
167 | ||
dd2b6810 | 168 | void AliAOD::SetParticleClassName(const char* classname) |
169 | { | |
170 | //Sets type of particle that is going to be stored | |
171 | if (gROOT == 0x0) Fatal("SetParticleClassName","ROOT System not initialized"); | |
172 | TClass* pclass = gROOT->GetClass(classname); | |
173 | if ( pclass == 0x0 ) | |
174 | { | |
175 | Error("SetParticleClass","Can not get TClass for class named %s",classname); | |
176 | return; | |
177 | } | |
178 | SetParticleClass(pclass); | |
179 | } | |
180 | /**************************************************************************/ | |
181 | ||
182 | void AliAOD::SetParticleClass(TClass* pclass) | |
183 | { | |
184 | //Sets type of particle that is going to be stored | |
185 | ||
186 | if ( pclass == 0x0 ) | |
187 | { | |
188 | Error("SetParticleClass","Parameter is NULL."); | |
189 | return; | |
190 | } | |
191 | ||
192 | if ( pclass->InheritsFrom("AliVAODParticle") == kFALSE ) | |
193 | { | |
194 | Error("SetParticleClass","Class named %s does not inherit from AliVAODParticle",pclass->GetName()); | |
195 | return; | |
196 | } | |
197 | if (pclass != fParticleClass) | |
198 | { | |
199 | fParticleClass = pclass; | |
200 | if (fParticleClass) delete fParticles; | |
201 | fParticles = new TClonesArray(fParticleClass); | |
202 | } | |
0d8a4589 | 203 | } |
204 | ||
a5556ea5 | 205 | /**************************************************************************/ |
206 | ||
207 | void AliAOD::AddParticle(TParticle* part, Int_t idx) | |
208 | { | |
209 | //Adds TParticle to event | |
210 | if (part == 0x0) | |
211 | { | |
212 | Error("AddParticle(TParticle*,Int_t)","pointer to particle is NULL"); | |
213 | return; | |
214 | } | |
dd2b6810 | 215 | |
216 | if (fParticles == 0x0) SetParticleClassName("AliAODParticle"); | |
afa8b37b | 217 | AddParticle( new AliAODParticle(*part,idx) ); |
a5556ea5 | 218 | } |
219 | /**************************************************************************/ | |
220 | ||
dd2b6810 | 221 | void AliAOD::AddParticle(AliVAODParticle* particle) |
222 | { | |
223 | //add particle to AOD | |
224 | //MAKES ITS OWN COPY OF THE PARTICLE!!! (AOD is not going to keep and delete input pointer) | |
225 | ||
226 | if (fParticles == 0x0) SetParticleClassName("AliAODParticle"); | |
227 | ||
228 | Int_t idx = fParticles->GetLast() + 1; | |
229 | TClonesArray& arr = *fParticles; | |
230 | ||
231 | AliVAODParticle* pp = (AliVAODParticle*)fParticleClass->New(arr[idx]); | |
232 | pp->operator=(*particle); | |
233 | ||
234 | } | |
235 | /**************************************************************************/ | |
236 | ||
a5556ea5 | 237 | void AliAOD::AddParticle(Int_t pdg, Int_t idx, |
238 | Double_t px, Double_t py, Double_t pz, Double_t etot, | |
239 | Double_t vx, Double_t vy, Double_t vz, Double_t time) | |
240 | { | |
dd2b6810 | 241 | //adds particle to event (standard AOD class) |
242 | ||
243 | if (fParticles == 0x0) SetParticleClassName("AliAODParticle"); | |
244 | ||
245 | Int_t newpartidx = fParticles->GetLast() + 1; | |
246 | TClonesArray& arr = *fParticles; | |
247 | ||
248 | AliVAODParticle* p = (AliVAODParticle*)fParticleClass->New(arr[newpartidx]); | |
249 | ||
250 | p->SetPdgCode(pdg); | |
251 | p->SetUID(idx); | |
252 | p->SetMomentum(px,py,pz,etot); | |
253 | p->SetProductionVertex(vx,vy,vz,time); | |
254 | ||
a5556ea5 | 255 | } |
256 | /**************************************************************************/ | |
257 | ||
258 | void AliAOD::SwapParticles(Int_t i, Int_t j) | |
259 | { | |
260 | //swaps particles positions; used by AliHBTEvent::Blend | |
261 | if ( (i<0) || (i>=GetNumberOfParticles()) ) return; | |
262 | if ( (j<0) || (j>=GetNumberOfParticles()) ) return; | |
dd2b6810 | 263 | |
264 | AliVAODParticle* tmpobj = (AliVAODParticle*)fParticleClass->New(); | |
265 | AliVAODParticle& tmp = *tmpobj; | |
266 | AliVAODParticle& first = *(GetParticle(i)); | |
267 | AliVAODParticle& second = *(GetParticle(j)); | |
268 | ||
269 | tmp = first; | |
270 | first = second; | |
271 | second = tmp; | |
e1a64564 | 272 | delete tmpobj; |
a5556ea5 | 273 | } |
274 | /**************************************************************************/ | |
275 | ||
276 | void AliAOD::Reset() | |
277 | { | |
278 | //deletes all particles from the event | |
dd2b6810 | 279 | if (fParticles) fParticles->Clear("C"); |
280 | ||
281 | fIsRandomized = kFALSE; | |
a5556ea5 | 282 | } |
0d8a4589 | 283 | /**************************************************************************/ |
284 | ||
285 | void AliAOD::GetPrimaryVertex(Double_t&x, Double_t&y, Double_t&z) | |
286 | { | |
287 | //returns positions of the primary vertex | |
288 | x = fPrimaryVertexX; | |
289 | y = fPrimaryVertexY; | |
290 | z = fPrimaryVertexZ; | |
291 | } | |
292 | /**************************************************************************/ | |
293 | ||
294 | void AliAOD::SetPrimaryVertex(Double_t x, Double_t y, Double_t z) | |
295 | { | |
296 | //Sets positions of the primary vertex | |
297 | fPrimaryVertexX = x; | |
298 | fPrimaryVertexY = y; | |
299 | fPrimaryVertexZ = z; | |
300 | } | |
301 | /**************************************************************************/ | |
302 | ||
303 | Int_t AliAOD::GetNumberOfCharged(Double_t etamin, Double_t etamax) const | |
304 | { | |
305 | //reurns number of charged particles within given pseudorapidity range | |
29e00d75 | 306 | Int_t n = 0; |
dd2b6810 | 307 | Int_t npart = GetNumberOfParticles(); |
0d8a4589 | 308 | for (Int_t i = 0; i < npart; i++) |
309 | { | |
dd2b6810 | 310 | AliVAODParticle* p = GetParticle(i); |
0d8a4589 | 311 | Double_t eta = p->Eta(); |
312 | if ( (eta < etamin) || (eta > etamax) ) continue; | |
313 | if (p->Charge() != 0.0) n++; | |
314 | } | |
29e00d75 | 315 | return n; |
0d8a4589 | 316 | } |
317 | /**************************************************************************/ | |
318 | ||
319 | void AliAOD::Move(Double_t x, Double_t y, Double_t z) | |
320 | { | |
321 | //moves all spacial coordinates about this vector | |
322 | // vertex | |
323 | // track points | |
324 | // and whatever will be added to AOD and AOD particles that is a space coordinate | |
325 | ||
326 | fPrimaryVertexX += x; | |
327 | fPrimaryVertexY += y; | |
328 | fPrimaryVertexZ += z; | |
329 | ||
dd2b6810 | 330 | Int_t npart = GetNumberOfParticles(); |
0d8a4589 | 331 | for (Int_t i = 0; i < npart; i++) |
332 | { | |
dd2b6810 | 333 | AliVAODParticle* p = GetParticle(i); |
0d8a4589 | 334 | AliTrackPoints* tp = p->GetTPCTrackPoints(); |
335 | if (tp) tp->Move(x,y,z); | |
336 | tp = p->GetITSTrackPoints(); | |
337 | if (tp) tp->Move(x,y,z); | |
338 | } | |
339 | } | |
dd2b6810 | 340 | |
341 | void AliAOD::Print(Option_t* /*option*/) | |
342 | { | |
343 | //Prints AOD | |
344 | TString ts; | |
345 | TString msg("\n"); | |
346 | msg+="Particle Class: "; | |
347 | if (fParticleClass) | |
348 | { | |
349 | msg+=fParticleClass->GetName(); | |
350 | } | |
351 | else | |
352 | { | |
353 | msg+="Not specified yet"; | |
354 | } | |
355 | msg += "\n"; | |
356 | msg += "Vertex position X: "; | |
357 | msg += fPrimaryVertexX; | |
358 | msg += " Y:" ; | |
359 | msg += fPrimaryVertexY; | |
360 | msg += " Z:"; | |
361 | msg += fPrimaryVertexZ; | |
362 | msg += "\n"; | |
363 | ||
364 | msg += "Randomized: "; | |
365 | msg += fIsRandomized; | |
366 | msg += "\n"; | |
367 | ||
368 | Info("Print","%s",msg.Data()); | |
369 | ||
370 | Int_t npart = GetNumberOfParticles(); | |
371 | Info("Print","Npart: %d",npart); | |
372 | for (Int_t i = 0; i < npart; i++) | |
373 | { | |
374 | Info("Print","Getting particle %d",i); | |
375 | AliVAODParticle* p = GetParticle(i); | |
376 | Info("Print","Printing particle %d, address %#x",i,p); | |
377 | p->Dump(); | |
378 | p->Print(); | |
379 | Info("Print","particle %d printed",i); | |
380 | } | |
381 | } | |
382 | ||
383 | void AliAOD::SetOwner(Bool_t /*owner*/) | |
384 | { | |
385 | //Sets the ownership of particles: if particles should be also deleted if AOD is deleted/reseted | |
386 | //Since fParticles is Clones and not Object Array, it is always the owner and this method does not have sense | |
387 | ||
388 | MayNotUse("SetOwner"); | |
389 | //if fParticles->SetOwner(owner); | |
390 | ||
391 | } |