1 #include "AliAODParticle.h"
2 //___________________________________________________________
3 /////////////////////////////////////////////////////////////
5 // class AliAODParticle
7 // Ali HBT Particle: simplified class TParticle
8 // Simplified in order to minimize the size of object
9 // - we want to keep a lot of such a objects in memory
10 // Additionaly adjusted for HBT Analysies purposes
11 // + pointer to Track Points
12 // + pointer to Cluster Map(s)
14 // Piotr.Skowronski@cern.ch
16 /////////////////////////////////////////////////////////////
17 #include <TParticle.h>
18 #include "AliTrackPoints.h"
19 #include "AliClusterMap.h"
21 ClassImp(AliAODParticle)
23 //______________________________________________________________________________
24 AliAODParticle::AliAODParticle():
25 fPdgIdx(0), fIdxInEvent(0),fNPids(0),fPids(0x0),fPidProb(0x0),
26 fCalcMass(0),fPx(0), fPy(0),fPz(0),fE(0), fVx(0), fVy(0),fVz(0),fVt(0),
27 fTrackPoints(0x0),fClusterMap(0x0)
30 //______________________________________________________________________________
32 AliAODParticle::AliAODParticle(Int_t pdg, Int_t idx,
33 Double_t px, Double_t py, Double_t pz, Double_t etot,
34 Double_t vx, Double_t vy, Double_t vz, Double_t time):
35 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
37 fPx(px), fPy(py),fPz(pz),fE(etot),
38 fVx(vx), fVy(vy),fVz(vz),fVt(time),
39 fTrackPoints(0x0),fClusterMap(0x0)
44 fCalcMass = GetPDG()->Mass();
46 Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
47 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
48 else fCalcMass = -TMath::Sqrt(-a2);
51 //______________________________________________________________________________
53 AliAODParticle::AliAODParticle(Int_t pdg, Float_t prob, Int_t idx,
54 Double_t px, Double_t py, Double_t pz, Double_t etot,
55 Double_t vx, Double_t vy, Double_t vz, Double_t time):
56 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
58 fPx(px), fPy(py),fPz(pz),fE(etot),
59 fVx(vx), fVy(vy),fVz(vz),fVt(time),
60 fTrackPoints(0x0),fClusterMap(0x0)
65 fCalcMass = GetPDG()->Mass();
67 Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
68 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
69 else fCalcMass = -TMath::Sqrt(-a2);
72 //______________________________________________________________________________
73 AliAODParticle::AliAODParticle(const AliAODParticle& in):
75 fPdgIdx(in.fPdgIdx), fIdxInEvent(in.fIdxInEvent),
76 fNPids(in.fNPids),fPids(new Int_t[fNPids]),fPidProb(new Float_t[fNPids]),
77 fCalcMass(in.GetCalcMass()),
78 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.Energy()),
79 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
80 fTrackPoints(0x0), fClusterMap(0x0)
83 for(Int_t i = 0; i<fNPids; i++)
85 fPids[i] = in.fPids[i];
86 fPidProb[i] = in.fPidProb[i];
90 fTrackPoints = (AliTrackPoints*)in.fTrackPoints->Clone();
92 fClusterMap = (AliClusterMap*)in.fClusterMap->Clone();
95 //______________________________________________________________________________
96 AliAODParticle::AliAODParticle(const TParticle &p,Int_t idx):
97 fPdgIdx(0), fIdxInEvent(idx),
98 fNPids(0),fPids(0x0),fPidProb(0x0),
99 fCalcMass(p.GetCalcMass()),
100 fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()),
101 fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
102 fTrackPoints(0x0),fClusterMap(0x0)
104 //all copied in the initialization
105 SetPdgCode(p.GetPdgCode());
107 //______________________________________________________________________________
109 AliAODParticle::~AliAODParticle()
117 //______________________________________________________________________________
119 AliAODParticle& AliAODParticle::operator=(const AliAODParticle& in)
126 Int_t* fPids = new Int_t[fNPids];
127 Float_t* fPidProb = new Float_t[fNPids];
128 for (Int_t i = 0; i < fNPids;i++)
130 fPids[i] = in.fPids[i];
131 fPidProb[i] = in.fPidProb[i];
134 fPdgIdx = in.fPdgIdx;
135 fIdxInEvent = in.fIdxInEvent;
136 fCalcMass = in.GetCalcMass();
147 fTrackPoints = (in.fTrackPoints)?(AliTrackPoints*)fTrackPoints->Clone():0x0;
150 fClusterMap = (in.fClusterMap)?(AliClusterMap*)in.fClusterMap->Clone():0x0;
154 //______________________________________________________________________________
156 void AliAODParticle::SetPdgCode(Int_t pdg,Float_t prob)
158 SetPIDprobability(pdg,prob);
159 fPdgIdx = GetPidSlot(pdg);
162 //______________________________________________________________________________
163 void AliAODParticle::SetPIDprobability(Int_t pdg, Float_t prob)
165 //Sets another pdg code and corresponding probabilty
166 //Ids are set in decreasing order
167 //Check if total prbaility is not ivercoming unity is performed
168 //in case, warning is printed
169 if (GetDebug() > 9) Info("SetPIDprobability","Setting PID %d prob %f",pdg,prob);
171 Float_t totprob = 0.0;//sums up probabilities
172 Int_t idx = GetPidSlot(pdg);
176 fPidProb[idx] = prob;
177 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
178 if (totprob > (1.0+0.000001))
180 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
184 Info("SetPIDprobability","Current Total probability: %f",totprob);
189 Int_t currentpid = GetPdgCode();
191 Float_t* aPidProbNew = new Float_t[fNPids];
192 Int_t* aPidsNew = new Int_t[fNPids];
194 for (i = 0; i < fNPids-1;i++)//find a slot
196 if ( fPidProb[i] > prob)
198 if (GetDebug()>9) Info("SetPID","Copying entry %d",i);
199 aPidProbNew[i] = fPidProb[i];
200 aPidsNew[i] = fPids[i];
201 totprob+=fPidProb[i];
206 if (GetDebug() > 9) Info("SetPID","Setting new PID on entry %d",i);
207 aPidProbNew[i] = prob;
212 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old araays
214 if (GetDebug() > 9) Info("SetPID","Copying from old entry %d to new entry %d",j-1,j);
215 aPidProbNew[j] = fPidProb[j-1];
216 aPidsNew[j] = fPids[j-1];
217 totprob+=fPidProb[j-1];
223 fPidProb = aPidProbNew;
226 fPdgIdx = GetPidSlot(currentpid);
227 if (fPdgIdx == -1) fPdgIdx = 0;
229 if (totprob > (1.0+0.000001))//place for numerical error
231 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
235 //______________________________________________________________________________
237 Float_t AliAODParticle::GetPIDprobability(Int_t pdg) const
239 //Returns probability that this particle is the type of pdg
240 Int_t idx = GetPidSlot(pdg);
241 if (idx < 0) return 0.0;//such pid was not specified for this particle
242 return fPidProb[idx];
244 //______________________________________________________________________________
246 const Char_t* AliAODParticle::GetName() const
248 //returns name of this particle
249 static char def[4] = "XXX";
250 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
251 if (ap) return ap->GetName();
254 //______________________________________________________________________________
256 Int_t AliAODParticle::GetPidSlot(Int_t pdg) const
258 //returns position of the given PID in fPids (and fPidProb) array.
259 if (fPids == 0x0) return -1;
260 for (Int_t i = 0; i< fNPids; i++)
262 if (fPids[i] == pdg) return i;
266 //______________________________________________________________________________
268 Int_t AliAODParticle::GetNthPid(Int_t idx) const
270 //returns PID sitting on slot idx in fPids
271 if ( (idx < 0) || (idx >= fNPids) )
273 Error("GetNthPid","Out Of Bounds");
278 //______________________________________________________________________________
280 Float_t AliAODParticle::GetNthPidProb(Int_t idx) const
282 //returns PID sitting on slot idx in fPidProb
283 if ( (idx < 0) || (idx >= fNPids) )
285 Error("GetNthPid","Out Of Bounds");
288 return fPidProb[idx];
290 //______________________________________________________________________________
292 void AliAODParticle::Print() const
294 //prints information about particle
295 printf("____________________________________________________\n");
296 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
297 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
300 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
304 printf("Not known\n");
307 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
308 Px(),Py(),Pz(),Energy(),GetCalcMass(),Vx(),Vy(),Vz(),T());
310 for (Int_t i = 0; i < fNPids; i++)
312 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
313 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
316 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
320 printf("Not known\n");
325 //______________________________________________________________________________
327 //void AliAODParticle::Streamer(TBuffer &b)
329 // // Stream all objects in the array to or from the I/O buffer.
330 // UInt_t R__s, R__c;
332 // if (b.IsReading())
335 // delete [] fPidProb;
337 // Version_t v = b.ReadVersion(&R__s, &R__c);
340 // AliAODParticle::Class()->ReadBuffer(b, this);
344 // TObject::Streamer(b);
349 // Int_t* fPids = new Int_t[fNPids];
350 // Float_t* fPidProb = new Float_t[fNPids];
351 // for (i = 0;i<fNPids;i++)
355 // for (i = 0;i<fNPids;i++)
370 // Info("Streamer","Read data");
374 // b.CheckByteCount(R__s, R__c,AliAODParticle::IsA());
378 // R__c = b.WriteVersion(AliAODParticle::IsA(), kTRUE);
379 // TObject::Streamer(b);
380 // Info("Streamer","Read data");
386 // for (i = 0;i<fNPids;i++)
392 // for (i = 0;i<fNPids;i++)
408 // b.SetByteCount(R__c, kTRUE);