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 AliAODParticle& AliAODParticle::operator=(const AliAODParticle& in)
191 // Info("operator=(const AliAODParticle& in)","AliAODParticle");
193 AliVAODParticle::operator=(in);
197 fPids = new Int_t[fNPids];
198 fPidProb = new Float_t[fNPids];
199 for (Int_t i = 0; i < fNPids;i++)
201 fPids[i] = in.fPids[i];
202 fPidProb[i] = in.fPidProb[i];
205 fPdgIdx = in.fPdgIdx;
206 fIdxInEvent = in.fIdxInEvent;
207 fCalcMass = in.GetCalcMass();
217 delete fTPCTrackPoints;
218 fTPCTrackPoints = (in.fTPCTrackPoints)?(AliTrackPoints*)in.fTPCTrackPoints->Clone():0x0;
220 delete fITSTrackPoints;
221 fITSTrackPoints = (in.fITSTrackPoints)?(AliTrackPoints*)in.fITSTrackPoints->Clone():0x0;
224 fClusterMap = (in.fClusterMap)?(AliClusterMap*)in.fClusterMap->Clone():0x0;
228 //______________________________________________________________________________
230 void AliAODParticle::SetPdgCode(Int_t pdg,Float_t prob)
233 SetPIDprobability(pdg,prob);
234 fPdgIdx = GetPidSlot(pdg);
237 //______________________________________________________________________________
238 void AliAODParticle::SetPIDprobability(Int_t pdg, Float_t prob)
240 //Sets another pdg code and corresponding probabilty
241 //Ids are set in decreasing order
242 //Check if total probability is not overcoming unity is performed
243 //in case, warning is printed
244 AliDebug(9,Form("SetPIDprobability","Setting PID %d prob %f",pdg,prob));
246 Float_t totprob = 0.0;//sums up probabilities
247 Int_t idx = GetPidSlot(pdg);
252 fPidProb[idx] = prob;
253 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
254 if (totprob > (1.0+0.000001))
256 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
258 AliDebug(9,Form("Current Total probability: %f",totprob));
262 Int_t currentpid = GetPdgCode();
264 Float_t* aPidProbNew = new Float_t[fNPids];
265 Int_t* aPidsNew = new Int_t[fNPids];
267 for (i = 0; i < fNPids-1;i++)//find a slot
269 if ( fPidProb[i] > prob)
271 AliDebug(9,Form("Copying entry %d",i));
272 aPidProbNew[i] = fPidProb[i];
273 aPidsNew[i] = fPids[i];
274 totprob+=fPidProb[i];
279 AliDebug(9,Form("SetPID","Setting new PID on entry %d",i));
280 aPidProbNew[i] = prob;
285 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old arays
287 AliDebug(9,Form("SetPID","Copying from old entry %d to new entry %d",j-1,j));
288 aPidProbNew[j] = fPidProb[j-1];
289 aPidsNew[j] = fPids[j-1];
290 totprob+=fPidProb[j-1];
296 fPidProb = aPidProbNew;
299 fPdgIdx = GetPidSlot(currentpid);
300 if (fPdgIdx == -1) fPdgIdx = 0;
302 if (totprob > (1.0+0.000001))//space for numerical error
304 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
308 //______________________________________________________________________________
310 Float_t AliAODParticle::GetPIDprobability(Int_t pdg) const
312 //Returns probability that this particle is the type of pdg
313 Int_t idx = GetPidSlot(pdg);
314 if (idx < 0) return 0.0;//such pid was not specified for this particle
315 return fPidProb[idx];
317 //______________________________________________________________________________
319 const Char_t* AliAODParticle::GetName() const
321 //returns name of this particle
322 static char def[4] = "XXX";
323 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
324 if (ap) return ap->GetName();
327 //______________________________________________________________________________
329 Int_t AliAODParticle::GetPidSlot(Int_t pdg) const
331 //returns position of the given PID in fPids (and fPidProb) array.
332 if (fPids == 0x0) return -1;
333 for (Int_t i = 0; i< fNPids; i++)
335 if (fPids[i] == pdg) return i;
339 //______________________________________________________________________________
341 Int_t AliAODParticle::GetNthPid(Int_t idx) const
343 //returns PID sitting on slot idx in fPids
344 if ( (idx < 0) || (idx >= fNPids) )
346 Error("GetNthPid","Out Of Bounds");
351 //______________________________________________________________________________
353 Float_t AliAODParticle::GetNthPidProb(Int_t idx) const
355 //returns PID sitting on slot idx in fPidProb
356 if ( (idx < 0) || (idx >= fNPids) )
358 Error("GetNthPid","Out Of Bounds");
361 return fPidProb[idx];
363 //______________________________________________________________________________
365 void AliAODParticle::Print(const Option_t * /*opt*/) const
367 //prints information about particle
368 printf("____________________________________________________\n");
369 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
370 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
373 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
377 printf("Not known\n");
380 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
381 Px(),Py(),Pz(),E(),GetCalcMass(),Vx(),Vy(),Vz(),T());
383 for (Int_t i = 0; i < fNPids; i++)
385 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
386 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
389 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
393 printf("Not known\n");
397 if (fITSTrackPoints) fITSTrackPoints->Print();
398 if (fTPCTrackPoints) fTPCTrackPoints->Print();
402 //______________________________________________________________________________
404 //void AliAODParticle::Streamer(TBuffer &b)
406 // // Stream all objects in the array to or from the I/O buffer.
407 // UInt_t R__s, R__c;
409 // if (b.IsReading())
412 // delete [] fPidProb;
414 // Version_t v = b.ReadVersion(&R__s, &R__c);
417 // AliAODParticle::Class()->ReadBuffer(b, this);
421 // TObject::Streamer(b);
426 // Int_t* fPids = new Int_t[fNPids];
427 // Float_t* fPidProb = new Float_t[fNPids];
428 // for (i = 0;i<fNPids;i++)
432 // for (i = 0;i<fNPids;i++)
447 // Info("Streamer","Read data");
451 // b.CheckByteCount(R__s, R__c,AliAODParticle::IsA());
455 // R__c = b.WriteVersion(AliAODParticle::IsA(), kTRUE);
456 // TObject::Streamer(b);
457 // Info("Streamer","Read data");
463 // for (i = 0;i<fNPids;i++)
469 // for (i = 0;i<fNPids;i++)
485 // b.SetByteCount(R__c, kTRUE);