1 #include "AliHBTParticle.h"
2 //___________________________________________________________
3 /////////////////////////////////////////////////////////////
5 // class AliHBTParticle
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 "AliHBTTrackPoints.h"
19 #include "AliHBTClusterMap.h"
21 ClassImp(AliHBTParticle)
23 Int_t AliHBTParticle::fgDebug = 0;
24 //______________________________________________________________________________
25 AliHBTParticle::AliHBTParticle():
26 fPdgIdx(0), fIdxInEvent(0),fNPids(0),fPids(0x0),fPidProb(0x0),
27 fCalcMass(0),fPx(0), fPy(0),fPz(0),fE(0), fVx(0), fVy(0),fVz(0),fVt(0),
28 fTrackPoints(0x0),fClusterMap(0x0)
31 //______________________________________________________________________________
33 AliHBTParticle::AliHBTParticle(Int_t pdg, Int_t idx,
34 Double_t px, Double_t py, Double_t pz, Double_t etot,
35 Double_t vx, Double_t vy, Double_t vz, Double_t time):
36 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
38 fPx(px), fPy(py),fPz(pz),fE(etot),
39 fVx(vx), fVy(vy),fVz(vz),fVt(time),
40 fTrackPoints(0x0),fClusterMap(0x0)
45 fCalcMass = GetPDG()->Mass();
47 Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
48 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
49 else fCalcMass = -TMath::Sqrt(-a2);
52 //______________________________________________________________________________
54 AliHBTParticle::AliHBTParticle(Int_t pdg, Float_t prob, Int_t idx,
55 Double_t px, Double_t py, Double_t pz, Double_t etot,
56 Double_t vx, Double_t vy, Double_t vz, Double_t time):
57 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
59 fPx(px), fPy(py),fPz(pz),fE(etot),
60 fVx(vx), fVy(vy),fVz(vz),fVt(time),
61 fTrackPoints(0x0),fClusterMap(0x0)
66 fCalcMass = GetPDG()->Mass();
68 Double_t a2 = fE*fE -fPx*fPx -fPy*fPy -fPz*fPz;
69 if (a2 >= 0) fCalcMass = TMath::Sqrt(a2);
70 else fCalcMass = -TMath::Sqrt(-a2);
73 //______________________________________________________________________________
74 AliHBTParticle::AliHBTParticle(const AliHBTParticle& 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.Energy()),
80 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
81 fTrackPoints(0x0), fClusterMap(0x0)
84 for(Int_t i = 0; i<fNPids; i++)
86 fPids[i] = in.fPids[i];
87 fPidProb[i] = in.fPidProb[i];
91 fTrackPoints = (AliHBTTrackPoints*)in.fTrackPoints->Clone();
93 fClusterMap = (AliHBTClusterMap*)in.fClusterMap->Clone();
96 //______________________________________________________________________________
97 AliHBTParticle::AliHBTParticle(const TParticle &p,Int_t idx):
98 fPdgIdx(0), fIdxInEvent(idx),
99 fNPids(0),fPids(0x0),fPidProb(0x0),
100 fCalcMass(p.GetCalcMass()),
101 fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()),
102 fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
103 fTrackPoints(0x0),fClusterMap(0x0)
105 //all copied in the initialization
106 SetPdgCode(p.GetPdgCode());
108 //______________________________________________________________________________
110 AliHBTParticle::~AliHBTParticle()
118 //______________________________________________________________________________
120 AliHBTParticle& AliHBTParticle::operator=(const AliHBTParticle& in)
127 Int_t* fPids = new Int_t[fNPids];
128 Float_t* fPidProb = new Float_t[fNPids];
129 for (Int_t i = 0; i < fNPids;i++)
131 fPids[i] = in.fPids[i];
132 fPidProb[i] = in.fPidProb[i];
135 fPdgIdx = in.fPdgIdx;
136 fIdxInEvent = in.fIdxInEvent;
137 fCalcMass = in.GetCalcMass();
148 fTrackPoints = (in.fTrackPoints)?(AliHBTTrackPoints*)fTrackPoints->Clone():0x0;
151 fClusterMap = (in.fClusterMap)?(AliHBTClusterMap*)in.fClusterMap->Clone():0x0;
155 //______________________________________________________________________________
157 void AliHBTParticle::SetPdgCode(Int_t pdg,Float_t prob)
159 SetPIDprobability(pdg,prob);
160 fPdgIdx = GetPidSlot(pdg);
163 //______________________________________________________________________________
164 void AliHBTParticle::SetPIDprobability(Int_t pdg, Float_t prob)
166 //Sets another pdg code and corresponding probabilty
167 //Ids are set in decreasing order
168 //Check if total prbaility is not ivercoming unity is performed
169 //in case, warning is printed
170 if (fgDebug > 9) Info("SetPIDprobability","Setting PID %d prob %f",pdg,prob);
172 Float_t totprob = 0.0;//sums up probabilities
173 Int_t idx = GetPidSlot(pdg);
177 fPidProb[idx] = prob;
178 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
179 if (totprob > (1.0+0.000001))
181 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
185 Info("SetPIDprobability","Current Total probability: %f",totprob);
190 Int_t currentpid = GetPdgCode();
192 Float_t* aPidProbNew = new Float_t[fNPids];
193 Int_t* aPidsNew = new Int_t[fNPids];
195 for (i = 0; i < fNPids-1;i++)//find a slot
197 if ( fPidProb[i] > prob)
199 if (fgDebug>9) Info("SetPID","Copying entry %d",i);
200 aPidProbNew[i] = fPidProb[i];
201 aPidsNew[i] = fPids[i];
202 totprob+=fPidProb[i];
207 if (fgDebug > 9) Info("SetPID","Setting new PID on entry %d",i);
208 aPidProbNew[i] = prob;
213 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old araays
215 if (fgDebug > 9) Info("SetPID","Copying from old entry %d to new entry %d",j-1,j);
216 aPidProbNew[j] = fPidProb[j-1];
217 aPidsNew[j] = fPids[j-1];
218 totprob+=fPidProb[j-1];
224 fPidProb = aPidProbNew;
227 fPdgIdx = GetPidSlot(currentpid);
228 if (fPdgIdx == -1) fPdgIdx = 0;
230 if (totprob > (1.0+0.000001))//place for numerical error
232 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
236 //______________________________________________________________________________
238 Float_t AliHBTParticle::GetPIDprobability(Int_t pdg) const
240 //Returns probability that this particle is the type of pdg
241 Int_t idx = GetPidSlot(pdg);
242 if (idx < 0) return 0.0;//such pid was not specified for this particle
243 return fPidProb[idx];
245 //______________________________________________________________________________
247 const Char_t* AliHBTParticle::GetName() const
249 //returns name of this particle
250 static char def[4] = "XXX";
251 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
252 if (ap) return ap->GetName();
255 //______________________________________________________________________________
257 Int_t AliHBTParticle::GetPidSlot(Int_t pdg) const
259 //returns position of the given PID in fPids (and fPidProb) array.
260 if (fPids == 0x0) return -1;
261 for (Int_t i = 0; i< fNPids; i++)
263 if (fPids[i] == pdg) return i;
267 //______________________________________________________________________________
269 Int_t AliHBTParticle::GetNthPid(Int_t idx) const
271 //returns PID sitting on slot idx in fPids
272 if ( (idx < 0) || (idx >= fNPids) )
274 Error("GetNthPid","Out Of Bounds");
279 //______________________________________________________________________________
281 Float_t AliHBTParticle::GetNthPidProb(Int_t idx) const
283 //returns PID sitting on slot idx in fPidProb
284 if ( (idx < 0) || (idx >= fNPids) )
286 Error("GetNthPid","Out Of Bounds");
289 return fPidProb[idx];
291 //______________________________________________________________________________
293 void AliHBTParticle::Print() const
295 //prints information about particle
296 printf("____________________________________________________\n");
297 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
298 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
301 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
305 printf("Not known\n");
308 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
309 Px(),Py(),Pz(),Energy(),GetCalcMass(),Vx(),Vy(),Vz(),T());
311 for (Int_t i = 0; i < fNPids; i++)
313 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
314 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
317 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
321 printf("Not known\n");
326 //______________________________________________________________________________
328 //void AliHBTParticle::Streamer(TBuffer &b)
330 // // Stream all objects in the array to or from the I/O buffer.
331 // UInt_t R__s, R__c;
333 // if (b.IsReading())
336 // delete [] fPidProb;
338 // Version_t v = b.ReadVersion(&R__s, &R__c);
341 // AliHBTParticle::Class()->ReadBuffer(b, this);
345 // TObject::Streamer(b);
350 // Int_t* fPids = new Int_t[fNPids];
351 // Float_t* fPidProb = new Float_t[fNPids];
352 // for (i = 0;i<fNPids;i++)
356 // for (i = 0;i<fNPids;i++)
371 // Info("Streamer","Read data");
375 // b.CheckByteCount(R__s, R__c,AliHBTParticle::IsA());
379 // R__c = b.WriteVersion(AliHBTParticle::IsA(), kTRUE);
380 // TObject::Streamer(b);
381 // Info("Streamer","Read data");
387 // for (i = 0;i<fNPids;i++)
393 // for (i = 0;i<fNPids;i++)
409 // b.SetByteCount(R__c, kTRUE);