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
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 for (Int_t i = curentr; i < inentr; i++)
138 TObject& inobj = *(in.fParticles->At(i));
139 TObject& obj = *((TObject*)(fParticleClass->New(arr[i])));
145 for (Int_t i = 0; i < inentr; i++)
147 TObject& inobj = *(in.fParticles->At(i));
148 TObject& obj = *(fParticles->At(i));
152 for (Int_t i = curentr ; i >= inentr ; i--)
154 fParticles->RemoveAt(i);
161 fParticles = (TClonesArray*)in.fParticles->Clone();
166 /**************************************************************************/
168 void AliAOD::SetParticleClassName(const char* classname)
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);
175 Error("SetParticleClass","Can not get TClass for class named %s",classname);
178 SetParticleClass(pclass);
180 /**************************************************************************/
182 void AliAOD::SetParticleClass(TClass* pclass)
184 //Sets type of particle that is going to be stored
188 Error("SetParticleClass","Parameter is NULL.");
192 if ( pclass->InheritsFrom("AliVAODParticle") == kFALSE )
194 Error("SetParticleClass","Class named %s does not inherit from AliVAODParticle",pclass->GetName());
197 if (pclass != fParticleClass)
199 fParticleClass = pclass;
200 if (fParticleClass) delete fParticles;
201 fParticles = new TClonesArray(fParticleClass);
205 /**************************************************************************/
207 void AliAOD::AddParticle(TParticle* part, Int_t idx)
209 //Adds TParticle to event
212 Error("AddParticle(TParticle*,Int_t)","pointer to particle is NULL");
216 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
217 AddParticle( new AliAODParticle(*part,idx) );
219 /**************************************************************************/
221 void AliAOD::AddParticle(AliVAODParticle* particle)
223 //add particle to AOD
224 //MAKES ITS OWN COPY OF THE PARTICLE!!! (AOD is not going to keep and delete input pointer)
226 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
228 Int_t idx = fParticles->GetLast() + 1;
229 TClonesArray& arr = *fParticles;
231 AliVAODParticle* pp = (AliVAODParticle*)fParticleClass->New(arr[idx]);
232 pp->operator=(*particle);
235 /**************************************************************************/
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)
241 //adds particle to event (standard AOD class)
243 if (fParticles == 0x0) SetParticleClassName("AliAODParticle");
245 Int_t newpartidx = fParticles->GetLast() + 1;
246 TClonesArray& arr = *fParticles;
248 AliVAODParticle* p = (AliVAODParticle*)fParticleClass->New(arr[newpartidx]);
252 p->SetMomentum(px,py,pz,etot);
253 p->SetProductionVertex(vx,vy,vz,time);
256 /**************************************************************************/
258 void AliAOD::SwapParticles(Int_t i, Int_t j)
260 //swaps particles positions; used by AliHBTEvent::Blend
261 if ( (i<0) || (i>=GetNumberOfParticles()) ) return;
262 if ( (j<0) || (j>=GetNumberOfParticles()) ) return;
264 AliVAODParticle* tmpobj = (AliVAODParticle*)fParticleClass->New();
265 AliVAODParticle& tmp = *tmpobj;
266 AliVAODParticle& first = *(GetParticle(i));
267 AliVAODParticle& second = *(GetParticle(j));
274 /**************************************************************************/
278 //deletes all particles from the event
279 if (fParticles) fParticles->Clear("C");
281 fIsRandomized = kFALSE;
283 /**************************************************************************/
285 void AliAOD::GetPrimaryVertex(Double_t&x, Double_t&y, Double_t&z)
287 //returns positions of the primary vertex
292 /**************************************************************************/
294 void AliAOD::SetPrimaryVertex(Double_t x, Double_t y, Double_t z)
296 //Sets positions of the primary vertex
301 /**************************************************************************/
303 Int_t AliAOD::GetNumberOfCharged(Double_t etamin, Double_t etamax) const
305 //reurns number of charged particles within given pseudorapidity range
307 Int_t npart = GetNumberOfParticles();
308 for (Int_t i = 0; i < npart; i++)
310 AliVAODParticle* p = GetParticle(i);
311 Double_t eta = p->Eta();
312 if ( (eta < etamin) || (eta > etamax) ) continue;
313 if (p->Charge() != 0.0) n++;
317 /**************************************************************************/
319 void AliAOD::Move(Double_t x, Double_t y, Double_t z)
321 //moves all spacial coordinates about this vector
324 // and whatever will be added to AOD and AOD particles that is a space coordinate
326 fPrimaryVertexX += x;
327 fPrimaryVertexY += y;
328 fPrimaryVertexZ += z;
330 Int_t npart = GetNumberOfParticles();
331 for (Int_t i = 0; i < npart; i++)
333 AliVAODParticle* p = GetParticle(i);
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);
341 void AliAOD::Print(Option_t* /*option*/)
346 msg+="Particle Class: ";
349 msg+=fParticleClass->GetName();
353 msg+="Not specified yet";
356 msg += "Vertex position X: ";
357 msg += fPrimaryVertexX;
359 msg += fPrimaryVertexY;
361 msg += fPrimaryVertexZ;
364 msg += "Randomized: ";
365 msg += fIsRandomized;
368 Info("Print","%s",msg.Data());
370 Int_t npart = GetNumberOfParticles();
371 Info("Print","Npart: %d",npart);
372 for (Int_t i = 0; i < npart; i++)
374 Info("Print","Getting particle %d",i);
375 AliVAODParticle* p = GetParticle(i);
376 Info("Print","Printing particle %d, address %#x",i,p);
379 Info("Print","particle %d printed",i);
383 void AliAOD::SetOwner(Bool_t /*owner*/)
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
388 MayNotUse("SetOwner");
389 //if fParticles->SetOwner(owner);