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