]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAODParticle.cxx
First version of standalone Makefile for test of PDC04
[u/mrichter/AliRoot.git] / ANALYSIS / AliAODParticle.cxx
CommitLineData
afa8b37b 1#include "AliAODParticle.h"
2//___________________________________________________________
a5556ea5 3/////////////////////////////////////////////////////////////
4//
afa8b37b 5// class AliAODParticle
a5556ea5 6//
afa8b37b 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)
a5556ea5 13//
afa8b37b 14// Piotr.Skowronski@cern.ch
a5556ea5 15//
16/////////////////////////////////////////////////////////////
afa8b37b 17#include <TParticle.h>
18#include "AliTrackPoints.h"
19#include "AliClusterMap.h"
a5556ea5 20
afa8b37b 21ClassImp(AliAODParticle)
a5556ea5 22
afa8b37b 23//______________________________________________________________________________
24AliAODParticle::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),
78d7c6d3 27 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
afa8b37b 28{//empty particle
29}
30//______________________________________________________________________________
a5556ea5 31
afa8b37b 32AliAODParticle::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),
36 fCalcMass(0),
37 fPx(px), fPy(py),fPz(pz),fE(etot),
38 fVx(vx), fVy(vy),fVz(vz),fVt(time),
78d7c6d3 39 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
afa8b37b 40{
41//mormal constructor
42 SetPdgCode(pdg);
43 if (GetPDG()) {
44 fCalcMass = GetPDG()->Mass();
45 } else {
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);
49 }
50}
51//______________________________________________________________________________
52
53AliAODParticle::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),
57 fCalcMass(0),
58 fPx(px), fPy(py),fPz(pz),fE(etot),
59 fVx(vx), fVy(vy),fVz(vz),fVt(time),
78d7c6d3 60 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
afa8b37b 61{
62//mormal constructor
63 SetPdgCode(pdg,prob);
64 if (GetPDG()) {
65 fCalcMass = GetPDG()->Mass();
66 } else {
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);
70 }
71}
72//______________________________________________________________________________
78d7c6d3 73
afa8b37b 74AliAODParticle::AliAODParticle(const AliAODParticle& in):
75 AliVAODParticle(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()),
b9eb3bc7 79 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()),
afa8b37b 80 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
78d7c6d3 81 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
afa8b37b 82{
83 //Copy constructor
dd2b6810 84// Info("AliAODParticle(const AliAODParticle& in)","");
afa8b37b 85 for(Int_t i = 0; i<fNPids; i++)
86 {
87 fPids[i] = in.fPids[i];
88 fPidProb[i] = in.fPidProb[i];
89 }
90
78d7c6d3 91 if (in.fTPCTrackPoints)
92 fTPCTrackPoints = (AliTrackPoints*)in.fTPCTrackPoints->Clone();
93 if (in.fITSTrackPoints)
94 fITSTrackPoints = (AliTrackPoints*)in.fITSTrackPoints->Clone();
afa8b37b 95 if (in.fClusterMap)
96 fClusterMap = (AliClusterMap*)in.fClusterMap->Clone();
97}
78d7c6d3 98//______________________________________________________________________________
afa8b37b 99
78d7c6d3 100AliAODParticle::AliAODParticle(const AliVAODParticle& in):
101 AliVAODParticle(in),
102 fPdgIdx(0), fIdxInEvent(in.GetUID()),
103 fNPids(0),fPids(0x0),fPidProb(0x0),
104 fCalcMass(-1.0),
105 fPx(in.Px()),fPy(in.Py()),fPz(in.Pz()),fE(in.E()),
106 fVx(in.Vx()),fVy(in.Vy()),fVz(in.Vz()),fVt(in.T()),
107 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
108{
109 //Copy constructor
dd2b6810 110 Info("AliAODParticle(const AliVAODParticle& in)","");
78d7c6d3 111 for(Int_t i = 0; i<in.GetNumberOfPids(); i++)
112 {
113 SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
114 }
115 SetPdgCode(in.GetPdgCode(),in.GetPidProb());
116
117 AliTrackPoints* tpts = in.GetTPCTrackPoints();
118 if (tpts) SetTPCTrackPoints((AliTrackPoints*)tpts->Clone());
119
120 tpts = in.GetITSTrackPoints();
121 if (tpts) SetITSTrackPoints((AliTrackPoints*)tpts->Clone());
122
123 AliClusterMap* clmap = in.GetClusterMap();
124 if (clmap) SetClusterMap((AliClusterMap*)clmap->Clone());
125}
afa8b37b 126//______________________________________________________________________________
78d7c6d3 127
afa8b37b 128AliAODParticle::AliAODParticle(const TParticle &p,Int_t idx):
129 fPdgIdx(0), fIdxInEvent(idx),
130 fNPids(0),fPids(0x0),fPidProb(0x0),
131 fCalcMass(p.GetCalcMass()),
132 fPx(p.Px()),fPy(p.Py()),fPz(p.Pz()),fE(p.Energy()),
133 fVx(p.Vx()),fVy(p.Vy()),fVz(p.Vz()),fVt(p.T()),
78d7c6d3 134 fTPCTrackPoints(0x0),fITSTrackPoints(0x0),fClusterMap(0x0)
afa8b37b 135{
136 //all copied in the initialization
137 SetPdgCode(p.GetPdgCode());
138}
139//______________________________________________________________________________
140
141AliAODParticle::~AliAODParticle()
142{
143//dtor
144 delete [] fPids;
145 delete [] fPidProb;
78d7c6d3 146 delete fTPCTrackPoints;
147 delete fITSTrackPoints;
afa8b37b 148 delete fClusterMap;
149}
150//______________________________________________________________________________
151
295c08ac 152void AliAODParticle::Clear(Option_t*)
153{
154//Must be implemented in order to store this object in Clones Array
155 delete [] fPids;
156 delete [] fPidProb;
157 delete fTPCTrackPoints;
158 delete fITSTrackPoints;
159 delete fClusterMap;
160
161 fPids = 0x0;
162 fPidProb = 0x0;
163 fTPCTrackPoints = 0x0;
164 fITSTrackPoints = 0x0;
165 fClusterMap = 0x0;
166}
167//______________________________________________________________________________
168
dd2b6810 169AliAODParticle& AliAODParticle::operator=(const AliVAODParticle& in)
170{
171//operator=
172// Info("operator=(const AliVAODParticle& in)","AliAODParticle");
173
174 delete [] fPids;
175 delete [] fPidProb;
176 fPids = 0x0;
177 fPidProb = 0x0;
178 Int_t npids = in.GetNumberOfPids();
179 for (Int_t i = 0; i < npids; i++)
180 {
181 SetPIDprobability(in.GetNthPid(i),in.GetNthPidProb(i));
182 }
183
184 SetPdgCode(in.GetPdgCode(),in.GetPidProb());
185
186 SetUID(in.GetUID());
187
188 fCalcMass = in.Mass();
189
190 fPx = in.Px();
191 fPy = in.Py();
192 fPz = in.Pz();
193 fE = in.E();
194 fVx = in.Vx();
195 fVy = in.Vy();
196 fVz = in.Vz();
197 fVt = in.T();
198
199 delete fTPCTrackPoints;
200 AliTrackPoints* tpts = in.GetTPCTrackPoints();
201 fTPCTrackPoints = (tpts)?(AliTrackPoints*)tpts->Clone():0x0;
202
203 delete fITSTrackPoints;
204 tpts = in.GetITSTrackPoints();
205 fITSTrackPoints = (tpts)?(AliTrackPoints*)tpts->Clone():0x0;
206
207 delete fClusterMap;
208 AliClusterMap* incmap = in.GetClusterMap();
209 fClusterMap = (incmap)?(AliClusterMap*)incmap->Clone():0x0;
210
211 return *this;
212}
213//______________________________________________________________________________
214
afa8b37b 215AliAODParticle& AliAODParticle::operator=(const AliAODParticle& in)
216{
217//assigment operator
dd2b6810 218// Info("operator=(const AliAODParticle& in)","AliAODParticle");
afa8b37b 219 fNPids = in.fNPids;
220 delete [] fPids;
221 delete [] fPidProb;
dd2b6810 222 fPids = new Int_t[fNPids];
223 fPidProb = new Float_t[fNPids];
afa8b37b 224 for (Int_t i = 0; i < fNPids;i++)
225 {
226 fPids[i] = in.fPids[i];
227 fPidProb[i] = in.fPidProb[i];
228 }
229
230 fPdgIdx = in.fPdgIdx;
231 fIdxInEvent = in.fIdxInEvent;
232 fCalcMass = in.GetCalcMass();
233 fPx = in.Px();
234 fPy = in.Py();
235 fPz = in.Pz();
b9eb3bc7 236 fE = in.E();
afa8b37b 237 fVx = in.Vx();
238 fVy = in.Vy();
239 fVz = in.Vz();
240 fVt = in.T();
241
78d7c6d3 242 delete fTPCTrackPoints;
dd2b6810 243 fTPCTrackPoints = (in.fTPCTrackPoints)?(AliTrackPoints*)in.fTPCTrackPoints->Clone():0x0;
78d7c6d3 244
245 delete fITSTrackPoints;
dd2b6810 246 fITSTrackPoints = (in.fITSTrackPoints)?(AliTrackPoints*)in.fITSTrackPoints->Clone():0x0;
afa8b37b 247
248 delete fClusterMap;
249 fClusterMap = (in.fClusterMap)?(AliClusterMap*)in.fClusterMap->Clone():0x0;
250
251 return *this;
252}
253//______________________________________________________________________________
254
255void AliAODParticle::SetPdgCode(Int_t pdg,Float_t prob)
256{
dd2b6810 257//Set PDG Code
afa8b37b 258 SetPIDprobability(pdg,prob);
259 fPdgIdx = GetPidSlot(pdg);
260}
261
262//______________________________________________________________________________
263void AliAODParticle::SetPIDprobability(Int_t pdg, Float_t prob)
264{
265//Sets another pdg code and corresponding probabilty
266//Ids are set in decreasing order
dd2b6810 267//Check if total probability is not overcoming unity is performed
afa8b37b 268//in case, warning is printed
269 if (GetDebug() > 9) Info("SetPIDprobability","Setting PID %d prob %f",pdg,prob);
270
271 Float_t totprob = 0.0;//sums up probabilities
272 Int_t idx = GetPidSlot(pdg);
273 Int_t i;
274 if (idx > -1)
275 {
276 fPidProb[idx] = prob;
277 for (i = 0; i < fNPids;i++) totprob+=fPidProb[i];
278 if (totprob > (1.0+0.000001))
279 {
280 Warning("SetPIDprobability","Total probability greater than unity (%f)",totprob);
281 }
282 if (GetDebug() > 9)
283 {
284 Info("SetPIDprobability","Current Total probability: %f",totprob);
285 }
286 return;
287 }
288
289 Int_t currentpid = GetPdgCode();
290 fNPids++;
291 Float_t* aPidProbNew = new Float_t[fNPids];
292 Int_t* aPidsNew = new Int_t[fNPids];
293
294 for (i = 0; i < fNPids-1;i++)//find a slot
295 {
296 if ( fPidProb[i] > prob)
297 {
298 if (GetDebug()>9) Info("SetPID","Copying entry %d",i);
299 aPidProbNew[i] = fPidProb[i];
300 aPidsNew[i] = fPids[i];
301 totprob+=fPidProb[i];
302 }
303 else break;
304 }
305
306 if (GetDebug() > 9) Info("SetPID","Setting new PID on entry %d",i);
307 aPidProbNew[i] = prob;
308 aPidsNew[i] = pdg;
309 totprob+=prob;
310
311
dd2b6810 312 for (Int_t j = fNPids-1; j > i ;j--)//copy rest of old arays
afa8b37b 313 {
314 if (GetDebug() > 9) Info("SetPID","Copying from old entry %d to new entry %d",j-1,j);
315 aPidProbNew[j] = fPidProb[j-1];
316 aPidsNew[j] = fPids[j-1];
317 totprob+=fPidProb[j-1];
318 }
319
320 delete [] fPidProb;
321 delete [] fPids;
322
323 fPidProb = aPidProbNew;
324 fPids = aPidsNew;
325
326 fPdgIdx = GetPidSlot(currentpid);
327 if (fPdgIdx == -1) fPdgIdx = 0;
328
78d7c6d3 329 if (totprob > (1.0+0.000001))//space for numerical error
afa8b37b 330 {
331 Warning("SetId","Total probability is greater than unity (%f)!!!",totprob);
332 Print();
333 }
334}
335//______________________________________________________________________________
a5556ea5 336
afa8b37b 337Float_t AliAODParticle::GetPIDprobability(Int_t pdg) const
338{
339//Returns probability that this particle is the type of pdg
340 Int_t idx = GetPidSlot(pdg);
341 if (idx < 0) return 0.0;//such pid was not specified for this particle
342 return fPidProb[idx];
343}
344//______________________________________________________________________________
345
346const Char_t* AliAODParticle::GetName() const
347{
348 //returns name of this particle
349 static char def[4] = "XXX";
350 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
351 if (ap) return ap->GetName();
352 else return def;
353}
354//______________________________________________________________________________
355
356Int_t AliAODParticle::GetPidSlot(Int_t pdg) const
357{
358 //returns position of the given PID in fPids (and fPidProb) array.
359 if (fPids == 0x0) return -1;
360 for (Int_t i = 0; i< fNPids; i++)
361 {
362 if (fPids[i] == pdg) return i;
363 }
364 return -1;
365}
366//______________________________________________________________________________
367
368Int_t AliAODParticle::GetNthPid(Int_t idx) const
369{
370 //returns PID sitting on slot idx in fPids
371 if ( (idx < 0) || (idx >= fNPids) )
372 {
373 Error("GetNthPid","Out Of Bounds");
374 return 0;
375 }
376 return fPids[idx];
377}
378//______________________________________________________________________________
379
380Float_t AliAODParticle::GetNthPidProb(Int_t idx) const
381{
382 //returns PID sitting on slot idx in fPidProb
383 if ( (idx < 0) || (idx >= fNPids) )
384 {
385 Error("GetNthPid","Out Of Bounds");
386 return 0;
387 }
388 return fPidProb[idx];
389}
390//______________________________________________________________________________
391
392void AliAODParticle::Print() const
393{
394//prints information about particle
395 printf("____________________________________________________\n");
396 printf("Idx: %d PID: %d Name: ",fIdxInEvent,GetPdgCode());
397 TParticlePDG *pdgp = TDatabasePDG::Instance()->GetParticle(GetPdgCode());
398 if (pdgp)
399 {
400 printf("%s Mass: %f\n",pdgp->GetName(),pdgp->Mass());
401 }
402 else
403 {
404 printf("Not known\n");
405 }
406
407 printf("Px: %+f Py: %+f Pz: %+f E: %+f Calculated Mass: %f\nVx: %+f Vy: %+f Vz: %+f T: %+f\n",
b9eb3bc7 408 Px(),Py(),Pz(),E(),GetCalcMass(),Vx(),Vy(),Vz(),T());
afa8b37b 409
410 for (Int_t i = 0; i < fNPids; i++)
411 {
412 printf("# %d PID: %d Probability %f name ",i,fPids[i],fPidProb[i]);
413 const TParticlePDG *ap = TDatabasePDG::Instance()->GetParticle(fPids[i]);
414 if (ap)
415 {
416 printf("%s Mass %f\n",ap->GetName(),ap->Mass());
417 }
418 else
419 {
420 printf("Not known\n");
421 }
422 }
423}
424
425//______________________________________________________________________________
426
427//void AliAODParticle::Streamer(TBuffer &b)
428//{
429// // Stream all objects in the array to or from the I/O buffer.
430// UInt_t R__s, R__c;
431// Int_t i;
432// if (b.IsReading())
433// {
434// delete [] fPids;
435// delete [] fPidProb;
436//
437// Version_t v = b.ReadVersion(&R__s, &R__c);
438// if (v == 1)
439// {
440// AliAODParticle::Class()->ReadBuffer(b, this);
441// }
442// else
443// {
444// TObject::Streamer(b);
445// b >> fPdgIdx;
446// b >> fIdxInEvent;
447//
448// b >> fNPids;
449// Int_t* fPids = new Int_t[fNPids];
450// Float_t* fPidProb = new Float_t[fNPids];
451// for (i = 0;i<fNPids;i++)
452// {
453// b >> fPids[i];
454// }
455// for (i = 0;i<fNPids;i++)
456// {
457// b >> fPidProb[i];
458// }
459// b >> fCalcMass;
460//
461// b >> fPx;
462// b >> fPy;
463// b >> fPz;
464// b >> fE;
465//
466// b >> fVx;
467// b >> fVy;
468// b >> fVz;
469// b >> fVt;
470// Info("Streamer","Read data");
471// Print();
472// }
473//
474// b.CheckByteCount(R__s, R__c,AliAODParticle::IsA());
475// }
476// else
477// {
478// R__c = b.WriteVersion(AliAODParticle::IsA(), kTRUE);
479// TObject::Streamer(b);
480// Info("Streamer","Read data");
481// Print();
482//
483// b << fPdgIdx;
484// b << fIdxInEvent;
485// b << fNPids;
486// for (i = 0;i<fNPids;i++)
487// {
488// b << fPids[i];
489// }
490// {
491// {
492// for (i = 0;i<fNPids;i++)
493// {
494// b << fPidProb[i];
495// }
496// b << fCalcMass;
497//
498// b << fPx;
499// b << fPy;
500// b << fPz;
501// b << fE;
502//
503// b << fVx;
504// b << fVy;
505// b << fVz;
506// b << fVt;
507//
508// b.SetByteCount(R__c, kTRUE);
509// }
510//}