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