2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 /////////////////////////////////////////////////////////////
21 // base class for AOD containers
23 /////////////////////////////////////////////////////////////
26 #include <TParticle.h>
29 #include "AliAODParticle.h"
30 #include "AliTrackPoints.h"
36 fIsRandomized(kFALSE),
43 // Info("AliAOD()","Entered");
45 // Info("AliAOD()","Exited");
47 /**************************************************************************/
49 AliAOD::AliAOD(const AliAOD& 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)
60 /**************************************************************************/
62 AliAOD& AliAOD::operator=(const AliAOD& in)
66 if (this == &in ) return *this;
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
77 /**************************************************************************/
82 //fParticleClass does not belong to AliAOD -> Do not delete it
86 /**************************************************************************/
88 void AliAOD::CopyData(AliAOD* aod)
90 //Copys all data from aod, but leaves local type of particles
91 if (aod == 0x0) return;
92 if (aod == this) return;
96 fIsRandomized = in.fIsRandomized ;
97 fPrimaryVertexX = in.fPrimaryVertexX ;
98 fPrimaryVertexY = in.fPrimaryVertexY ;
99 fPrimaryVertexZ = in.fPrimaryVertexZ ;
100 fParticleClass = in.fParticleClass ; //althought it is pointer, this points to object in class list of gROOT
103 if (in.fParticles == 0x0)
104 {//if in obj has null fParticles we delete ours
111 { //if ours particles were already created
112 if (fParticles->GetClass() != in.fParticles->GetClass())
115 fParticles = (TClonesArray*)in.fParticles->Clone();
119 //it should be faster than cloning
120 Int_t inentr = in.fParticles->GetEntriesFast();
121 Int_t curentr = fParticles->GetEntriesFast();
123 TClonesArray& arr = *fParticles;
125 //we have to take care about different sizes of arrays
126 if ( curentr < inentr )
128 for (Int_t i = 0; i < curentr; i++)
130 TObject& inobj = *(in.fParticles->At(i));
131 TObject& obj = *(fParticles->At(i));
135 TClass* partclass = GetParticleClass();
136 if (partclass == 0x0)
138 Fatal("CopyData","Can not get particle class");
142 for (Int_t i = curentr; i < inentr; i++)
144 TObject& inobj = *(in.fParticles->At(i));
145 TObject& obj = *((TObject*)(partclass->New(arr[i])));
151 for (Int_t i = 0; i < inentr; i++)
153 TObject& inobj = *(in.fParticles->At(i));
154 TObject& obj = *(fParticles->At(i));
158 for (Int_t i = curentr ; i >= inentr ; i--)
160 fParticles->RemoveAt(i);
167 fParticles = (TClonesArray*)in.fParticles->Clone();
172 /**************************************************************************/
174 void AliAOD::SetParticleClassName(const char* classname)
176 //Sets type of particle that is going to be stored
177 if (gROOT == 0x0) Fatal("SetParticleClassName","ROOT System not initialized");
178 TClass* pclass = gROOT->GetClass(classname);
181 Error("SetParticleClass","Can not get TClass for class named %s",classname);
184 SetParticleClass(pclass);
186 /**************************************************************************/
188 void AliAOD::SetParticleClass(TClass* pclass)
190 //Sets type of particle that is going to be stored
194 Error("SetParticleClass","Parameter is NULL.");
198 if ( pclass->InheritsFrom("AliVAODParticle") == kFALSE )
200 Error("SetParticleClass","Class named %s does not inherit from AliVAODParticle",pclass->GetName());
203 if (pclass != fParticleClass)
205 fParticleClass = pclass;
206 if (fParticleClass) delete fParticles;
207 fParticles = new TClonesArray(fParticleClass);
210 /**************************************************************************/
211 TClass* AliAOD::GetParticleClass()
213 //returns TClass of particle class
214 if (fParticleClass) return fParticleClass;
216 if (fParticles == 0x0) return 0x0;
218 fParticleClass = fParticles->GetClass();
219 return fParticleClass;
222 /**************************************************************************/
224 void AliAOD::AddParticle(TParticle* part, Int_t idx)
226 //Adds TParticle to event
229 Error("AddParticle(TParticle*,Int_t)","pointer to particle is NULL");
233 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
234 AddParticle( new AliAODParticle(*part,idx) );
236 /**************************************************************************/
238 void AliAOD::AddParticle(AliVAODParticle* particle)
240 //add particle to AOD
241 //MAKES ITS OWN COPY OF THE PARTICLE!!! (AOD is not going to keep and delete input pointer)
243 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
245 Int_t idx = fParticles->GetLast() + 1;
246 TClonesArray& arr = *fParticles;
248 TClass* partclass = GetParticleClass();
249 if (partclass == 0x0)
251 Error("AddParticle(AliVAODParticle*)","Can not get particle class");
255 AliVAODParticle* pp = (AliVAODParticle*)partclass->New(arr[idx]);
256 pp->operator=(*particle);
259 /**************************************************************************/
261 void AliAOD::AddParticle(Int_t pdg, Int_t idx,
262 Double_t px, Double_t py, Double_t pz, Double_t etot,
263 Double_t vx, Double_t vy, Double_t vz, Double_t time)
265 //adds particle to event (standard AOD class)
267 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
269 Int_t newpartidx = fParticles->GetLast() + 1;
270 TClonesArray& arr = *fParticles;
272 TClass* partclass = GetParticleClass();
273 if (partclass == 0x0)
275 Error("AddParticle(Int_t,...)","Can not get particle class");
279 AliVAODParticle* p = (AliVAODParticle*)partclass->New(arr[newpartidx]);
283 p->SetMomentum(px,py,pz,etot);
284 p->SetProductionVertex(vx,vy,vz,time);
287 /**************************************************************************/
289 void AliAOD::SwapParticles(Int_t i, Int_t j)
291 //swaps particles positions; used by AliHBTEvent::Blend
292 if ( (i<0) || (i>=GetNumberOfParticles()) ) return;
293 if ( (j<0) || (j>=GetNumberOfParticles()) ) return;
296 TClass* partclass = GetParticleClass();
297 if (partclass == 0x0)
299 Error("SwapParticles","Can not get particle class");
303 AliVAODParticle* tmpobj = (AliVAODParticle*)partclass->New();
304 AliVAODParticle& tmp = *tmpobj;
305 AliVAODParticle& first = *(GetParticle(i));
306 AliVAODParticle& second = *(GetParticle(j));
313 /**************************************************************************/
317 //deletes all particles from the event
318 if (fParticles) fParticles->Clear("C");
320 fIsRandomized = kFALSE;
322 /**************************************************************************/
324 void AliAOD::GetPrimaryVertex(Double_t&x, Double_t&y, Double_t&z)
326 //returns positions of the primary vertex
331 /**************************************************************************/
333 void AliAOD::SetPrimaryVertex(Double_t x, Double_t y, Double_t z)
335 //Sets positions of the primary vertex
340 /**************************************************************************/
342 Int_t AliAOD::GetNumberOfCharged(Double_t etamin, Double_t etamax) const
344 //reurns number of charged particles within given pseudorapidity range
346 Int_t npart = GetNumberOfParticles();
347 for (Int_t i = 0; i < npart; i++)
349 AliVAODParticle* p = GetParticle(i);
350 Double_t eta = p->Eta();
351 if ( (eta < etamin) || (eta > etamax) ) continue;
352 if (p->Charge() != 0.0) n++;
356 /**************************************************************************/
358 void AliAOD::Move(Double_t x, Double_t y, Double_t z)
360 //moves all spacial coordinates about this vector
363 // and whatever will be added to AOD and AOD particles that is a space coordinate
365 fPrimaryVertexX += x;
366 fPrimaryVertexY += y;
367 fPrimaryVertexZ += z;
369 Int_t npart = GetNumberOfParticles();
370 for (Int_t i = 0; i < npart; i++)
372 AliVAODParticle* p = GetParticle(i);
373 AliTrackPoints* tp = p->GetTPCTrackPoints();
374 if (tp) tp->Move(x,y,z);
375 tp = p->GetITSTrackPoints();
376 if (tp) tp->Move(x,y,z);
379 /**************************************************************************/
381 void AliAOD::Print(Option_t* /*option*/)
386 msg+="Particle Class: ";
389 msg+=fParticleClass->GetName();
393 msg+="Not specified yet";
396 msg += "Vertex position X: ";
397 msg += fPrimaryVertexX;
399 msg += fPrimaryVertexY;
401 msg += fPrimaryVertexZ;
404 msg += "Randomized: ";
405 msg += fIsRandomized;
408 Info("Print","%s",msg.Data());
410 Int_t npart = GetNumberOfParticles();
411 Info("Print","Npart: %d",npart);
412 for (Int_t i = 0; i < npart; i++)
414 Info("Print","Getting particle %d",i);
415 AliVAODParticle* p = GetParticle(i);
416 Info("Print","Printing particle %d, address %#x",i,p);
419 Info("Print","particle %d printed",i);
423 void AliAOD::SetOwner(Bool_t /*owner*/)
425 //Sets the ownership of particles: if particles should be also deleted if AOD is deleted/reseted
426 //Since fParticles is Clones and not Object Array, it is always the owner and this method does not have sense
428 MayNotUse("SetOwner");
429 //if fParticles->SetOwner(owner);