]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HBTAN/AliHBTParticle.cxx
Missing include
[u/mrichter/AliRoot.git] / HBTAN / AliHBTParticle.cxx
CommitLineData
1b446896 1#include "AliHBTParticle.h"
f5de2f09 2//___________________________________________________________
3/////////////////////////////////////////////////////////////
4//
5// class AliHBTParticle
6//
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
37e71815 11// + pointer to Track Points
12// + pointer to Cluster Map(s)
13//
14// Piotr.Skowronski@cern.ch
f5de2f09 15//
16/////////////////////////////////////////////////////////////
1b446896 17#include <TParticle.h>
f5de2f09 18#include "AliHBTTrackPoints.h"
66d1d1a4 19#include "AliHBTClusterMap.h"
1b446896 20
21ClassImp(AliHBTParticle)
22
8089a083 23Int_t AliHBTParticle::fgDebug = 0;
1b446896 24//______________________________________________________________________________
25AliHBTParticle::AliHBTParticle():
8089a083 26 fPdgIdx(0), fIdxInEvent(0),fNPids(0),fPids(0x0),fPidProb(0x0),
f5de2f09 27 fCalcMass(0),fPx(0), fPy(0),fPz(0),fE(0), fVx(0), fVy(0),fVz(0),fVt(0),
66d1d1a4 28 fTrackPoints(0x0),fClusterMap(0x0)
1b446896 29{//empty particle
30}
8089a083 31//______________________________________________________________________________
1b446896 32
8089a083 33AliHBTParticle::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):
e665964c 36 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
8089a083 37 fCalcMass(0),
38 fPx(px), fPy(py),fPz(pz),fE(etot),
f5de2f09 39 fVx(vx), fVy(vy),fVz(vz),fVt(time),
66d1d1a4 40 fTrackPoints(0x0),fClusterMap(0x0)
8089a083 41{
42//mormal constructor
43 SetPdgCode(pdg);
44 if (GetPDG()) {
45 fCalcMass = GetPDG()->Mass();
46 } else {
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);
50 }
51}
1b446896 52//______________________________________________________________________________
8089a083 53
54AliHBTParticle::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):
e665964c 57 fPdgIdx(0), fIdxInEvent(idx),fNPids(0),fPids(0x0),fPidProb(0x0),
8089a083 58 fCalcMass(0),
35d14c47 59 fPx(px), fPy(py),fPz(pz),fE(etot),
f5de2f09 60 fVx(vx), fVy(vy),fVz(vz),fVt(time),
66d1d1a4 61 fTrackPoints(0x0),fClusterMap(0x0)
1b446896 62{
63//mormal constructor
8089a083 64 SetPdgCode(pdg,prob);
1b446896 65 if (GetPDG()) {
66 fCalcMass = GetPDG()->Mass();
67 } else {
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);
71 }
72}
8089a083 73//______________________________________________________________________________
74AliHBTParticle::AliHBTParticle(const AliHBTParticle& in):
bed069a4 75 TObject(in),
8089a083 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()),
9616170a 80 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
66d1d1a4 81 fTrackPoints(0x0), fClusterMap(0x0)
8089a083 82{
83 //Copy constructor
84 for(Int_t i = 0; i<fNPids; i++)
85 {
86 fPids[i] = in.fPids[i];
87 fPidProb[i] = in.fPidProb[i];
88 }
9616170a 89
9616170a 90 if (in.fTrackPoints)
91 fTrackPoints = (AliHBTTrackPoints*)in.fTrackPoints->Clone();
66d1d1a4 92 if (in.fClusterMap)
93 fClusterMap = (AliHBTClusterMap*)in.fClusterMap->Clone();
8089a083 94}
1b446896 95
96//______________________________________________________________________________
8089a083 97AliHBTParticle::AliHBTParticle(const TParticle &p,Int_t idx):
98 fPdgIdx(0), fIdxInEvent(idx),
99 fNPids(0),fPids(0x0),fPidProb(0x0),
100 fCalcMass(p.GetCalcMass()),
1b446896 101 fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()),
f5de2f09 102 fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
66d1d1a4 103 fTrackPoints(0x0),fClusterMap(0x0)
1b446896 104{
105 //all copied in the initialization
8089a083 106 SetPdgCode(p.GetPdgCode());
107}
108//______________________________________________________________________________
109
bed069a4 110AliHBTParticle::~AliHBTParticle()
111{
112//dtor
113 delete [] fPids;
114 delete [] fPidProb;
f5de2f09 115 delete fTrackPoints;
66d1d1a4 116 delete fClusterMap;
bed069a4 117}
118//______________________________________________________________________________
119
120AliHBTParticle& AliHBTParticle::operator=(const AliHBTParticle& in)
121{
122//assigment operator
123
124 fNPids = in.fNPids;
125 delete [] fPids;
126 delete [] fPidProb;
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++)
130 {
131 fPids[i] = in.fPids[i];
132 fPidProb[i] = in.fPidProb[i];
133 }
134
135 fPdgIdx = in.fPdgIdx;
136 fIdxInEvent = in.fIdxInEvent;
137 fCalcMass = in.GetCalcMass();
138 fPx = in.Px();
139 fPy = in.Py();
140 fPz = in.Pz();
141 fE = in.Energy();
142 fVx = in.Vx();
143 fVy = in.Vy();
144 fVz = in.Vz();
145 fVt = in.T();
146
f5de2f09 147 delete fTrackPoints;
148 fTrackPoints = (in.fTrackPoints)?(AliHBTTrackPoints*)fTrackPoints->Clone():0x0;
149
66d1d1a4 150 delete fClusterMap;
151 fClusterMap = (in.fClusterMap)?(AliHBTClusterMap*)in.fClusterMap->Clone():0x0;
152
bed069a4 153 return *this;
154}
155//______________________________________________________________________________
156
8089a083 157void AliHBTParticle::SetPdgCode(Int_t pdg,Float_t prob)
158{
159 SetPIDprobability(pdg,prob);
160 fPdgIdx = GetPidSlot(pdg);
1b446896 161}
162
163//______________________________________________________________________________
8089a083 164void AliHBTParticle::SetPIDprobability(Int_t pdg, Float_t prob)
165{
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
e665964c 170 if (fgDebug > 9) Info("SetPIDprobability","Setting PID %d prob %f",pdg,prob);
8089a083 171
172 Float_t totprob = 0.0;//sums up probabilities
173 Int_t idx = GetPidSlot(pdg);
174 Int_t i;
175 if (idx > -1)
176 {
177 fPidProb[idx] = prob;
178 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
e665964c 179 if (totprob > (1.0+0.000001))
8089a083 180 {
e665964c 181 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
8089a083 182 }
e665964c 183 if (fgDebug > 9)
8089a083 184 {
185 Info("SetPIDprobability","Current Total probability: %f",totprob);
186 }
187 return;
188 }
189
190 Int_t currentpid = GetPdgCode();
191 fNPids++;
192 Float_t* aPidProbNew = new Float_t[fNPids];
193 Int_t* aPidsNew = new Int_t[fNPids];
194
195 for (i = 0; i < fNPids-1;i++)//find a slot
196 {
197 if ( fPidProb[i] > prob)
198 {
e665964c 199 if (fgDebug>9) Info("SetPID","Copying entry %d",i);
8089a083 200 aPidProbNew[i] = fPidProb[i];
201 aPidsNew[i] = fPids[i];
202 totprob+=fPidProb[i];
203 }
204 else break;
205 }
206
e665964c 207 if (fgDebug > 9) Info("SetPID","Setting new PID on entry %d",i);
8089a083 208 aPidProbNew[i] = prob;
209 aPidsNew[i] = pdg;
210 totprob+=prob;
211
212
e665964c 213 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old araays
8089a083 214 {
e665964c 215 if (fgDebug > 9) Info("SetPID","Copying from old entry %d to new entry %d",j-1,j);
8089a083 216 aPidProbNew[j] = fPidProb[j-1];
217 aPidsNew[j] = fPids[j-1];
218 totprob+=fPidProb[j-1];
219 }
220
8089a083 221 delete [] fPidProb;
222 delete [] fPids;
223
224 fPidProb = aPidProbNew;
225 fPids = aPidsNew;
226
227 fPdgIdx = GetPidSlot(currentpid);
228 if (fPdgIdx == -1) fPdgIdx = 0;
e665964c 229
230 if (totprob > (1.0+0.000001))//place for numerical error
231 {
232 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
233 Print();
234 }
8089a083 235}
236//______________________________________________________________________________
237
37e71815 238Float_t AliHBTParticle::GetPIDprobability(Int_t pdg) const
8089a083 239{
37e71815 240//Returns probability that this particle is the type of pdg
8089a083 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];
244}
245//______________________________________________________________________________
246
1b446896 247const Char_t* AliHBTParticle::GetName() const
248{
37e71815 249 //returns name of this particle
1b446896 250 static char def[4] = "XXX";
8089a083 251 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
1b446896 252 if (ap) return ap->GetName();
253 else return def;
254}
1b446896 255//______________________________________________________________________________
37e71815 256
8089a083 257Int_t AliHBTParticle::GetPidSlot(Int_t pdg) const
258{
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++)
262 {
263 if (fPids[i] == pdg) return i;
264 }
265 return -1;
266}
e665964c 267//______________________________________________________________________________
268
269Int_t AliHBTParticle::GetNthPid(Int_t idx) const
270{
271 //returns PID sitting on slot idx in fPids
272 if ( (idx < 0) || (idx >= fNPids) )
273 {
274 Error("GetNthPid","Out Of Bounds");
275 return 0;
276 }
277 return fPids[idx];
278}
279//______________________________________________________________________________
1b446896 280
e665964c 281Float_t AliHBTParticle::GetNthPidProb(Int_t idx) const
282{
283 //returns PID sitting on slot idx in fPidProb
284 if ( (idx < 0) || (idx >= fNPids) )
285 {
286 Error("GetNthPid","Out Of Bounds");
287 return 0;
288 }
289 return fPidProb[idx];
290}
8089a083 291//______________________________________________________________________________
e665964c 292
8089a083 293void AliHBTParticle::Print() const
294{
295//prints information about particle
296 printf("____________________________________________________\n");
e665964c 297 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
8089a083 298 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
299 if (pdgp)
300 {
e665964c 301 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
8089a083 302 }
303 else
304 {
305 printf("Not known\n");
306 }
307
ff3d1148 308 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
8089a083 309 Px(),Py(),Pz(),Energy(),GetCalcMass(),Vx(),Vy(),Vz(),T());
1b446896 310
8089a083 311 for (Int_t i = 0; i < fNPids; i++)
312 {
ff3d1148 313 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
8089a083 314 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
315 if (ap)
316 {
317 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
318 }
319 else
320 {
321 printf("Not known\n");
322 }
323 }
324}
ff3d1148 325
326//______________________________________________________________________________
327
328//void AliHBTParticle::Streamer(TBuffer &b)
329//{
330// // Stream all objects in the array to or from the I/O buffer.
331// UInt_t R__s, R__c;
332// Int_t i;
333// if (b.IsReading())
334// {
335// delete [] fPids;
336// delete [] fPidProb;
337//
338// Version_t v = b.ReadVersion(&R__s, &R__c);
339// if (v == 1)
340// {
341// AliHBTParticle::Class()->ReadBuffer(b, this);
342// }
343// else
344// {
345// TObject::Streamer(b);
346// b >> fPdgIdx;
347// b >> fIdxInEvent;
348//
349// b >> fNPids;
350// Int_t* fPids = new Int_t[fNPids];
351// Float_t* fPidProb = new Float_t[fNPids];
352// for (i = 0;i<fNPids;i++)
353// {
354// b >> fPids[i];
355// }
356// for (i = 0;i<fNPids;i++)
357// {
358// b >> fPidProb[i];
359// }
360// b >> fCalcMass;
361//
362// b >> fPx;
363// b >> fPy;
364// b >> fPz;
365// b >> fE;
366//
367// b >> fVx;
368// b >> fVy;
369// b >> fVz;
370// b >> fVt;
371// Info("Streamer","Read data");
372// Print();
373// }
374//
375// b.CheckByteCount(R__s, R__c,AliHBTParticle::IsA());
376// }
377// else
378// {
379// R__c = b.WriteVersion(AliHBTParticle::IsA(), kTRUE);
380// TObject::Streamer(b);
381// Info("Streamer","Read data");
382// Print();
383//
384// b << fPdgIdx;
385// b << fIdxInEvent;
386// b << fNPids;
387// for (i = 0;i<fNPids;i++)
388// {
389// b << fPids[i];
390// }
391// {
392// {
393// for (i = 0;i<fNPids;i++)
394// {
395// b << fPidProb[i];
396// }
397// b << fCalcMass;
398//
399// b << fPx;
400// b << fPy;
401// b << fPz;
402// b << fE;
403//
404// b << fVx;
405// b << fVy;
406// b << fVz;
407// b << fVt;
408//
409// b.SetByteCount(R__c, kTRUE);
410// }
411//}