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 fTPCTrackPoints(0x0),fITSTrackPoints(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 fTPCTrackPoints(0x0),fITSTrackPoints(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 fTPCTrackPoints(0x0),fITSTrackPoints(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 //______________________________________________________________________________
74 AliAODParticle::AliAODParticle(const AliAODParticle& in):
76 fPdgIdx(in.fPdgIdx), fIdxInEvent(in.fIdxInEvent),
77 fNPids(in.fNPids),fPids(new Int_t[fNPids]),fPidProb(new Float_t[fNPids]),
78 fCalcMass(in.GetCalcMass()),
79 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()),
80 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
81 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
84 for(Int_t i = 0; i<fNPids; i++)
86 fPids[i] = in.fPids[i];
87 fPidProb[i] = in.fPidProb[i];
90 if (in.fTPCTrackPoints)
91 fTPCTrackPoints = (AliTrackPoints*)in.fTPCTrackPoints->Clone();
92 if (in.fITSTrackPoints)
93 fITSTrackPoints = (AliTrackPoints*)in.fITSTrackPoints->Clone();
95 fClusterMap = (AliClusterMap*)in.fClusterMap->Clone();
97 //______________________________________________________________________________
99 AliAODParticle::AliAODParticle(const AliVAODParticle& in):
101 fPdgIdx(0), fIdxInEvent(in.GetUID()),
102 fNPids(0),fPids(0x0),fPidProb(0x0),
104 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()),
105 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
106 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
110 for(Int_t i = 0; i<in.GetNumberOfPids(); i++)
112 SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
114 SetPdgCode(in.GetPdgCode(),in.GetPidProb());
116 AliTrackPoints* tpts = in.GetTPCTrackPoints();
117 if (tpts) SetTPCTrackPoints((AliTrackPoints*)tpts->Clone());
119 tpts = in.GetITSTrackPoints();
120 if (tpts) SetITSTrackPoints((AliTrackPoints*)tpts->Clone());
122 AliClusterMap* clmap = in.GetClusterMap();
123 if (clmap) SetClusterMap((AliClusterMap*)clmap->Clone());
125 //______________________________________________________________________________
127 AliAODParticle::AliAODParticle(const TParticle &p,Int_t idx):
128 fPdgIdx(0), fIdxInEvent(idx),
129 fNPids(0),fPids(0x0),fPidProb(0x0),
130 fCalcMass(p.GetCalcMass()),
131 fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()),
132 fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
133 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
135 //all copied in the initialization
136 SetPdgCode(p.GetPdgCode());
138 //______________________________________________________________________________
140 AliAODParticle::~AliAODParticle()
145 delete fTPCTrackPoints;
146 delete fITSTrackPoints;
149 //______________________________________________________________________________
151 void AliAODParticle::Clear(Option_t*)
153 //Must be implemented in order to store this object in Clones Array
156 delete fTPCTrackPoints;
157 delete fITSTrackPoints;
162 fTPCTrackPoints = 0x0;
163 fITSTrackPoints = 0x0;
166 //______________________________________________________________________________
168 AliAODParticle& AliAODParticle::operator=(const AliAODParticle& in)
175 Int_t* fPids = new Int_t[fNPids];
176 Float_t* fPidProb = new Float_t[fNPids];
177 for (Int_t i = 0; i < fNPids;i++)
179 fPids[i] = in.fPids[i];
180 fPidProb[i] = in.fPidProb[i];
183 fPdgIdx = in.fPdgIdx;
184 fIdxInEvent = in.fIdxInEvent;
185 fCalcMass = in.GetCalcMass();
195 delete fTPCTrackPoints;
196 fTPCTrackPoints = (in.fTPCTrackPoints)?(AliTrackPoints*)fTPCTrackPoints->Clone():0x0;
198 delete fITSTrackPoints;
199 fITSTrackPoints = (in.fITSTrackPoints)?(AliTrackPoints*)fITSTrackPoints->Clone():0x0;
202 fClusterMap = (in.fClusterMap)?(AliClusterMap*)in.fClusterMap->Clone():0x0;
206 //______________________________________________________________________________
208 void AliAODParticle::SetPdgCode(Int_t pdg,Float_t prob)
210 SetPIDprobability(pdg,prob);
211 fPdgIdx = GetPidSlot(pdg);
214 //______________________________________________________________________________
215 void AliAODParticle::SetPIDprobability(Int_t pdg, Float_t prob)
217 //Sets another pdg code and corresponding probabilty
218 //Ids are set in decreasing order
219 //Check if total prbaility is not ivercoming unity is performed
220 //in case, warning is printed
221 if (GetDebug() > 9) Info("SetPIDprobability","Setting PID %d prob %f",pdg,prob);
223 Float_t totprob = 0.0;//sums up probabilities
224 Int_t idx = GetPidSlot(pdg);
228 fPidProb[idx] = prob;
229 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
230 if (totprob > (1.0+0.000001))
232 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
236 Info("SetPIDprobability","Current Total probability: %f",totprob);
241 Int_t currentpid = GetPdgCode();
243 Float_t* aPidProbNew = new Float_t[fNPids];
244 Int_t* aPidsNew = new Int_t[fNPids];
246 for (i = 0; i < fNPids-1;i++)//find a slot
248 if ( fPidProb[i] > prob)
250 if (GetDebug()>9) Info("SetPID","Copying entry %d",i);
251 aPidProbNew[i] = fPidProb[i];
252 aPidsNew[i] = fPids[i];
253 totprob+=fPidProb[i];
258 if (GetDebug() > 9) Info("SetPID","Setting new PID on entry %d",i);
259 aPidProbNew[i] = prob;
264 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old araays
266 if (GetDebug() > 9) Info("SetPID","Copying from old entry %d to new entry %d",j-1,j);
267 aPidProbNew[j] = fPidProb[j-1];
268 aPidsNew[j] = fPids[j-1];
269 totprob+=fPidProb[j-1];
275 fPidProb = aPidProbNew;
278 fPdgIdx = GetPidSlot(currentpid);
279 if (fPdgIdx == -1) fPdgIdx = 0;
281 if (totprob > (1.0+0.000001))//space for numerical error
283 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
287 //______________________________________________________________________________
289 Float_t AliAODParticle::GetPIDprobability(Int_t pdg) const
291 //Returns probability that this particle is the type of pdg
292 Int_t idx = GetPidSlot(pdg);
293 if (idx < 0) return 0.0;//such pid was not specified for this particle
294 return fPidProb[idx];
296 //______________________________________________________________________________
298 const Char_t* AliAODParticle::GetName() const
300 //returns name of this particle
301 static char def[4] = "XXX";
302 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
303 if (ap) return ap->GetName();
306 //______________________________________________________________________________
308 Int_t AliAODParticle::GetPidSlot(Int_t pdg) const
310 //returns position of the given PID in fPids (and fPidProb) array.
311 if (fPids == 0x0) return -1;
312 for (Int_t i = 0; i< fNPids; i++)
314 if (fPids[i] == pdg) return i;
318 //______________________________________________________________________________
320 Int_t AliAODParticle::GetNthPid(Int_t idx) const
322 //returns PID sitting on slot idx in fPids
323 if ( (idx < 0) || (idx >= fNPids) )
325 Error("GetNthPid","Out Of Bounds");
330 //______________________________________________________________________________
332 Float_t AliAODParticle::GetNthPidProb(Int_t idx) const
334 //returns PID sitting on slot idx in fPidProb
335 if ( (idx < 0) || (idx >= fNPids) )
337 Error("GetNthPid","Out Of Bounds");
340 return fPidProb[idx];
342 //______________________________________________________________________________
344 void AliAODParticle::Print() const
346 //prints information about particle
347 printf("____________________________________________________\n");
348 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
349 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
352 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
356 printf("Not known\n");
359 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
360 Px(),Py(),Pz(),E(),GetCalcMass(),Vx(),Vy(),Vz(),T());
362 for (Int_t i = 0; i < fNPids; i++)
364 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
365 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
368 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
372 printf("Not known\n");
377 //______________________________________________________________________________
379 //void AliAODParticle::Streamer(TBuffer &b)
381 // // Stream all objects in the array to or from the I/O buffer.
382 // UInt_t R__s, R__c;
384 // if (b.IsReading())
387 // delete [] fPidProb;
389 // Version_t v = b.ReadVersion(&R__s, &R__c);
392 // AliAODParticle::Class()->ReadBuffer(b, this);
396 // TObject::Streamer(b);
401 // Int_t* fPids = new Int_t[fNPids];
402 // Float_t* fPidProb = new Float_t[fNPids];
403 // for (i = 0;i<fNPids;i++)
407 // for (i = 0;i<fNPids;i++)
422 // Info("Streamer","Read data");
426 // b.CheckByteCount(R__s, R__c,AliAODParticle::IsA());
430 // R__c = b.WriteVersion(AliAODParticle::IsA(), kTRUE);
431 // TObject::Streamer(b);
432 // Info("Streamer","Read data");
438 // for (i = 0;i<fNPids;i++)
444 // for (i = 0;i<fNPids;i++)
460 // b.SetByteCount(R__c, kTRUE);