]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliTrack.cxx
wrap some insanely long lines into mulitple lines.
[u/mrichter/AliRoot.git] / RALICE / AliTrack.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
f531a546 16// $Id$
4c039060 17
959fbac5 18///////////////////////////////////////////////////////////////////////////
19// Class AliTrack
20// Handling of the attributes of a reconstructed particle track.
21//
22// Coding example :
23// ----------------
24//
25// Float_t a[4]={195.,1.2,-0.04,8.5};
26// Ali4Vector pmu;
27// pmu.SetVector(a,"car");
28// AliTrack t1;
29// t1.Set4Momentum(pmu);
30//
31// Float_t b[3]={1.2,-0.04,8.5};
32// Ali3Vector p;
33// p.SetVector(b,"car");
34// AliTrack t2;
35// t2.Set3Momentum(p);
36// t2.SetCharge(0);
37// t2.SetMass(1.115);
38//
84bb7c66 39// t1.Data();
40// t2.Data();
959fbac5 41//
42// Float_t pi=acos(-1.);
43// Float_t thcms=0.2*pi; // decay theta angle in cms
44// Float_t phicms=pi/4.; // decay theta angle in cms
45// Float_t m1=0.938;
46// Float_t m2=0.140;
47// t2.Decay(m1,m2,thcms,phicms); // Track t2 decay : Lambda -> proton + pion
48//
49// t2.List();
50//
51// Int_t ndec=t2.GetNdecay();
52// AliTrack* d1=t2.GetDecayTrack(1); // Access to decay track number 1
53// AliTrack* d2=t2.GetDecayTrack(2); // Access to decay track number 2
54//
55// AliSignal s1,s2,s3,s4;
56//
57// .... // Code (e.g. detector readout) to fill AliSignal data
58//
59// AliTrack trec; // Track which will be reconstructed from signals
60// trec.AddSignal(s1);
61// trec.AddSignal(s3);
62// trec.AddSignal(s4);
63//
64// Ali3Vector P;
65// Float_t Q,M;
66//
67// ... // Code which accesses signals from trec and reconstructs
68// 3-momentum P, charge Q, mass M etc...
69//
70// trec.Set3Momentum(P);
71// trec.SetCharge(Q);
72// trec.SetMass(M);
73//
74// Float_t r1[3]={1.6,-3.8,25.7};
75// Float_t er1[3]={0.2,0.5,1.8};
76// Float_t r2[3]={8.6,23.8,-6.7};
77// Float_t er2[3]={0.93,1.78,0.8};
78// AliPosition begin,end;
79// begin.SetPosition(r1,"car");
80// begin.SetPositionErrors(er1,"car");
81// end.SetPosition(r2,"car");
82// end.SetPositionErrors(er2,"car");
83// trec.SetBeginPoint(begin);
84// trec.SetEndPoint(end);
85//
86// Note : All quantities are in GeV, GeV/c or GeV/c**2
87//
88//--- Author: Nick van Eijndhoven 10-jul-1997 UU-SAP Utrecht
f531a546 89//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 90///////////////////////////////////////////////////////////////////////////
91
d88f97cc 92#include "AliTrack.h"
c72198f1 93#include "Riostream.h"
d88f97cc 94
95ClassImp(AliTrack) // Class implementation to enable ROOT I/O
96
5f25234b 97AliTrack::AliTrack() : TNamed(),Ali4Vector()
d88f97cc 98{
99// Default constructor
100// All variables initialised to 0
6516b62d 101 Init();
102 Reset();
103}
104///////////////////////////////////////////////////////////////////////////
105void AliTrack::Init()
106{
107// Initialisation of pointers etc...
d88f97cc 108 fDecays=0;
959fbac5 109 fSignals=0;
5f25234b 110 fHypotheses=0;
c72198f1 111 fBegin=0;
112 fEnd=0;
113 fImpactXY=0;
114 fImpactXZ=0;
115 fImpactYZ=0;
116 fClosest=0;
1fbffa23 117 fParent=0;
d88f97cc 118}
119///////////////////////////////////////////////////////////////////////////
120AliTrack::~AliTrack()
121{
5f25234b 122// Destructor to delete memory allocated for decay tracks array.
123// This destructor automatically cleares the pointer of this AliTrack
124// from all the link slots of the related AliSignal objects.
125
126 Int_t nsig=GetNsignals();
127 for (Int_t i=1; i<=nsig; i++)
128 {
129 AliSignal* s=GetSignal(i);
d0a8ef71 130 if (s) s->ResetLinks(this);
5f25234b 131 }
132
d88f97cc 133 if (fDecays)
134 {
d88f97cc 135 delete fDecays;
136 fDecays=0;
137 }
959fbac5 138 if (fSignals)
139 {
140 fSignals->Clear();
141 delete fSignals;
142 fSignals=0;
143 }
5f25234b 144 if (fHypotheses)
c72198f1 145 {
5f25234b 146 delete fHypotheses;
147 fHypotheses=0;
c72198f1 148 }
149 if (fBegin)
150 {
151 delete fBegin;
152 fBegin=0;
153 }
154 if (fEnd)
155 {
156 delete fEnd;
157 fEnd=0;
158 }
159 if (fImpactXY)
160 {
161 delete fImpactXY;
162 fImpactXY=0;
163 }
164 if (fImpactXZ)
165 {
166 delete fImpactXZ;
167 fImpactXZ=0;
168 }
169 if (fImpactYZ)
170 {
171 delete fImpactYZ;
172 fImpactYZ=0;
173 }
174 if (fClosest)
175 {
176 delete fClosest;
177 fClosest=0;
178 }
d88f97cc 179}
180///////////////////////////////////////////////////////////////////////////
261c0caf 181AliTrack::AliTrack(const AliTrack& t) : TNamed(t),Ali4Vector(t)
6516b62d 182{
183// Copy constructor
184 Init();
185
c72198f1 186 fQ=t.fQ;
5f25234b 187 fProb=t.fProb;
c72198f1 188 if (t.fBegin) fBegin=new AliPositionObj(*(t.fBegin));
189 if (t.fEnd) fEnd=new AliPositionObj(*(t.fEnd));
190 if (t.fImpactXY) fImpactXY=new AliPositionObj(*(t.fImpactXY));
191 if (t.fImpactXZ) fImpactXZ=new AliPositionObj(*(t.fImpactXZ));
192 if (t.fImpactYZ) fImpactYZ=new AliPositionObj(*(t.fImpactYZ));
193 if (t.fClosest) fClosest=new AliPositionObj(*(t.fClosest));
194 fUserId=t.fUserId;
195 fChi2=t.fChi2;
196 fNdf=t.fNdf;
197 fCode=t.fCode;
1fbffa23 198 fParent=t.fParent;
c72198f1 199
5f25234b 200 Int_t ndec=t.GetNdecay();
201 if (ndec)
6516b62d 202 {
5f25234b 203 fDecays=new TObjArray(ndec);
6516b62d 204 fDecays->SetOwner();
5f25234b 205 for (Int_t it=1; it<=ndec; it++)
6516b62d 206 {
c72198f1 207 AliTrack* tx=t.GetDecayTrack(it);
6516b62d 208 fDecays->Add(new AliTrack(*tx));
209 }
210 }
211
5f25234b 212 Int_t nsig=t.GetNsignals();
213 if (nsig)
6516b62d 214 {
5f25234b 215 fSignals=new TObjArray(nsig);
216 for (Int_t is=1; is<=nsig; is++)
6516b62d 217 {
c72198f1 218 AliSignal* sx=t.GetSignal(is);
6516b62d 219 fSignals->Add(sx);
220 }
221 }
5f25234b 222
223 Int_t nhyp=t.GetNhypotheses();
224 if (nhyp)
225 {
226 fHypotheses=new TObjArray(nhyp);
227 fHypotheses->SetOwner();
228 for (Int_t ih=1; ih<=nhyp; ih++)
229 {
230 AliTrack* tx=t.GetTrackHypothesis(ih);
231 fHypotheses->Add(new AliTrack(*tx));
232 }
233 }
6516b62d 234}
235///////////////////////////////////////////////////////////////////////////
d88f97cc 236void AliTrack::Reset()
237{
35044448 238// Reset all variables to 0 and delete all auto-generated decay tracks.
d88f97cc 239 fQ=0;
2693cb4e 240 fChi2=0;
241 fNdf=0;
43bfa5be 242 fUserId=0;
fdbea0ce 243 fCode=0;
5f25234b 244 fProb=0;
d88f97cc 245 Double_t a[4]={0,0,0,0};
246 SetVector(a,"sph");
1fbffa23 247 fParent=0;
d88f97cc 248 if (fDecays)
249 {
d88f97cc 250 delete fDecays;
251 fDecays=0;
252 }
959fbac5 253 if (fSignals)
254 {
255 fSignals->Clear();
256 delete fSignals;
257 fSignals=0;
258 }
5f25234b 259 if (fHypotheses)
f531a546 260 {
5f25234b 261 delete fHypotheses;
262 fHypotheses=0;
f531a546 263 }
c72198f1 264 if (fBegin)
265 {
266 delete fBegin;
267 fBegin=0;
268 }
269 if (fEnd)
270 {
271 delete fEnd;
272 fEnd=0;
273 }
274 if (fImpactXY)
275 {
276 delete fImpactXY;
277 fImpactXY=0;
278 }
279 if (fImpactXZ)
280 {
281 delete fImpactXZ;
282 fImpactXZ=0;
283 }
284 if (fImpactYZ)
285 {
286 delete fImpactYZ;
287 fImpactYZ=0;
288 }
289 if (fClosest)
290 {
291 delete fClosest;
292 fClosest=0;
293 }
d88f97cc 294}
295///////////////////////////////////////////////////////////////////////////
296void AliTrack::Set3Momentum(Ali3Vector& p)
297{
261c0caf 298// Set the track parameters according to the 3-momentum p.
299// In case the mass was not yet set, the energy is set to correspond to m=0.
959fbac5 300 Set3Vector(p);
261c0caf 301 Double_t inv=GetInvariant();
302 if (inv<0) SetMass(0.);
d88f97cc 303}
304///////////////////////////////////////////////////////////////////////////
305void AliTrack::Set4Momentum(Ali4Vector& p)
306{
307// Set the track parameters according to the 4-momentum p
308 Double_t E=p.GetScalar();
959fbac5 309 Double_t dE=p.GetResultError();
d88f97cc 310 Ali3Vector pv=p.Get3Vector();
311 SetVector(E,pv);
959fbac5 312 SetScalarError(dE);
d88f97cc 313}
314///////////////////////////////////////////////////////////////////////////
959fbac5 315void AliTrack::SetMass(Double_t m,Double_t dm)
d88f97cc 316{
317// Set the particle mass
959fbac5 318// The default value for the error dm is 0.
319 Double_t inv=pow(m,2);
320 Double_t dinv=fabs(2.*m*dm);
321 SetInvariant(inv,dinv);
d88f97cc 322}
323///////////////////////////////////////////////////////////////////////////
324void AliTrack::SetCharge(Float_t q)
325{
326// Set the particle charge
327 fQ=q;
328}
329///////////////////////////////////////////////////////////////////////////
84bb7c66 330void AliTrack::Data(TString f)
d88f97cc 331{
332// Provide track information within the coordinate frame f
959fbac5 333 Double_t m=GetMass();
334 Double_t dm=GetResultError();
5f25234b 335 const char* name=GetName();
336 const char* title=GetTitle();
337
338 cout << " *" << ClassName() << "::Data*";
339 if (strlen(name)) cout << " Name : " << GetName();
340 if (strlen(title)) cout << " Title : " << GetTitle();
341 cout << endl;
342 cout << " Id : " << fUserId << " Code : " << fCode
343 << " m : " << m << " dm : " << dm << " Charge : " << fQ
344 << " p : " << GetMomentum() << endl;
345 cout << " Nhypotheses : " << GetNhypotheses() << " Ndecay-tracks : " << GetNdecay()
346 << " Nsignals : " << GetNsignals() << endl;
84bb7c66 347 Ali4Vector::Data(f);
d88f97cc 348}
349///////////////////////////////////////////////////////////////////////////
350void AliTrack::List(TString f)
351{
352// Provide current track and decay level 1 information within coordinate frame f
353
84bb7c66 354 Data(f); // Information of the current track
d88f97cc 355
356 // Decay products of this track
357 AliTrack* td;
5f25234b 358 for (Int_t id=1; id<=GetNdecay(); id++)
d88f97cc 359 {
360 td=GetDecayTrack(id);
361 if (td)
362 {
363 cout << " ---Level 1 sec. track no. " << id << endl;
84bb7c66 364 td->Data(f);
d88f97cc 365 }
366 else
367 {
5f25234b 368 cout << " *AliTrack::List* Error : Empty decay track slot." << endl;
d88f97cc 369 }
370 }
371}
372///////////////////////////////////////////////////////////////////////////
373void AliTrack::ListAll(TString f)
374{
375// Provide complete track and decay information within the coordinate frame f
376
84bb7c66 377 Data(f); // Information of the current track
c72198f1 378 if (fBegin) { cout << " Begin-point :"; fBegin->Data(f); }
379 if (fEnd) { cout << " End-point :"; fEnd->Data(f); }
5f25234b 380
381 Int_t nhyp=GetNhypotheses();
382 if (nhyp)
383 {
384 cout << " List of the " << nhyp << " track hypotheses : " << endl;
385 for (Int_t ih=1; ih<=nhyp; ih++)
386 {
387 AliTrack* tx=GetTrackHypothesis(ih);
388 if (tx) tx->Data(f);
389 }
390 }
391
392 Int_t nsig=GetNsignals();
393 if (nsig)
959fbac5 394 {
d0a8ef71 395 cout << " List of the corresponding slots for the " << nsig
396 << " related signals : " << endl;
397 AliPosition r;
398 Int_t nrefs,jslot;
399 TArrayI slotarr;
5f25234b 400 for (Int_t is=1; is<=nsig; is++)
401 {
402 AliSignal* sx=GetSignal(is);
d0a8ef71 403 if (sx)
404 {
405 nrefs=sx->GetIndices(this,slotarr,0);
406 for (Int_t jref=0; jref<nrefs; jref++)
407 {
408 jslot=slotarr.At(jref);
409 sx->List(jslot);
410 }
411 r=sx->GetPosition();
412 cout << " Position";
413 r.Data(f);
414 }
5f25234b 415 }
959fbac5 416 }
d88f97cc 417
418 AliTrack* t=this;
1c01b4f8 419 Dumps(t,1,f); // Information of all decay products
d88f97cc 420}
421//////////////////////////////////////////////////////////////////////////
1c01b4f8 422void AliTrack::Dumps(AliTrack* t,Int_t n,TString f)
d88f97cc 423{
424// Recursively provide the info of all decay levels of this track
425 AliTrack* td;
426 for (Int_t id=1; id<=t->GetNdecay(); id++)
427 {
428 td=t->GetDecayTrack(id);
429 if (td)
430 {
431 cout << " ---Level " << n << " sec. track no. " << id << endl;
84bb7c66 432 td->Data(f);
5f25234b 433
434 Int_t nhyp=td->GetNhypotheses();
435 if (nhyp)
436 {
437 cout << " List of the " << nhyp << " track hypotheses : " << endl;
438 for (Int_t ih=1; ih<=nhyp; ih++)
439 {
440 AliTrack* tx=td->GetTrackHypothesis(ih);
441 if (tx) tx->Data(f);
442 }
443 }
444
445 Int_t nsig=td->GetNsignals();
446 if (nsig)
959fbac5 447 {
5f25234b 448 cout << " List of the " << nsig << " related signals : " << endl;
449 for (Int_t is=1; is<=nsig; is++)
450 {
451 AliSignal* sx=td->GetSignal(is);
452 if (sx) sx->Data(f);
453 }
959fbac5 454 }
d88f97cc 455
456 // Go for next decay level of this decay track recursively
1c01b4f8 457 Dumps(td,n+1,f);
d88f97cc 458 }
459 else
460 {
5f25234b 461 cout << " *AliTrack::Dumps* Error : Empty decay track slot." << endl;
d88f97cc 462 }
463 }
464}
465//////////////////////////////////////////////////////////////////////////
466Double_t AliTrack::GetMomentum()
467{
959fbac5 468// Provide the value of the track 3-momentum.
469// The error can be obtained by invoking GetResultError() after
470// invokation of GetMomentum().
959fbac5 471 Double_t norm=fV.GetNorm();
d071d629 472 fDresult=fV.GetResultError();
959fbac5 473 return norm;
d88f97cc 474}
475///////////////////////////////////////////////////////////////////////////
261c0caf 476Ali3Vector AliTrack::Get3Momentum() const
d88f97cc 477{
478// Provide the track 3-momentum
479 return (Ali3Vector)Get3Vector();
480}
481///////////////////////////////////////////////////////////////////////////
482Double_t AliTrack::GetMass()
483{
959fbac5 484// Provide the particle mass.
485// The error can be obtained by invoking GetResultError() after
486// invokation of GetMass().
487 Double_t inv=GetInvariant();
488 Double_t dinv=GetResultError();
489 Double_t dm=0;
490 if (inv >= 0)
491 {
492 Double_t m=sqrt(inv);
493 if (m) dm=dinv/(2.*m);
494 fDresult=dm;
495 return m;
496 }
497 else
498 {
499 cout << "*AliTrack::GetMass* Unphysical situation m**2 = " << inv << endl;
500 cout << " Value 0 will be returned." << endl;
501 fDresult=dm;
502 return 0;
503 }
d88f97cc 504}
505///////////////////////////////////////////////////////////////////////////
261c0caf 506Float_t AliTrack::GetCharge() const
d88f97cc 507{
508// Provide the particle charge
509 return fQ;
510}
511///////////////////////////////////////////////////////////////////////////
512Double_t AliTrack::GetEnergy()
513{
959fbac5 514// Provide the particle's energy.
515// The error can be obtained by invoking GetResultError() after
516// invokation of GetEnergy().
517 Double_t E=GetScalar();
518 if (E>0)
519 {
520 return E;
521 }
522 else
523 {
524 cout << "*AliTrack::GetEnergy* Unphysical situation E = " << E << endl;
525 cout << " Value 0 will be returned." << endl;
526 return 0;
527 }
d88f97cc 528}
529///////////////////////////////////////////////////////////////////////////
530void AliTrack::Decay(Double_t m1,Double_t m2,Double_t thcms,Double_t phicms)
531{
532// Perform 2-body decay of current track
533// m1 : mass of decay product 1
534// m2 : mass of decay product 2
535// thcms : cms theta decay angle (in rad.) of m1
536// phicms : cms phi decay angle (in rad.) of m1
537
959fbac5 538 Double_t M=GetMass();
d88f97cc 539
540// Compute the 4-momenta of the decay products in the cms
541// Note : p2=p1=pnorm for a 2-body decay
959fbac5 542 Double_t e1=0;
543 if (M) e1=((M*M)+(m1*m1)-(m2*m2))/(2.*M);
544 Double_t e2=0;
545 if (M) e2=((M*M)+(m2*m2)-(m1*m1))/(2.*M);
d88f97cc 546 Double_t pnorm=(e1*e1)-(m1*m1);
547 if (pnorm>0.)
548 {
549 pnorm=sqrt(pnorm);
550 }
551 else
552 {
553 pnorm=0;
554 }
555
556 Double_t a[3];
557 a[0]=pnorm;
558 a[1]=thcms;
559 a[2]=phicms;
560 Ali3Vector p;
561 p.SetVector(a,"sph");
562
563 Ali4Vector pprim1;
564 pprim1.SetVector(e1,p);
959fbac5 565 pprim1.SetInvariant(m1*m1);
d88f97cc 566
567 Ali4Vector pprim2;
568 p*=-1;
569 pprim2.SetVector(e2,p);
959fbac5 570 pprim2.SetInvariant(m2*m2);
d88f97cc 571
572 // Determine boost parameters from the parent particle
959fbac5 573 Double_t E=GetEnergy();
d88f97cc 574 p=Get3Vector();
575 Ali4Vector pmu;
576 pmu.SetVector(E,p);
577
578 AliBoost q;
579 q.Set4Momentum(pmu);
580
581 Ali4Vector p1=q.Inverse(pprim1); // Boost decay product 1
582 Ali4Vector p2=q.Inverse(pprim2); // Boost decay product 2
583
584 // Enter the boosted data into the decay tracks array
585 if (fDecays)
586 {
d88f97cc 587 delete fDecays;
6516b62d 588 fDecays=0;
d88f97cc 589 }
5f25234b 590 fDecays=new TObjArray(2);
6516b62d 591 fDecays->SetOwner();
d88f97cc 592
593 fDecays->Add(new AliTrack);
594 ((AliTrack*)fDecays->At(0))->Set4Momentum(p1);
959fbac5 595 ((AliTrack*)fDecays->At(0))->SetMass(m1);
d88f97cc 596 fDecays->Add(new AliTrack);
597 ((AliTrack*)fDecays->At(1))->Set4Momentum(p2);
d88f97cc 598 ((AliTrack*)fDecays->At(1))->SetMass(m2);
599}
600///////////////////////////////////////////////////////////////////////////
261c0caf 601Int_t AliTrack::GetNdecay() const
d88f97cc 602{
603// Provide the number of decay produced tracks
5f25234b 604 Int_t ndec=0;
605 if (fDecays) ndec=fDecays->GetEntries();
606 return ndec;
d88f97cc 607}
608///////////////////////////////////////////////////////////////////////////
261c0caf 609AliTrack* AliTrack::GetDecayTrack(Int_t j) const
d88f97cc 610{
611// Provide decay produced track number j
612// Note : j=1 denotes the first decay track
6516b62d 613 if (!fDecays)
d88f97cc 614 {
6516b62d 615 cout << " *AliTrack::GetDecayTrack* No tracks present." << endl;
616 return 0;
d88f97cc 617 }
618 else
619 {
5f25234b 620 if ((j >= 1) && (j <= GetNdecay()))
6516b62d 621 {
622 return (AliTrack*)fDecays->At(j-1);
623 }
624 else
625 {
626 cout << " *AliTrack* decay track number : " << j << " out of range."
5f25234b 627 << " Ndec = " << GetNdecay() << endl;
6516b62d 628 return 0;
629 }
d88f97cc 630 }
631}
632///////////////////////////////////////////////////////////////////////////
5f25234b 633void AliTrack::RemoveDecays()
634{
635// Remove all decay tracks from this track.
636 if (fDecays)
637 {
638 delete fDecays;
639 fDecays=0;
640 }
641}
642///////////////////////////////////////////////////////////////////////////
959fbac5 643void AliTrack::AddSignal(AliSignal& s)
644{
645// Relate an AliSignal object to this track.
5f25234b 646 if (!fSignals) fSignals=new TObjArray(1);
647
648 // Check if this signal is already stored for this track
649 Int_t nsig=GetNsignals();
650 for (Int_t i=0; i<nsig; i++)
651 {
652 if (&s==fSignals->At(i)) return;
653 }
654
959fbac5 655 fSignals->Add(&s);
656}
657///////////////////////////////////////////////////////////////////////////
658void AliTrack::RemoveSignal(AliSignal& s)
659{
5f25234b 660// Remove related AliSignal object from this track.
959fbac5 661 if (fSignals)
662 {
663 AliSignal* test=(AliSignal*)fSignals->Remove(&s);
5f25234b 664 if (test) fSignals->Compress();
665 }
666}
667///////////////////////////////////////////////////////////////////////////
668void AliTrack::RemoveSignals()
669{
670// Remove all related AliSignal objects from this track.
671 if (fSignals)
672 {
673 fSignals->Clear();
674 delete fSignals;
675 fSignals=0;
959fbac5 676 }
677}
678///////////////////////////////////////////////////////////////////////////
261c0caf 679Int_t AliTrack::GetNsignals() const
959fbac5 680{
681// Provide the number of related AliSignals.
5f25234b 682 Int_t nsig=0;
683 if (fSignals) nsig=fSignals->GetEntries();
684 return nsig;
959fbac5 685}
686///////////////////////////////////////////////////////////////////////////
261c0caf 687AliSignal* AliTrack::GetSignal(Int_t j) const
959fbac5 688{
689// Provide the related AliSignal number j.
690// Note : j=1 denotes the first signal.
6516b62d 691 if (!fSignals)
959fbac5 692 {
6516b62d 693 cout << " *AliTrack::GetSignal* No signals present." << endl;
694 return 0;
959fbac5 695 }
696 else
697 {
5f25234b 698 if ((j >= 1) && (j <= GetNsignals()))
6516b62d 699 {
700 return (AliSignal*)fSignals->At(j-1);
701 }
702 else
703 {
704 cout << " *AliTrack* signal number : " << j << " out of range."
5f25234b 705 << " Nsig = " << GetNsignals() << endl;
6516b62d 706 return 0;
707 }
959fbac5 708 }
709}
710///////////////////////////////////////////////////////////////////////////
5f25234b 711void AliTrack::AddTrackHypothesis(AliTrack& t)
959fbac5 712{
5f25234b 713// Relate a track hypothesis to this track.
714// Note : a private copy of the input track will be made via the Clone()
715// facility.
716 if (!fHypotheses)
c72198f1 717 {
5f25234b 718 fHypotheses=new TObjArray(1);
719 fHypotheses->SetOwner();
c72198f1 720 }
5f25234b 721 fHypotheses->Add(t.Clone());
959fbac5 722}
723///////////////////////////////////////////////////////////////////////////
5f25234b 724void AliTrack::AddTrackHypothesis(Double_t prob,Double_t m,Double_t dm)
959fbac5 725{
5f25234b 726// Add a track hypothesis by explicitly setting the mass and probability.
727// This will affect e.g. the hypothesis track's energy, since the momentum
728// and all other attributes will be copied from the current track.
729//
730// Input arguments :
731// -----------------
732// prob=probalility m=mass value dm=error on the mass value.
733// The default value for the mass error dm is 0.
734
735 AliTrack t(*this);
736 t.RemoveDecays();
737 t.RemoveTrackHypotheses();
738 t.RemoveSignals();
739 t.SetTitle("Mass hypothesis");
740 t.SetMass(m,dm);
741 t.SetProb(prob);
742 AddTrackHypothesis(t);
959fbac5 743}
744///////////////////////////////////////////////////////////////////////////
5f25234b 745void AliTrack::RemoveTrackHypothesis(AliTrack& t)
959fbac5 746{
5f25234b 747// Remove the specified track hypothesis from this track.
748 if (fHypotheses)
c72198f1 749 {
5f25234b 750 AliTrack* test=(AliTrack*)fHypotheses->Remove(&t);
751 if (test) fHypotheses->Compress();
c72198f1 752 }
959fbac5 753}
754///////////////////////////////////////////////////////////////////////////
5f25234b 755void AliTrack::RemoveTrackHypotheses()
959fbac5 756{
5f25234b 757// Remove all track hypotheses from this track.
758 if (fHypotheses)
759 {
760 delete fHypotheses;
761 fHypotheses=0;
762 }
f531a546 763}
764///////////////////////////////////////////////////////////////////////////
261c0caf 765Int_t AliTrack::GetNhypotheses() const
f531a546 766{
5f25234b 767// Provide the number of track hypotheses.
768 Int_t nhyp=0;
769 if (fHypotheses) nhyp=fHypotheses->GetEntries();
770 return nhyp;
f531a546 771}
772///////////////////////////////////////////////////////////////////////////
261c0caf 773AliTrack* AliTrack::GetTrackHypothesis(Int_t j) const
f531a546 774{
5f25234b 775// Provide the j-th track hypothesis.
776// Note : j=1 denotes the first hypothesis.
f531a546 777// Default : j=0 ==> Hypothesis with highest probability.
f531a546 778
5f25234b 779 if (!fHypotheses) return 0;
780
781 Int_t nhyp=GetNhypotheses();
f531a546 782
783 // Check validity of index j
5f25234b 784 if (j<0 || j>nhyp)
f531a546 785 {
5f25234b 786 cout << " *AliTrack* hypothesis number : " << j << " out of range."
787 << " Nhyp = " << nhyp << endl;
788 return 0;
789 }
f531a546 790
5f25234b 791 AliTrack* t=0;
792
793 if (j==0) // Provide track hypothesis with highest probability
f531a546 794 {
5f25234b 795 Float_t prob=0;
796 t=(AliTrack*)fHypotheses->At(0);
797 if (t) prob=t->GetProb();
798 Float_t probx=0;
799 for (Int_t ih=1; ih<nhyp; ih++)
f531a546 800 {
5f25234b 801 AliTrack* tx=(AliTrack*)fHypotheses->At(ih);
802 if (tx)
f531a546 803 {
5f25234b 804 probx=tx->GetProb();
805 if (probx > prob) t=tx;
f531a546 806 }
807 }
5f25234b 808 return t;
809 }
810 else // Provide requested j-th track hypothesis
811 {
812 return (AliTrack*)fHypotheses->At(j-1);
f531a546 813 }
f531a546 814}
815///////////////////////////////////////////////////////////////////////////
5f25234b 816void AliTrack::SetBeginPoint(AliPosition& p)
f531a546 817{
5f25234b 818// Store the position of the track begin-point.
819 if (!fBegin)
f531a546 820 {
5f25234b 821 fBegin=new AliPositionObj(p);
f531a546 822 }
5f25234b 823 else
f531a546 824 {
5f25234b 825 fBegin->Load(p);
f531a546 826 }
f531a546 827}
828///////////////////////////////////////////////////////////////////////////
5f25234b 829AliPosition* AliTrack::GetBeginPoint()
f531a546 830{
5f25234b 831// Provide the position of the track begin-point.
832 return fBegin;
833}
834///////////////////////////////////////////////////////////////////////////
835void AliTrack::SetEndPoint(AliPosition& p)
836{
837// Store the position of the track end-point.
838 if (!fEnd)
f531a546 839 {
5f25234b 840 fEnd=new AliPositionObj(p);
f531a546 841 }
842 else
843 {
5f25234b 844 fEnd->Load(p);
f531a546 845 }
846}
847///////////////////////////////////////////////////////////////////////////
5f25234b 848AliPosition* AliTrack::GetEndPoint()
849{
850// Provide the position of the track end-point.
851 return fEnd;
852}
853///////////////////////////////////////////////////////////////////////////
854void AliTrack::SetMass()
f531a546 855{
5f25234b 856// Set the mass and error to the value of the hypothesis with highest prob.
f531a546 857
5f25234b 858 Double_t m=0,dm=0;
859
860 // Select mass hypothesis with highest probability
861 AliTrack* t=GetTrackHypothesis(0);
862 if (t)
f531a546 863 {
5f25234b 864 m=t->GetMass();
865 dm=t->GetResultError();
866 SetMass(m,dm);
f531a546 867 }
868 else
869 {
5f25234b 870 cout << " *AliTrack::SetMass()* No hypothesis present => No action." << endl;
f531a546 871 }
872}
873///////////////////////////////////////////////////////////////////////////
d071d629 874Double_t AliTrack::GetPt()
875{
876// Provide trans. momentum value w.r.t. z-axis.
877// The error on the value can be obtained by GetResultError()
878// after invokation of GetPt().
879 Ali3Vector v;
880 v=GetVecTrans();
881 Double_t norm=v.GetNorm();
882 fDresult=v.GetResultError();
883
884 return norm;
885}
886///////////////////////////////////////////////////////////////////////////
887Double_t AliTrack::GetPl()
888{
889// Provide long. momentum value w.r.t. z-axis.
8adaf597 890// Note : the returned value can also be negative.
d071d629 891// The error on the value can be obtained by GetResultError()
892// after invokation of GetPl().
893 Ali3Vector v;
894 v=GetVecLong();
8adaf597 895
896 Double_t pl=v.GetNorm();
d071d629 897 fDresult=v.GetResultError();
898
8adaf597 899 Double_t a[3];
900 v.GetVector(a,"sph");
901 if (cos(a[1])<0) pl=-pl;
902
903 return pl;
d071d629 904}
905///////////////////////////////////////////////////////////////////////////
906Double_t AliTrack::GetEt()
907{
908// Provide trans. energy value w.r.t. z-axis.
909// The error on the value can be obtained by GetResultError()
910// after invokation of GetEt().
911 Double_t et=GetScaTrans();
912
913 return et;
914}
915///////////////////////////////////////////////////////////////////////////
916Double_t AliTrack::GetEl()
917{
918// Provide long. energy value w.r.t. z-axis.
8adaf597 919// Note : the returned value can also be negative.
d071d629 920// The error on the value can be obtained by GetResultError()
921// after invokation of GetEl().
922 Double_t el=GetScaLong();
923
924 return el;
925}
926///////////////////////////////////////////////////////////////////////////
927Double_t AliTrack::GetMt()
928{
929// Provide transverse mass value w.r.t. z-axis.
930// The error on the value can be obtained by GetResultError()
931// after invokation of GetMt().
932 Double_t pt=GetPt();
933 Double_t dpt=GetResultError();
934 Double_t m=GetMass();
935 Double_t dm=GetResultError();
936
937 Double_t mt=sqrt(pt*pt+m*m);
938 Double_t dmt2=0;
939 if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
940
941 fDresult=sqrt(dmt2);
942 return mt;
943}
944///////////////////////////////////////////////////////////////////////////
8adaf597 945Double_t AliTrack::GetRapidity()
946{
947// Provide rapidity value w.r.t. z-axis.
948// The error on the value can be obtained by GetResultError()
949// after invokation of GetRapidity().
950// Note : Also GetPseudoRapidity() is available since this class is
951// derived from Ali4Vector.
952 Double_t e=GetEnergy();
953 Double_t de=GetResultError();
954 Double_t pl=GetPl();
955 Double_t dpl=GetResultError();
956 Double_t sum=e+pl;
957 Double_t dif=e-pl;
958
959 Double_t y=9999,dy2=0;
960 if (sum && dif) y=0.5*log(sum/dif);
961
962 if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
963
964 fDresult=sqrt(dy2);
965 return y;
966}
967///////////////////////////////////////////////////////////////////////////
c72198f1 968void AliTrack::SetImpactPoint(AliPosition& p,TString q)
43bfa5be 969{
970// Store the position of the impact-point in the plane "q=0".
971// Here q denotes one of the axes X, Y or Z.
972// Note : The character to denote the axis may be entered in lower or
973// in uppercase.
974 Int_t axis=0;
975 if (q=="x" || q=="X") axis=1;
976 if (q=="y" || q=="Y") axis=2;
977 if (q=="z" || q=="Z") axis=3;
978
979 switch (axis)
980 {
981 case 1: // Impact-point in the plane X=0
c72198f1 982 if (!fImpactYZ)
983 {
984 fImpactYZ=new AliPositionObj(p);
985 }
986 else
987 {
988 fImpactYZ->Load(p);
989 }
43bfa5be 990 break;
991
992 case 2: // Impact-point in the plane Y=0
c72198f1 993 if (!fImpactXZ)
994 {
995 fImpactXZ=new AliPositionObj(p);
996 }
997 else
998 {
999 fImpactXZ->Load(p);
1000 }
43bfa5be 1001 break;
1002
1003 case 3: // Impact-point in the plane Z=0
c72198f1 1004 if (!fImpactXY)
1005 {
1006 fImpactXY=new AliPositionObj(p);
1007 }
1008 else
1009 {
1010 fImpactXY->Load(p);
1011 }
43bfa5be 1012 break;
1013
1014 default: // Unsupported axis
1015 cout << "*AliTrack::SetImpactPoint* Unsupported axis : " << q << endl
1016 << " Possible axes are 'X', 'Y' and 'Z'." << endl;
1017 break;
1018 }
1019}
1020///////////////////////////////////////////////////////////////////////////
c72198f1 1021AliPosition* AliTrack::GetImpactPoint(TString q)
43bfa5be 1022{
1023// Provide the position of the impact-point in the plane "q=0".
1024// Here q denotes one of the axes X, Y or Z.
1025// Note : The character to denote the axis may be entered in lower or
1026// in uppercase.
43bfa5be 1027 Int_t axis=0;
1028 if (q=="x" || q=="X") axis=1;
1029 if (q=="y" || q=="Y") axis=2;
1030 if (q=="z" || q=="Z") axis=3;
1031
1032 switch (axis)
1033 {
1034 case 1: // Impact-point in the plane X=0
1035 return fImpactYZ;
1036
1037 case 2: // Impact-point in the plane Y=0
1038 return fImpactXZ;
1039
1040 case 3: // Impact-point in the plane Z=0
1041 return fImpactXY;
1042
1043 default: // Unsupported axis
1044 cout << "*AliTrack::GetImpactPoint* Unsupported axis : " << q << endl
1045 << " Possible axes are 'X', 'Y' and 'Z'." << endl;
c72198f1 1046 return 0;
43bfa5be 1047 }
1048}
1049///////////////////////////////////////////////////////////////////////////
1050void AliTrack::SetId(Int_t id)
1051{
fdbea0ce 1052// Set a user defined unique identifier for this track.
43bfa5be 1053 fUserId=id;
1054}
1055///////////////////////////////////////////////////////////////////////////
261c0caf 1056Int_t AliTrack::GetId() const
43bfa5be 1057{
fdbea0ce 1058// Provide the user defined unique identifier of this track.
43bfa5be 1059 return fUserId;
1060}
1061///////////////////////////////////////////////////////////////////////////
c72198f1 1062void AliTrack::SetClosestPoint(AliPosition& p)
43bfa5be 1063{
1064// Set position p as the point of closest approach w.r.t. some reference
c72198f1 1065 if (!fClosest)
1066 {
1067 fClosest=new AliPositionObj(p);
1068 }
1069 else
1070 {
1071 fClosest->Load(p);
1072 }
43bfa5be 1073}
1074///////////////////////////////////////////////////////////////////////////
c72198f1 1075AliPosition* AliTrack::GetClosestPoint()
43bfa5be 1076{
1077// Provide the point of closest approach w.r.t. some reference
1078 return fClosest;
1079}
1080///////////////////////////////////////////////////////////////////////////
2693cb4e 1081void AliTrack::SetChi2(Float_t chi2)
1082{
1083// Set the chi-squared value of the track fit.
1084 if (chi2<0)
1085 {
1086 cout << " *AliTrack::SetChi2* Invalid chi2 value : " << chi2 << endl;
1087 }
1088 else
1089 {
1090 fChi2=chi2;
1091 }
1092}
1093///////////////////////////////////////////////////////////////////////////
1094void AliTrack::SetNdf(Int_t ndf)
1095{
1096// Set the number of degrees of freedom for the track fit.
1097 if (ndf<0)
1098 {
1099 cout << " *AliTrack::SetNdf* Invalid ndf value : " << ndf << endl;
1100 }
1101 else
1102 {
1103 fNdf=ndf;
1104 }
1105}
1106///////////////////////////////////////////////////////////////////////////
261c0caf 1107Float_t AliTrack::GetChi2() const
2693cb4e 1108{
1109// Provide the chi-squared value of the track fit.
1110 return fChi2;
1111}
1112///////////////////////////////////////////////////////////////////////////
261c0caf 1113Int_t AliTrack::GetNdf() const
2693cb4e 1114{
1115// Provide the number of degrees of freedom for the track fit.
1116 return fNdf;
1117}
1118///////////////////////////////////////////////////////////////////////////
fdbea0ce 1119void AliTrack::SetParticleCode(Int_t code)
1120{
1121// Set the user defined particle id code (e.g. the PDF convention).
1122 fCode=code;
1123}
1124///////////////////////////////////////////////////////////////////////////
261c0caf 1125Int_t AliTrack::GetParticleCode() const
fdbea0ce 1126{
1127// Provide the user defined particle id code.
1128 return fCode;
1129}
1130///////////////////////////////////////////////////////////////////////////
1fbffa23 1131void AliTrack::SetParentTrack(AliTrack* t)
1132{
1133// Set pointer to the parent track.
1134 fParent=t;
1135}
1136///////////////////////////////////////////////////////////////////////////
1137AliTrack* AliTrack::GetParentTrack()
1138{
1139// Provide pointer to the parent track.
1140 return fParent;
1141}
1142///////////////////////////////////////////////////////////////////////////
5f25234b 1143void AliTrack::SetProb(Double_t prob)
1144{
1145// Set hypothesis probability for this track.
1146 fProb=prob;
1147}
1148///////////////////////////////////////////////////////////////////////////
261c0caf 1149Float_t AliTrack::GetProb() const
5f25234b 1150{
1151// Provide the hypothesis probability for this track.
1152 return fProb;
1153}
1154///////////////////////////////////////////////////////////////////////////
261c0caf 1155TObject* AliTrack::Clone(const char* name) const
5f25234b 1156{
1157// Make a deep copy of the current object and provide the pointer to the copy.
1158// This memberfunction enables automatic creation of new objects of the
1159// correct type depending on the object type, a feature which may be very useful
1160// for containers when adding objects in case the container owns the objects.
1161// This feature allows e.g. AliJet to store either AliTrack objects or
1162// objects derived from AliTrack via the AddTrack memberfunction, provided
1163// these derived classes also have a proper Clone memberfunction.
1164
1165 AliTrack* trk=new AliTrack(*this);
1166 if (name)
1167 {
1168 if (strlen(name)) trk->SetName(name);
1169 }
1170 return trk;
1171}
1172///////////////////////////////////////////////////////////////////////////