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 //___________________________________________________________
19 /////////////////////////////////////////////////////////////
21 // class AliAODParticle
23 // Ali HBT Particle: simplified class TParticle
24 // Simplified in order to minimize the size of object
25 // - we want to keep a lot of such a objects in memory
26 // Additionaly adjusted for HBT Analysies purposes
27 // + pointer to Track Points
28 // + pointer to Cluster Map(s)
30 // Piotr.Skowronski@cern.ch
32 /////////////////////////////////////////////////////////////
33 #include <TParticle.h>
35 #include "AliAODParticle.h"
36 #include "AliClusterMap.h"
38 #include "AliTrackPoints.h"
40 ClassImp(AliAODParticle)
42 //______________________________________________________________________________
43 AliAODParticle::AliAODParticle():
44 fPdgIdx(0), fIdxInEvent(0),fNPids(0),fPids(0x0),fPidProb(0x0),
45 fCalcMass(0),fPx(0), fPy(0),fPz(0),fE(0), fVx(0), fVy(0),fVz(0),fVt(0),
46 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
49 //______________________________________________________________________________
51 AliAODParticle::AliAODParticle(Int_t pdg, Int_t idx,
52 Double_t px, Double_t py, Double_t pz, Double_t etot,
53 Double_t vx, Double_t vy, Double_t vz, Double_t time):
54 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
56 fPx(px), fPy(py),fPz(pz),fE(etot),
57 fVx(vx), fVy(vy),fVz(vz),fVt(time),
58 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
63 fCalcMass = GetPDG()->Mass();
65 Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
66 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
67 else fCalcMass = -TMath::Sqrt(-a2);
70 //______________________________________________________________________________
72 AliAODParticle::AliAODParticle(Int_t pdg, Float_t prob, Int_t idx,
73 Double_t px, Double_t py, Double_t pz, Double_t etot,
74 Double_t vx, Double_t vy, Double_t vz, Double_t time):
75 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
77 fPx(px), fPy(py),fPz(pz),fE(etot),
78 fVx(vx), fVy(vy),fVz(vz),fVt(time),
79 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
84 fCalcMass = GetPDG()->Mass();
86 Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
87 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
88 else fCalcMass = -TMath::Sqrt(-a2);
91 //______________________________________________________________________________
93 AliAODParticle::AliAODParticle(const AliAODParticle& in):
95 fPdgIdx(in.fPdgIdx), fIdxInEvent(in.fIdxInEvent),
96 fNPids(in.fNPids),fPids(new Int_t[fNPids]),fPidProb(new Float_t[fNPids]),
97 fCalcMass(in.GetCalcMass()),
98 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()),
99 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
100 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
103 // Info("AliAODParticle(const AliAODParticle& in)","");
104 for(Int_t i = 0; i<fNPids; i++)
106 fPids[i] = in.fPids[i];
107 fPidProb[i] = in.fPidProb[i];
110 if (in.fTPCTrackPoints)
111 fTPCTrackPoints = (AliTrackPoints*)in.fTPCTrackPoints->Clone();
112 if (in.fITSTrackPoints)
113 fITSTrackPoints = (AliTrackPoints*)in.fITSTrackPoints->Clone();
115 fClusterMap = (AliClusterMap*)in.fClusterMap->Clone();
117 //______________________________________________________________________________
119 AliAODParticle::AliAODParticle(const AliVAODParticle& in):
121 fPdgIdx(0), fIdxInEvent(in.GetUID()),
122 fNPids(0),fPids(0x0),fPidProb(0x0),
124 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()),
125 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
126 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
129 // Info("AliAODParticle(const AliVAODParticle& in)","");
130 for(Int_t i = 0; i<in.GetNumberOfPids(); i++)
132 SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
134 SetPdgCode(in.GetPdgCode(),in.GetPidProb());
136 AliTrackPoints* tpts = in.GetTPCTrackPoints();
137 if (tpts) SetTPCTrackPoints((AliTrackPoints*)tpts->Clone());
139 tpts = in.GetITSTrackPoints();
140 if (tpts) SetITSTrackPoints((AliTrackPoints*)tpts->Clone());
142 AliClusterMap* clmap = in.GetClusterMap();
143 if (clmap) SetClusterMap((AliClusterMap*)clmap->Clone());
145 //______________________________________________________________________________
147 AliAODParticle::AliAODParticle(const TParticle &p,Int_t idx):
148 fPdgIdx(0), fIdxInEvent(idx),
149 fNPids(0),fPids(0x0),fPidProb(0x0),
150 fCalcMass(p.GetCalcMass()),
151 fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()),
152 fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
153 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
155 //all copied in the initialization
156 SetPdgCode(p.GetPdgCode());
158 //______________________________________________________________________________
160 AliAODParticle::~AliAODParticle()
165 delete fTPCTrackPoints;
166 delete fITSTrackPoints;
169 //______________________________________________________________________________
171 void AliAODParticle::Clear(Option_t*)
173 //Must be implemented in order to store this object in Clones Array
176 delete fTPCTrackPoints;
177 delete fITSTrackPoints;
182 fTPCTrackPoints = 0x0;
183 fITSTrackPoints = 0x0;
186 //______________________________________________________________________________
188 AliVAODParticle& AliAODParticle::operator=(const AliVAODParticle& in)
191 // Info("operator=(const AliVAODParticle& in)","AliAODParticle");
193 if (&in == this) return *this;
201 Int_t npids = in.GetNumberOfPids();
202 for (Int_t i = 0; i < npids; i++)
204 SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
207 SetPdgCode(in.GetPdgCode(),in.GetPidProb());
211 fCalcMass = in.Mass();
222 delete fTPCTrackPoints;
223 AliTrackPoints* tpts = in.GetTPCTrackPoints();
224 fTPCTrackPoints = (tpts)?(AliTrackPoints*)tpts->Clone():0x0;
226 delete fITSTrackPoints;
227 tpts = in.GetITSTrackPoints();
228 fITSTrackPoints = (tpts)?(AliTrackPoints*)tpts->Clone():0x0;
231 AliClusterMap* incmap = in.GetClusterMap();
232 fClusterMap = (incmap)?(AliClusterMap*)incmap->Clone():0x0;
236 //______________________________________________________________________________
238 AliAODParticle& AliAODParticle::operator=(const AliAODParticle& in)
241 // Info("operator=(const AliAODParticle& in)","AliAODParticle");
242 if (&in == this) return *this;
246 fPids = new Int_t[fNPids];
247 fPidProb = new Float_t[fNPids];
248 for (Int_t i = 0; i < fNPids;i++)
250 fPids[i] = in.fPids[i];
251 fPidProb[i] = in.fPidProb[i];
254 fPdgIdx = in.fPdgIdx;
255 fIdxInEvent = in.fIdxInEvent;
256 fCalcMass = in.GetCalcMass();
266 delete fTPCTrackPoints;
267 fTPCTrackPoints = (in.fTPCTrackPoints)?(AliTrackPoints*)in.fTPCTrackPoints->Clone():0x0;
269 delete fITSTrackPoints;
270 fITSTrackPoints = (in.fITSTrackPoints)?(AliTrackPoints*)in.fITSTrackPoints->Clone():0x0;
273 fClusterMap = (in.fClusterMap)?(AliClusterMap*)in.fClusterMap->Clone():0x0;
277 //______________________________________________________________________________
279 void AliAODParticle::SetPdgCode(Int_t pdg,Float_t prob)
282 SetPIDprobability(pdg,prob);
283 fPdgIdx = GetPidSlot(pdg);
286 //______________________________________________________________________________
287 void AliAODParticle::SetPIDprobability(Int_t pdg, Float_t prob)
289 //Sets another pdg code and corresponding probabilty
290 //Ids are set in decreasing order
291 //Check if total probability is not overcoming unity is performed
292 //in case, warning is printed
293 AliDebug(9,Form("SetPIDprobability","Setting PID %d prob %f",pdg,prob));
295 Float_t totprob = 0.0;//sums up probabilities
296 Int_t idx = GetPidSlot(pdg);
301 fPidProb[idx] = prob;
302 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
303 if (totprob > (1.0+0.000001))
305 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
307 AliDebug(9,Form("Current Total probability: %f",totprob));
311 Int_t currentpid = GetPdgCode();
313 Float_t* aPidProbNew = new Float_t[fNPids];
314 Int_t* aPidsNew = new Int_t[fNPids];
316 for (i = 0; i < fNPids-1;i++)//find a slot
318 if ( fPidProb[i] > prob)
320 AliDebug(9,Form("Copying entry %d",i));
321 aPidProbNew[i] = fPidProb[i];
322 aPidsNew[i] = fPids[i];
323 totprob+=fPidProb[i];
328 AliDebug(9,Form("SetPID","Setting new PID on entry %d",i));
329 aPidProbNew[i] = prob;
334 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old arays
336 AliDebug(9,Form("SetPID","Copying from old entry %d to new entry %d",j-1,j));
337 aPidProbNew[j] = fPidProb[j-1];
338 aPidsNew[j] = fPids[j-1];
339 totprob+=fPidProb[j-1];
345 fPidProb = aPidProbNew;
348 fPdgIdx = GetPidSlot(currentpid);
349 if (fPdgIdx == -1) fPdgIdx = 0;
351 if (totprob > (1.0+0.000001))//space for numerical error
353 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
357 //______________________________________________________________________________
359 Float_t AliAODParticle::GetPIDprobability(Int_t pdg) const
361 //Returns probability that this particle is the type of pdg
362 Int_t idx = GetPidSlot(pdg);
363 if (idx < 0) return 0.0;//such pid was not specified for this particle
364 return fPidProb[idx];
366 //______________________________________________________________________________
368 const Char_t* AliAODParticle::GetName() const
370 //returns name of this particle
371 static char def[4] = "XXX";
372 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
373 if (ap) return ap->GetName();
376 //______________________________________________________________________________
378 Int_t AliAODParticle::GetPidSlot(Int_t pdg) const
380 //returns position of the given PID in fPids (and fPidProb) array.
381 if (fPids == 0x0) return -1;
382 for (Int_t i = 0; i< fNPids; i++)
384 if (fPids[i] == pdg) return i;
388 //______________________________________________________________________________
390 Int_t AliAODParticle::GetNthPid(Int_t idx) const
392 //returns PID sitting on slot idx in fPids
393 if ( (idx < 0) || (idx >= fNPids) )
395 Error("GetNthPid","Out Of Bounds");
400 //______________________________________________________________________________
402 Float_t AliAODParticle::GetNthPidProb(Int_t idx) const
404 //returns PID sitting on slot idx in fPidProb
405 if ( (idx < 0) || (idx >= fNPids) )
407 Error("GetNthPid","Out Of Bounds");
410 return fPidProb[idx];
412 //______________________________________________________________________________
414 void AliAODParticle::Print(const Option_t * /*opt*/) const
416 //prints information about particle
417 printf("____________________________________________________\n");
418 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
419 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
422 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
426 printf("Not known\n");
429 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
430 Px(),Py(),Pz(),E(),GetCalcMass(),Vx(),Vy(),Vz(),T());
432 for (Int_t i = 0; i < fNPids; i++)
434 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
435 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
438 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
442 printf("Not known\n");
446 if (fITSTrackPoints) fITSTrackPoints->Print();
447 if (fTPCTrackPoints) fTPCTrackPoints->Print();
451 //______________________________________________________________________________
453 //void AliAODParticle::Streamer(TBuffer &b)
455 // // Stream all objects in the array to or from the I/O buffer.
456 // UInt_t R__s, R__c;
458 // if (b.IsReading())
461 // delete [] fPidProb;
463 // Version_t v = b.ReadVersion(&R__s, &R__c);
466 // AliAODParticle::Class()->ReadBuffer(b, this);
470 // TObject::Streamer(b);
475 // Int_t* fPids = new Int_t[fNPids];
476 // Float_t* fPidProb = new Float_t[fNPids];
477 // for (i = 0;i<fNPids;i++)
481 // for (i = 0;i<fNPids;i++)
496 // Info("Streamer","Read data");
500 // b.CheckByteCount(R__s, R__c,AliAODParticle::IsA());
504 // R__c = b.WriteVersion(AliAODParticle::IsA(), kTRUE);
505 // TObject::Streamer(b);
506 // Info("Streamer","Read data");
512 // for (i = 0;i<fNPids;i++)
518 // for (i = 0;i<fNPids;i++)
534 // b.SetByteCount(R__c, kTRUE);