1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /////////////////////////////////////////////////////////////
20 // base class for AOD containers
22 /////////////////////////////////////////////////////////////
25 #include <TParticle.h>
30 #include "AliAODParticle.h"
31 #include "AliTrackPoints.h"
37 fIsRandomized(kFALSE),
44 // Info("AliAOD()","Entered");
46 // Info("AliAOD()","Exited");
48 /**************************************************************************/
50 AliAOD::AliAOD(const AliAOD& in):
52 fParticles((TClonesArray*)in.fParticles->Clone()),
53 fIsRandomized(in.fIsRandomized),
54 fPrimaryVertexX(fPrimaryVertexX),
55 fPrimaryVertexY(in.fPrimaryVertexY),
56 fPrimaryVertexZ(in.fPrimaryVertexZ),
57 fParticleClass(in.fParticleClass)
61 /**************************************************************************/
63 AliAOD& AliAOD::operator=(const AliAOD& in)
67 if (this == &in ) return *this;
70 fParticles = (TClonesArray*)in.fParticles->Clone();
71 fIsRandomized = in.fIsRandomized ;
72 fPrimaryVertexX = in.fPrimaryVertexX ;
73 fPrimaryVertexY = in.fPrimaryVertexY ;
74 fPrimaryVertexZ = in.fPrimaryVertexZ ;
75 fParticleClass = in.fParticleClass ; //althought it is pointer, this points to object in class list of gROOT
78 /**************************************************************************/
83 //fParticleClass does not belong to AliAOD -> Do not delete it
87 /**************************************************************************/
89 void AliAOD::CopyData(AliAOD* aod)
91 //Copys all data from aod, but leaves local type of particles
92 if (aod == 0x0) return;
93 if (aod == this) return;
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
104 if (in.fParticles == 0x0)
105 {//if in obj has null fParticles we delete ours
112 { //if ours particles were already created
113 if (fParticles->GetClass() != in.fParticles->GetClass())
116 fParticles = (TClonesArray*)in.fParticles->Clone();
120 //it should be faster than cloning
121 Int_t inentr = in.fParticles->GetEntriesFast();
122 Int_t curentr = fParticles->GetEntriesFast();
124 TClonesArray& arr = *fParticles;
126 //we have to take care about different sizes of arrays
127 if ( curentr < inentr )
129 for (Int_t i = 0; i < curentr; i++)
131 TObject& inobj = *(in.fParticles->At(i));
132 TObject& obj = *(fParticles->At(i));
136 TClass* partclass = GetParticleClass();
137 if (partclass == 0x0)
139 Fatal("CopyData","Can not get particle class");
143 for (Int_t i = curentr; i < inentr; i++)
145 TObject& inobj = *(in.fParticles->At(i));
146 TObject& obj = *((TObject*)(partclass->New(arr[i])));
152 for (Int_t i = 0; i < inentr; i++)
154 TObject& inobj = *(in.fParticles->At(i));
155 TObject& obj = *(fParticles->At(i));
159 for (Int_t i = curentr ; i >= inentr ; i--)
161 fParticles->RemoveAt(i);
168 fParticles = (TClonesArray*)in.fParticles->Clone();
173 /**************************************************************************/
175 void AliAOD::SetParticleClassName(const char* classname)
177 //Sets type of particle that is going to be stored
178 if (gROOT == 0x0) Fatal("SetParticleClassName","ROOT System not initialized");
179 TClass* pclass = gROOT->GetClass(classname);
182 Error("SetParticleClass","Can not get TClass for class named %s",classname);
185 SetParticleClass(pclass);
187 /**************************************************************************/
189 void AliAOD::SetParticleClass(TClass* pclass)
191 //Sets type of particle that is going to be stored
195 Error("SetParticleClass","Parameter is NULL.");
199 if ( pclass->InheritsFrom("AliVAODParticle") == kFALSE )
201 Error("SetParticleClass","Class named %s does not inherit from AliVAODParticle",pclass->GetName());
204 if (pclass != fParticleClass)
206 fParticleClass = pclass;
207 if (fParticleClass) delete fParticles;
208 fParticles = new TClonesArray(fParticleClass);
211 /**************************************************************************/
212 TClass* AliAOD::GetParticleClass()
214 //returns TClass of particle class
215 if (fParticleClass) return fParticleClass;
217 if (fParticles == 0x0) return 0x0;
219 fParticleClass = fParticles->GetClass();
220 return fParticleClass;
223 /**************************************************************************/
225 void AliAOD::AddParticle(TParticle* part, Int_t idx)
227 //Adds TParticle to event
230 Error("AddParticle(TParticle*,Int_t)","pointer to particle is NULL");
234 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
235 AddParticle( new AliAODParticle(*part,idx) );
237 /**************************************************************************/
239 void AliAOD::AddParticle(AliVAODParticle* particle)
241 //add particle to AOD
242 //MAKES ITS OWN COPY OF THE PARTICLE!!! (AOD is not going to keep and delete input pointer)
244 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
246 Int_t idx = fParticles->GetLast() + 1;
247 TClonesArray& arr = *fParticles;
249 TClass* partclass = GetParticleClass();
250 if (partclass == 0x0)
252 Error("AddParticle(AliVAODParticle*)","Can not get particle class");
256 AliVAODParticle* pp = (AliVAODParticle*)partclass->New(arr[idx]);
257 pp->operator=(*particle);
260 /**************************************************************************/
262 void AliAOD::AddParticle(Int_t pdg, Int_t idx,
263 Double_t px, Double_t py, Double_t pz, Double_t etot,
264 Double_t vx, Double_t vy, Double_t vz, Double_t time)
266 //adds particle to event (standard AOD class)
268 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
270 Int_t newpartidx = fParticles->GetLast() + 1;
271 TClonesArray& arr = *fParticles;
273 TClass* partclass = GetParticleClass();
274 if (partclass == 0x0)
276 Error("AddParticle(Int_t,...)","Can not get particle class");
280 AliVAODParticle* p = (AliVAODParticle*)partclass->New(arr[newpartidx]);
284 p->SetMomentum(px,py,pz,etot);
285 p->SetProductionVertex(vx,vy,vz,time);
288 /**************************************************************************/
290 void AliAOD::SwapParticles(Int_t i, Int_t j)
292 //swaps particles positions; used by AliHBTEvent::Blend
293 if ( (i<0) || (i>=GetNumberOfParticles()) ) return;
294 if ( (j<0) || (j>=GetNumberOfParticles()) ) return;
297 TClass* partclass = GetParticleClass();
298 if (partclass == 0x0)
300 Error("SwapParticles","Can not get particle class");
304 AliVAODParticle* tmpobj = (AliVAODParticle*)partclass->New();
305 AliVAODParticle& tmp = *tmpobj;
306 AliVAODParticle& first = *(GetParticle(i));
307 AliVAODParticle& second = *(GetParticle(j));
314 /**************************************************************************/
318 //deletes all particles from the event
319 if (fParticles) fParticles->Clear("C");
321 fIsRandomized = kFALSE;
323 /**************************************************************************/
325 void AliAOD::GetPrimaryVertex(Double_t&x, Double_t&y, Double_t&z)
327 //returns positions of the primary vertex
332 /**************************************************************************/
334 void AliAOD::SetPrimaryVertex(Double_t x, Double_t y, Double_t z)
336 //Sets positions of the primary vertex
341 /**************************************************************************/
343 Int_t AliAOD::GetNumberOfCharged(Double_t etamin, Double_t etamax) const
345 //reurns number of charged particles within given pseudorapidity range
347 Int_t npart = GetNumberOfParticles();
348 for (Int_t i = 0; i < npart; i++)
350 AliVAODParticle* p = GetParticle(i);
351 Double_t eta = p->Eta();
352 if ( (eta < etamin) || (eta > etamax) ) continue;
353 if (p->Charge() != 0.0) n++;
357 /**************************************************************************/
359 void AliAOD::Move(Double_t x, Double_t y, Double_t z)
361 //moves all spacial coordinates about this vector
364 // and whatever will be added to AOD and AOD particles that is a space coordinate
366 fPrimaryVertexX += x;
367 fPrimaryVertexY += y;
368 fPrimaryVertexZ += z;
370 Int_t npart = GetNumberOfParticles();
371 for (Int_t i = 0; i < npart; i++)
373 AliVAODParticle* p = GetParticle(i);
374 AliTrackPoints* tp = p->GetTPCTrackPoints();
375 if (tp) tp->Move(x,y,z);
376 tp = p->GetITSTrackPoints();
377 if (tp) tp->Move(x,y,z);
380 /**************************************************************************/
382 void AliAOD::Print(const Option_t* /*option*/) const
387 msg+="Particle Class: ";
390 msg+=fParticleClass->GetName();
394 msg+="Not specified yet";
397 msg += "Vertex position X: ";
398 msg += fPrimaryVertexX;
400 msg += fPrimaryVertexY;
402 msg += fPrimaryVertexZ;
405 msg += "Randomized: ";
406 msg += fIsRandomized;
409 Info("Print","%s",msg.Data());
411 Int_t npart = GetNumberOfParticles();
412 Info("Print","Npart: %d",npart);
413 for (Int_t i = 0; i < npart; i++)
415 Info("Print","Getting particle %d",i);
416 AliVAODParticle* p = GetParticle(i);
417 Info("Print","Printing particle %d, address %#x",i,p);
420 Info("Print","particle %d printed",i);
424 void AliAOD::SetOwner(Bool_t /*owner*/)
426 //Sets the ownership of particles: if particles should be also deleted if AOD is deleted/reseted
427 //Since fParticles is Clones and not Object Array, it is always the owner and this method does not have sense
429 MayNotUse("SetOwner");
430 //if fParticles->SetOwner(owner);