]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliTrack.cxx
12-may-2004 NvE Track reference-point introduced in AliTrack.
[u/mrichter/AliRoot.git] / RALICE / AliTrack.cxx
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
16 // $Id$
17
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 //
39 // t1.Data();
40 // t2.Data();
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
89 //- Modified: NvE $Date$ UU-SAP Utrecht
90 ///////////////////////////////////////////////////////////////////////////
91
92 #include "AliTrack.h"
93 #include "Riostream.h"
94  
95 ClassImp(AliTrack) // Class implementation to enable ROOT I/O
96  
97 AliTrack::AliTrack() : TNamed(),Ali4Vector()
98 {
99 // Default constructor
100 // All variables initialised to 0
101  Init();
102  Reset();
103 }
104 ///////////////////////////////////////////////////////////////////////////
105 void AliTrack::Init()
106 {
107 // Initialisation of pointers etc...
108  fDecays=0;
109  fSignals=0;
110  fHypotheses=0;
111  fBegin=0;
112  fEnd=0;
113  fRef=0;
114  fImpactXY=0;
115  fImpactXZ=0;
116  fImpactYZ=0;
117  fClosest=0;
118  fParent=0;
119 }
120 ///////////////////////////////////////////////////////////////////////////
121 AliTrack::~AliTrack()
122 {
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);
131   if (s) s->ResetLinks(this);
132  }
133  
134  if (fDecays)
135  {
136   delete fDecays;
137   fDecays=0;
138  }
139  if (fSignals)
140  {
141   fSignals->Clear();
142   delete fSignals;
143   fSignals=0;
144  }
145  if (fHypotheses)
146  {
147   delete fHypotheses;
148   fHypotheses=0;
149  }
150  if (fBegin)
151  {
152   delete fBegin;
153   fBegin=0;
154  }
155  if (fEnd)
156  {
157   delete fEnd;
158   fEnd=0;
159  }
160  if (fRef)
161  {
162   delete fRef;
163   fRef=0;
164  }
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  }
185 }
186 ///////////////////////////////////////////////////////////////////////////
187 AliTrack::AliTrack(const AliTrack& t) : TNamed(t),Ali4Vector(t)
188 {
189 // Copy constructor
190  Init();
191
192  fQ=t.fQ;
193  fProb=t.fProb;
194  if (t.fBegin) fBegin=new AliPositionObj(*(t.fBegin));
195  if (t.fEnd) fEnd=new AliPositionObj(*(t.fEnd));
196  if (t.fRef) fRef=new AliPositionObj(*(t.fRef));
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;
205  fParent=t.fParent;
206
207  Int_t ndec=t.GetNdecay();
208  if (ndec)
209  {
210   fDecays=new TObjArray(ndec);
211   fDecays->SetOwner();
212   for (Int_t it=1; it<=ndec; it++)
213   {
214    AliTrack* tx=t.GetDecayTrack(it);
215    fDecays->Add(new AliTrack(*tx));
216   }
217  }
218
219  Int_t nsig=t.GetNsignals();
220  if (nsig)
221  {
222   fSignals=new TObjArray(nsig);
223   for (Int_t is=1; is<=nsig; is++)
224   {
225    AliSignal* sx=t.GetSignal(is);
226    fSignals->Add(sx);
227   }
228  }
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  }
241 }
242 ///////////////////////////////////////////////////////////////////////////
243 void AliTrack::Reset()
244 {
245 // Reset all variables to 0 and delete all auto-generated decay tracks.
246  fQ=0;
247  fChi2=0;
248  fNdf=0;
249  fUserId=0;
250  fCode=0;
251  fProb=0;
252  Double_t a[4]={0,0,0,0};
253  SetVector(a,"sph");
254  fParent=0;
255  if (fDecays)
256  {
257   delete fDecays;
258   fDecays=0;
259  }
260  if (fSignals)
261  {
262   fSignals->Clear();
263   delete fSignals;
264   fSignals=0;
265  }
266  if (fHypotheses)
267  {
268   delete fHypotheses;
269   fHypotheses=0;
270  }
271  if (fBegin)
272  {
273   delete fBegin;
274   fBegin=0;
275  }
276  if (fEnd)
277  {
278   delete fEnd;
279   fEnd=0;
280  }
281  if (fRef)
282  {
283   delete fRef;
284   fRef=0;
285  }
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  }
306 }
307 ///////////////////////////////////////////////////////////////////////////
308 void AliTrack::Set3Momentum(Ali3Vector& p)
309 {
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. 
312  Set3Vector(p);
313  Double_t inv=GetInvariant();
314  if (inv<0) SetMass(0.);
315 }
316 ///////////////////////////////////////////////////////////////////////////
317 void AliTrack::Set4Momentum(Ali4Vector& p)
318 {
319 // Set the track parameters according to the 4-momentum p
320  Double_t E=p.GetScalar();
321  Double_t dE=p.GetResultError();
322  Ali3Vector pv=p.Get3Vector();
323  SetVector(E,pv);
324  SetScalarError(dE);
325 }
326 ///////////////////////////////////////////////////////////////////////////
327 void AliTrack::SetMass(Double_t m,Double_t dm)
328 {
329 // Set the particle mass
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);
334 }
335 ///////////////////////////////////////////////////////////////////////////
336 void AliTrack::SetCharge(Float_t q)
337 {
338 // Set the particle charge
339  fQ=q;
340 }
341 ///////////////////////////////////////////////////////////////////////////
342 void AliTrack::Data(TString f)
343 {
344 // Provide track information within the coordinate frame f
345  Double_t m=GetMass();
346  Double_t dm=GetResultError();
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;
359  Ali4Vector::Data(f); 
360
361 ///////////////////////////////////////////////////////////////////////////
362 void AliTrack::List(TString f)
363 {
364 // Provide current track and decay level 1 information within coordinate frame f
365
366  Data(f); // Information of the current track
367
368  // Decay products of this track
369  AliTrack* td; 
370  for (Int_t id=1; id<=GetNdecay(); id++)
371  {
372   td=GetDecayTrack(id);
373   if (td)
374   {
375    cout << "  ---Level 1 sec. track no. " << id << endl;
376    td->Data(f); 
377   }
378   else
379   {
380    cout << " *AliTrack::List* Error : Empty decay track slot." << endl; 
381   }
382  }
383
384 ///////////////////////////////////////////////////////////////////////////
385 void AliTrack::ListAll(TString f)
386 {
387 // Provide complete track and decay information within the coordinate frame f
388
389  Data(f); // Information of the current track
390  if (fBegin) { cout << " Begin-point :"; fBegin->Data(f); }
391  if (fEnd)   { cout << " End-point   :"; fEnd->Data(f); }
392  if (fRef)   { cout << " Ref-point   :"; fRef->Data(f); }
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)
407  {
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;
413   for (Int_t is=1; is<=nsig; is++)
414   {
415    AliSignal* sx=GetSignal(is);
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    }
428   }
429  }
430
431  AliTrack* t=this;
432  Dumps(t,1,f); // Information of all decay products
433 }
434 //////////////////////////////////////////////////////////////////////////
435 void AliTrack::Dumps(AliTrack* t,Int_t n,TString f)
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;
445    td->Data(f); 
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)
460    {
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     }
467    }
468
469    // Go for next decay level of this decay track recursively
470    Dumps(td,n+1,f);
471   }
472   else
473   {
474    cout << " *AliTrack::Dumps* Error : Empty decay track slot." << endl; 
475   }
476  }
477
478 //////////////////////////////////////////////////////////////////////////
479 Double_t AliTrack::GetMomentum()
480 {
481 // Provide the value of the track 3-momentum.
482 // The error can be obtained by invoking GetResultError() after
483 // invokation of GetMomentum().
484  Double_t norm=fV.GetNorm();
485  fDresult=fV.GetResultError();
486  return norm;
487 }
488 ///////////////////////////////////////////////////////////////////////////
489 Ali3Vector AliTrack::Get3Momentum() const
490 {
491 // Provide the track 3-momentum
492  return (Ali3Vector)Get3Vector();
493 }
494 ///////////////////////////////////////////////////////////////////////////
495 Double_t AliTrack::GetMass()
496 {
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  }
517 }
518 ///////////////////////////////////////////////////////////////////////////
519 Float_t AliTrack::GetCharge() const
520 {
521 // Provide the particle charge
522  return fQ;
523 }
524 ///////////////////////////////////////////////////////////////////////////
525 Double_t AliTrack::GetEnergy()
526 {
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  }
541 }
542 ///////////////////////////////////////////////////////////////////////////
543 void 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  
551  Double_t M=GetMass();
552  
553 // Compute the 4-momenta of the decay products in the cms
554 // Note : p2=p1=pnorm for a 2-body decay
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);
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);
578  pprim1.SetInvariant(m1*m1);
579
580  Ali4Vector pprim2;
581  p*=-1;
582  pprim2.SetVector(e2,p);
583  pprim2.SetInvariant(m2*m2);
584
585  // Determine boost parameters from the parent particle
586  Double_t E=GetEnergy();
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  {
600   delete fDecays;
601   fDecays=0;
602  }
603  fDecays=new TObjArray(2);
604  fDecays->SetOwner();
605
606  fDecays->Add(new AliTrack);
607  ((AliTrack*)fDecays->At(0))->Set4Momentum(p1);
608  ((AliTrack*)fDecays->At(0))->SetMass(m1);
609  fDecays->Add(new AliTrack);
610  ((AliTrack*)fDecays->At(1))->Set4Momentum(p2);
611  ((AliTrack*)fDecays->At(1))->SetMass(m2);
612 }
613 ///////////////////////////////////////////////////////////////////////////
614 Int_t AliTrack::GetNdecay() const
615 {
616 // Provide the number of decay produced tracks
617  Int_t ndec=0;
618  if (fDecays) ndec=fDecays->GetEntries();
619  return ndec;
620 }
621 ///////////////////////////////////////////////////////////////////////////
622 AliTrack* AliTrack::GetDecayTrack(Int_t j) const
623 {
624 // Provide decay produced track number j
625 // Note : j=1 denotes the first decay track
626  if (!fDecays)
627  {
628   cout << " *AliTrack::GetDecayTrack* No tracks present." << endl;
629   return 0;
630  }
631  else
632  {
633   if ((j >= 1) && (j <= GetNdecay()))
634   {
635    return (AliTrack*)fDecays->At(j-1);
636   }
637   else
638   {
639    cout << " *AliTrack* decay track number : " << j << " out of range."
640         << " Ndec = " << GetNdecay() << endl;
641    return 0;  
642   }
643  }
644 }
645 ///////////////////////////////////////////////////////////////////////////
646 void AliTrack::RemoveDecays()
647 {
648 // Remove all decay tracks from this track.
649  if (fDecays)
650  {
651   delete fDecays;
652   fDecays=0;
653  }
654 }
655 ///////////////////////////////////////////////////////////////////////////
656 void AliTrack::AddSignal(AliSignal& s)
657 {
658 // Relate an AliSignal object to this track.
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
668  fSignals->Add(&s);
669 }
670 ///////////////////////////////////////////////////////////////////////////
671 void AliTrack::RemoveSignal(AliSignal& s)
672 {
673 // Remove related AliSignal object from this track.
674  if (fSignals)
675  {
676   AliSignal* test=(AliSignal*)fSignals->Remove(&s);
677   if (test) fSignals->Compress();
678  }
679 }
680 ///////////////////////////////////////////////////////////////////////////
681 void 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;
689  }
690 }
691 ///////////////////////////////////////////////////////////////////////////
692 Int_t AliTrack::GetNsignals() const
693 {
694 // Provide the number of related AliSignals.
695  Int_t nsig=0;
696  if (fSignals) nsig=fSignals->GetEntries();
697  return nsig;
698 }
699 ///////////////////////////////////////////////////////////////////////////
700 AliSignal* AliTrack::GetSignal(Int_t j) const
701 {
702 // Provide the related AliSignal number j.
703 // Note : j=1 denotes the first signal.
704  if (!fSignals)
705  {
706   cout << " *AliTrack::GetSignal* No signals present." << endl;
707   return 0;
708  }
709  else
710  {
711   if ((j >= 1) && (j <= GetNsignals()))
712   {
713    return (AliSignal*)fSignals->At(j-1);
714   }
715   else
716   {
717    cout << " *AliTrack* signal number : " << j << " out of range."
718         << " Nsig = " << GetNsignals() << endl;
719    return 0;
720   }
721  }
722 }
723 ///////////////////////////////////////////////////////////////////////////
724 void AliTrack::AddTrackHypothesis(AliTrack& t)
725 {
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)
730  {
731   fHypotheses=new TObjArray(1);
732   fHypotheses->SetOwner();
733  }
734  fHypotheses->Add(t.Clone());
735 }
736 ///////////////////////////////////////////////////////////////////////////
737 void AliTrack::AddTrackHypothesis(Double_t prob,Double_t m,Double_t dm)
738 {
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);
756 }
757 ///////////////////////////////////////////////////////////////////////////
758 void AliTrack::RemoveTrackHypothesis(AliTrack& t)
759 {
760 // Remove the specified track hypothesis from this track.
761  if (fHypotheses)
762  {
763   AliTrack* test=(AliTrack*)fHypotheses->Remove(&t);
764   if (test) fHypotheses->Compress();
765  }
766 }
767 ///////////////////////////////////////////////////////////////////////////
768 void AliTrack::RemoveTrackHypotheses()
769 {
770 // Remove all track hypotheses from this track.
771  if (fHypotheses)
772  {
773   delete fHypotheses;
774   fHypotheses=0;
775  }
776 }
777 ///////////////////////////////////////////////////////////////////////////
778 Int_t AliTrack::GetNhypotheses() const
779 {
780 // Provide the number of track hypotheses.
781  Int_t nhyp=0;
782  if (fHypotheses) nhyp=fHypotheses->GetEntries();
783  return nhyp;
784 }
785 ///////////////////////////////////////////////////////////////////////////
786 AliTrack* AliTrack::GetTrackHypothesis(Int_t j) const
787 {
788 // Provide the j-th track hypothesis.
789 // Note : j=1 denotes the first hypothesis.
790 // Default : j=0 ==> Hypothesis with highest probability.
791
792  if (!fHypotheses) return 0;
793
794  Int_t nhyp=GetNhypotheses();
795
796  // Check validity of index j
797  if (j<0 || j>nhyp)
798  {
799    cout << " *AliTrack* hypothesis number : " << j << " out of range."
800         << " Nhyp = " << nhyp << endl;
801    return 0;
802  } 
803
804  AliTrack* t=0;
805
806  if (j==0) // Provide track hypothesis with highest probability
807  {
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++)
813   {
814    AliTrack* tx=(AliTrack*)fHypotheses->At(ih);
815    if (tx)
816    {
817     probx=tx->GetProb();
818     if (probx > prob) t=tx; 
819    }
820   }
821   return t;
822  }
823  else // Provide requested j-th track hypothesis
824  {
825   return (AliTrack*)fHypotheses->At(j-1);
826  }
827 }
828 ///////////////////////////////////////////////////////////////////////////
829 void AliTrack::SetBeginPoint(AliPosition& p)
830 {
831 // Store the position of the track begin-point.
832  if (!fBegin)
833  {
834   fBegin=new AliPositionObj(p);
835  }
836  else
837  {
838   fBegin->Load(p);
839  }
840 }
841 ///////////////////////////////////////////////////////////////////////////
842 AliPosition* AliTrack::GetBeginPoint()
843 {
844 // Provide the position of the track begin-point.
845  return fBegin;
846 }
847 ///////////////////////////////////////////////////////////////////////////
848 void AliTrack::SetEndPoint(AliPosition& p)
849 {
850 // Store the position of the track end-point.
851  if (!fEnd)
852  {
853   fEnd=new AliPositionObj(p);
854  }
855  else
856  {
857   fEnd->Load(p);
858  }
859 }
860 ///////////////////////////////////////////////////////////////////////////
861 AliPosition* AliTrack::GetEndPoint()
862 {
863 // Provide the position of the track end-point.
864  return fEnd;
865 }
866 ///////////////////////////////////////////////////////////////////////////
867 void 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 ///////////////////////////////////////////////////////////////////////////
884 AliPosition* 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 ///////////////////////////////////////////////////////////////////////////
894 void AliTrack::SetMass()
895 {
896 // Set the mass and error to the value of the hypothesis with highest prob.
897
898  Double_t m=0,dm=0;
899
900  // Select mass hypothesis with highest probability
901  AliTrack* t=GetTrackHypothesis(0);
902  if (t) 
903  {
904   m=t->GetMass();
905   dm=t->GetResultError();
906   SetMass(m,dm);
907  }
908  else
909  {
910   cout << " *AliTrack::SetMass()* No hypothesis present => No action." << endl;
911  }
912 }
913 ///////////////////////////////////////////////////////////////////////////
914 Double_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 ///////////////////////////////////////////////////////////////////////////
927 Double_t AliTrack::GetPl()
928 {
929 // Provide long. momentum value w.r.t. z-axis.
930 // Note : the returned value can also be negative.
931 // The error on the value can be obtained by GetResultError()
932 // after invokation of GetPl().
933  Ali3Vector v;
934  v=GetVecLong();
935
936  Double_t pl=v.GetNorm();
937  fDresult=v.GetResultError();
938
939  Double_t a[3];
940  v.GetVector(a,"sph");
941  if (cos(a[1])<0) pl=-pl;
942
943  return pl;
944 }
945 ///////////////////////////////////////////////////////////////////////////
946 Double_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 ///////////////////////////////////////////////////////////////////////////
956 Double_t AliTrack::GetEl()
957 {
958 // Provide long. energy value w.r.t. z-axis.
959 // Note : the returned value can also be negative.
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 ///////////////////////////////////////////////////////////////////////////
967 Double_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 ///////////////////////////////////////////////////////////////////////////
985 Double_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 ///////////////////////////////////////////////////////////////////////////
1008 void AliTrack::SetImpactPoint(AliPosition& p,TString q)
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
1022    if (!fImpactYZ)
1023    {
1024     fImpactYZ=new AliPositionObj(p);
1025    }
1026    else
1027    {
1028     fImpactYZ->Load(p);
1029    }
1030    break;
1031
1032   case 2: // Impact-point in the plane Y=0
1033    if (!fImpactXZ)
1034    {
1035     fImpactXZ=new AliPositionObj(p);
1036    }
1037    else
1038    {
1039     fImpactXZ->Load(p);
1040    }
1041    break;
1042
1043   case 3: // Impact-point in the plane Z=0
1044    if (!fImpactXY)
1045    {
1046     fImpactXY=new AliPositionObj(p);
1047    }
1048    else
1049    {
1050     fImpactXY->Load(p);
1051    }
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 ///////////////////////////////////////////////////////////////////////////
1061 AliPosition* AliTrack::GetImpactPoint(TString q)
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.
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; 
1086    return 0;
1087  }
1088 }
1089 ///////////////////////////////////////////////////////////////////////////
1090 void AliTrack::SetId(Int_t id)
1091 {
1092 // Set a user defined unique identifier for this track.
1093  fUserId=id;
1094 }
1095 ///////////////////////////////////////////////////////////////////////////
1096 Int_t AliTrack::GetId() const
1097 {
1098 // Provide the user defined unique identifier of this track.
1099  return fUserId;
1100 }
1101 ///////////////////////////////////////////////////////////////////////////
1102 void AliTrack::SetClosestPoint(AliPosition& p)
1103 {
1104 // Set position p as the point of closest approach w.r.t. some reference
1105  if (!fClosest)
1106  {
1107   fClosest=new AliPositionObj(p);
1108  }
1109  else
1110  {
1111   fClosest->Load(p);
1112  }
1113 }
1114 ///////////////////////////////////////////////////////////////////////////
1115 AliPosition* AliTrack::GetClosestPoint()
1116 {
1117 // Provide the point of closest approach w.r.t. some reference
1118  return fClosest;
1119 }
1120 ///////////////////////////////////////////////////////////////////////////
1121 void 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 ///////////////////////////////////////////////////////////////////////////
1134 void 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 ///////////////////////////////////////////////////////////////////////////
1147 Float_t AliTrack::GetChi2() const
1148 {
1149 // Provide the chi-squared value of the track fit.
1150  return fChi2;
1151 }
1152 ///////////////////////////////////////////////////////////////////////////
1153 Int_t AliTrack::GetNdf() const
1154 {
1155 // Provide the number of degrees of freedom for the track fit.
1156  return fNdf;
1157 }
1158 ///////////////////////////////////////////////////////////////////////////
1159 void AliTrack::SetParticleCode(Int_t code)
1160 {
1161 // Set the user defined particle id code (e.g. the PDF convention).
1162  fCode=code;
1163 }
1164 ///////////////////////////////////////////////////////////////////////////
1165 Int_t AliTrack::GetParticleCode() const
1166 {
1167 // Provide the user defined particle id code.
1168  return fCode;
1169 }
1170 ///////////////////////////////////////////////////////////////////////////
1171 void AliTrack::SetParentTrack(AliTrack* t)
1172 {
1173 // Set pointer to the parent track.
1174  fParent=t;
1175 }
1176 ///////////////////////////////////////////////////////////////////////////
1177 AliTrack* AliTrack::GetParentTrack()
1178 {
1179 // Provide pointer to the parent track.
1180  return fParent;
1181 }
1182 ///////////////////////////////////////////////////////////////////////////
1183 void AliTrack::SetProb(Double_t prob)
1184 {
1185 // Set hypothesis probability for this track.
1186  fProb=prob;
1187 }
1188 ///////////////////////////////////////////////////////////////////////////
1189 Float_t AliTrack::GetProb() const
1190 {
1191 // Provide the hypothesis probability for this track.
1192  return fProb;
1193 }
1194 ///////////////////////////////////////////////////////////////////////////
1195 TObject* AliTrack::Clone(const char* name) const
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 ///////////////////////////////////////////////////////////////////////////