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