]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliTrack.cxx
Added support for static libraries,
[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  fImpactXY=0;
114  fImpactXZ=0;
115  fImpactYZ=0;
116  fClosest=0;
117  fParent=0;
118 }
119 ///////////////////////////////////////////////////////////////////////////
120 AliTrack::~AliTrack()
121 {
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  
133  if (fDecays)
134  {
135   delete fDecays;
136   fDecays=0;
137  }
138  if (fSignals)
139  {
140   fSignals->Clear();
141   delete fSignals;
142   fSignals=0;
143  }
144  if (fHypotheses)
145  {
146   delete fHypotheses;
147   fHypotheses=0;
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  }
179 }
180 ///////////////////////////////////////////////////////////////////////////
181 AliTrack::AliTrack(AliTrack& t) : TNamed(t),Ali4Vector(t)
182 {
183 // Copy constructor
184  Init();
185
186  fQ=t.fQ;
187  fProb=t.fProb;
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;
198  fParent=t.fParent;
199
200  Int_t ndec=t.GetNdecay();
201  if (ndec)
202  {
203   fDecays=new TObjArray(ndec);
204   fDecays->SetOwner();
205   for (Int_t it=1; it<=ndec; it++)
206   {
207    AliTrack* tx=t.GetDecayTrack(it);
208    fDecays->Add(new AliTrack(*tx));
209   }
210  }
211
212  Int_t nsig=t.GetNsignals();
213  if (nsig)
214  {
215   fSignals=new TObjArray(nsig);
216   for (Int_t is=1; is<=nsig; is++)
217   {
218    AliSignal* sx=t.GetSignal(is);
219    fSignals->Add(sx);
220   }
221  }
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  }
234 }
235 ///////////////////////////////////////////////////////////////////////////
236 void AliTrack::Reset()
237 {
238 // Reset all variables to 0 and delete all auto-generated decay tracks.
239  fQ=0;
240  fChi2=0;
241  fNdf=0;
242  fUserId=0;
243  fCode=0;
244  fProb=0;
245  Double_t a[4]={0,0,0,0};
246  SetVector(a,"sph");
247  fParent=0;
248  if (fDecays)
249  {
250   delete fDecays;
251   fDecays=0;
252  }
253  if (fSignals)
254  {
255   fSignals->Clear();
256   delete fSignals;
257   fSignals=0;
258  }
259  if (fHypotheses)
260  {
261   delete fHypotheses;
262   fHypotheses=0;
263  }
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  }
294 }
295 ///////////////////////////////////////////////////////////////////////////
296 void AliTrack::Set3Momentum(Ali3Vector& p)
297 {
298 // Set the track parameters according to the 3-momentum p
299  Set3Vector(p);
300 }
301 ///////////////////////////////////////////////////////////////////////////
302 void AliTrack::Set4Momentum(Ali4Vector& p)
303 {
304 // Set the track parameters according to the 4-momentum p
305  Double_t E=p.GetScalar();
306  Double_t dE=p.GetResultError();
307  Ali3Vector pv=p.Get3Vector();
308  SetVector(E,pv);
309  SetScalarError(dE);
310 }
311 ///////////////////////////////////////////////////////////////////////////
312 void AliTrack::SetMass(Double_t m,Double_t dm)
313 {
314 // Set the particle mass
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);
319 }
320 ///////////////////////////////////////////////////////////////////////////
321 void AliTrack::SetCharge(Float_t q)
322 {
323 // Set the particle charge
324  fQ=q;
325 }
326 ///////////////////////////////////////////////////////////////////////////
327 void AliTrack::Data(TString f)
328 {
329 // Provide track information within the coordinate frame f
330  Double_t m=GetMass();
331  Double_t dm=GetResultError();
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;
344  Ali4Vector::Data(f); 
345
346 ///////////////////////////////////////////////////////////////////////////
347 void AliTrack::List(TString f)
348 {
349 // Provide current track and decay level 1 information within coordinate frame f
350
351  Data(f); // Information of the current track
352
353  // Decay products of this track
354  AliTrack* td; 
355  for (Int_t id=1; id<=GetNdecay(); id++)
356  {
357   td=GetDecayTrack(id);
358   if (td)
359   {
360    cout << "  ---Level 1 sec. track no. " << id << endl;
361    td->Data(f); 
362   }
363   else
364   {
365    cout << " *AliTrack::List* Error : Empty decay track slot." << endl; 
366   }
367  }
368
369 ///////////////////////////////////////////////////////////////////////////
370 void AliTrack::ListAll(TString f)
371 {
372 // Provide complete track and decay information within the coordinate frame f
373
374  Data(f); // Information of the current track
375  if (fBegin) { cout << " Begin-point :"; fBegin->Data(f); }
376  if (fEnd)   { cout << " End-point   :"; fEnd->Data(f); }
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)
391  {
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   }
398  }
399
400  AliTrack* t=this;
401  Dumps(t,1,f); // Information of all decay products
402 }
403 //////////////////////////////////////////////////////////////////////////
404 void AliTrack::Dumps(AliTrack* t,Int_t n,TString f)
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;
414    td->Data(f); 
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)
429    {
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     }
436    }
437
438    // Go for next decay level of this decay track recursively
439    Dumps(td,n+1,f);
440   }
441   else
442   {
443    cout << " *AliTrack::Dumps* Error : Empty decay track slot." << endl; 
444   }
445  }
446
447 //////////////////////////////////////////////////////////////////////////
448 Double_t AliTrack::GetMomentum()
449 {
450 // Provide the value of the track 3-momentum.
451 // The error can be obtained by invoking GetResultError() after
452 // invokation of GetMomentum().
453  Double_t norm=fV.GetNorm();
454  fDresult=fV.GetResultError();
455  return norm;
456 }
457 ///////////////////////////////////////////////////////////////////////////
458 Ali3Vector AliTrack::Get3Momentum()
459 {
460 // Provide the track 3-momentum
461  return (Ali3Vector)Get3Vector();
462 }
463 ///////////////////////////////////////////////////////////////////////////
464 Double_t AliTrack::GetMass()
465 {
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  }
486 }
487 ///////////////////////////////////////////////////////////////////////////
488 Float_t AliTrack::GetCharge()
489 {
490 // Provide the particle charge
491  return fQ;
492 }
493 ///////////////////////////////////////////////////////////////////////////
494 Double_t AliTrack::GetEnergy()
495 {
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  }
510 }
511 ///////////////////////////////////////////////////////////////////////////
512 void 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  
520  Double_t M=GetMass();
521  
522 // Compute the 4-momenta of the decay products in the cms
523 // Note : p2=p1=pnorm for a 2-body decay
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);
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);
547  pprim1.SetInvariant(m1*m1);
548
549  Ali4Vector pprim2;
550  p*=-1;
551  pprim2.SetVector(e2,p);
552  pprim2.SetInvariant(m2*m2);
553
554  // Determine boost parameters from the parent particle
555  Double_t E=GetEnergy();
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  {
569   delete fDecays;
570   fDecays=0;
571  }
572  fDecays=new TObjArray(2);
573  fDecays->SetOwner();
574
575  fDecays->Add(new AliTrack);
576  ((AliTrack*)fDecays->At(0))->Set4Momentum(p1);
577  ((AliTrack*)fDecays->At(0))->SetMass(m1);
578  fDecays->Add(new AliTrack);
579  ((AliTrack*)fDecays->At(1))->Set4Momentum(p2);
580  ((AliTrack*)fDecays->At(1))->SetMass(m2);
581 }
582 ///////////////////////////////////////////////////////////////////////////
583 Int_t AliTrack::GetNdecay()
584 {
585 // Provide the number of decay produced tracks
586  Int_t ndec=0;
587  if (fDecays) ndec=fDecays->GetEntries();
588  return ndec;
589 }
590 ///////////////////////////////////////////////////////////////////////////
591 AliTrack* AliTrack::GetDecayTrack(Int_t j)
592 {
593 // Provide decay produced track number j
594 // Note : j=1 denotes the first decay track
595  if (!fDecays)
596  {
597   cout << " *AliTrack::GetDecayTrack* No tracks present." << endl;
598   return 0;
599  }
600  else
601  {
602   if ((j >= 1) && (j <= GetNdecay()))
603   {
604    return (AliTrack*)fDecays->At(j-1);
605   }
606   else
607   {
608    cout << " *AliTrack* decay track number : " << j << " out of range."
609         << " Ndec = " << GetNdecay() << endl;
610    return 0;  
611   }
612  }
613 }
614 ///////////////////////////////////////////////////////////////////////////
615 void AliTrack::RemoveDecays()
616 {
617 // Remove all decay tracks from this track.
618  if (fDecays)
619  {
620   delete fDecays;
621   fDecays=0;
622  }
623 }
624 ///////////////////////////////////////////////////////////////////////////
625 void AliTrack::AddSignal(AliSignal& s)
626 {
627 // Relate an AliSignal object to this track.
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
637  fSignals->Add(&s);
638 }
639 ///////////////////////////////////////////////////////////////////////////
640 void AliTrack::RemoveSignal(AliSignal& s)
641 {
642 // Remove related AliSignal object from this track.
643  if (fSignals)
644  {
645   AliSignal* test=(AliSignal*)fSignals->Remove(&s);
646   if (test) fSignals->Compress();
647  }
648 }
649 ///////////////////////////////////////////////////////////////////////////
650 void 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;
658  }
659 }
660 ///////////////////////////////////////////////////////////////////////////
661 Int_t AliTrack::GetNsignals()
662 {
663 // Provide the number of related AliSignals.
664  Int_t nsig=0;
665  if (fSignals) nsig=fSignals->GetEntries();
666  return nsig;
667 }
668 ///////////////////////////////////////////////////////////////////////////
669 AliSignal* AliTrack::GetSignal(Int_t j)
670 {
671 // Provide the related AliSignal number j.
672 // Note : j=1 denotes the first signal.
673  if (!fSignals)
674  {
675   cout << " *AliTrack::GetSignal* No signals present." << endl;
676   return 0;
677  }
678  else
679  {
680   if ((j >= 1) && (j <= GetNsignals()))
681   {
682    return (AliSignal*)fSignals->At(j-1);
683   }
684   else
685   {
686    cout << " *AliTrack* signal number : " << j << " out of range."
687         << " Nsig = " << GetNsignals() << endl;
688    return 0;
689   }
690  }
691 }
692 ///////////////////////////////////////////////////////////////////////////
693 void AliTrack::AddTrackHypothesis(AliTrack& t)
694 {
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)
699  {
700   fHypotheses=new TObjArray(1);
701   fHypotheses->SetOwner();
702  }
703  fHypotheses->Add(t.Clone());
704 }
705 ///////////////////////////////////////////////////////////////////////////
706 void AliTrack::AddTrackHypothesis(Double_t prob,Double_t m,Double_t dm)
707 {
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);
725 }
726 ///////////////////////////////////////////////////////////////////////////
727 void AliTrack::RemoveTrackHypothesis(AliTrack& t)
728 {
729 // Remove the specified track hypothesis from this track.
730  if (fHypotheses)
731  {
732   AliTrack* test=(AliTrack*)fHypotheses->Remove(&t);
733   if (test) fHypotheses->Compress();
734  }
735 }
736 ///////////////////////////////////////////////////////////////////////////
737 void AliTrack::RemoveTrackHypotheses()
738 {
739 // Remove all track hypotheses from this track.
740  if (fHypotheses)
741  {
742   delete fHypotheses;
743   fHypotheses=0;
744  }
745 }
746 ///////////////////////////////////////////////////////////////////////////
747 Int_t AliTrack::GetNhypotheses()
748 {
749 // Provide the number of track hypotheses.
750  Int_t nhyp=0;
751  if (fHypotheses) nhyp=fHypotheses->GetEntries();
752  return nhyp;
753 }
754 ///////////////////////////////////////////////////////////////////////////
755 AliTrack* AliTrack::GetTrackHypothesis(Int_t j)
756 {
757 // Provide the j-th track hypothesis.
758 // Note : j=1 denotes the first hypothesis.
759 // Default : j=0 ==> Hypothesis with highest probability.
760
761  if (!fHypotheses) return 0;
762
763  Int_t nhyp=GetNhypotheses();
764
765  // Check validity of index j
766  if (j<0 || j>nhyp)
767  {
768    cout << " *AliTrack* hypothesis number : " << j << " out of range."
769         << " Nhyp = " << nhyp << endl;
770    return 0;
771  } 
772
773  AliTrack* t=0;
774
775  if (j==0) // Provide track hypothesis with highest probability
776  {
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++)
782   {
783    AliTrack* tx=(AliTrack*)fHypotheses->At(ih);
784    if (tx)
785    {
786     probx=tx->GetProb();
787     if (probx > prob) t=tx; 
788    }
789   }
790   return t;
791  }
792  else // Provide requested j-th track hypothesis
793  {
794   return (AliTrack*)fHypotheses->At(j-1);
795  }
796 }
797 ///////////////////////////////////////////////////////////////////////////
798 void AliTrack::SetBeginPoint(AliPosition& p)
799 {
800 // Store the position of the track begin-point.
801  if (!fBegin)
802  {
803   fBegin=new AliPositionObj(p);
804  }
805  else
806  {
807   fBegin->Load(p);
808  }
809 }
810 ///////////////////////////////////////////////////////////////////////////
811 AliPosition* AliTrack::GetBeginPoint()
812 {
813 // Provide the position of the track begin-point.
814  return fBegin;
815 }
816 ///////////////////////////////////////////////////////////////////////////
817 void AliTrack::SetEndPoint(AliPosition& p)
818 {
819 // Store the position of the track end-point.
820  if (!fEnd)
821  {
822   fEnd=new AliPositionObj(p);
823  }
824  else
825  {
826   fEnd->Load(p);
827  }
828 }
829 ///////////////////////////////////////////////////////////////////////////
830 AliPosition* AliTrack::GetEndPoint()
831 {
832 // Provide the position of the track end-point.
833  return fEnd;
834 }
835 ///////////////////////////////////////////////////////////////////////////
836 void AliTrack::SetMass()
837 {
838 // Set the mass and error to the value of the hypothesis with highest prob.
839
840  Double_t m=0,dm=0;
841
842  // Select mass hypothesis with highest probability
843  AliTrack* t=GetTrackHypothesis(0);
844  if (t) 
845  {
846   m=t->GetMass();
847   dm=t->GetResultError();
848   SetMass(m,dm);
849  }
850  else
851  {
852   cout << " *AliTrack::SetMass()* No hypothesis present => No action." << endl;
853  }
854 }
855 ///////////////////////////////////////////////////////////////////////////
856 Double_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 ///////////////////////////////////////////////////////////////////////////
869 Double_t AliTrack::GetPl()
870 {
871 // Provide long. momentum value w.r.t. z-axis.
872 // Note : the returned value can also be negative.
873 // The error on the value can be obtained by GetResultError()
874 // after invokation of GetPl().
875  Ali3Vector v;
876  v=GetVecLong();
877
878  Double_t pl=v.GetNorm();
879  fDresult=v.GetResultError();
880
881  Double_t a[3];
882  v.GetVector(a,"sph");
883  if (cos(a[1])<0) pl=-pl;
884
885  return pl;
886 }
887 ///////////////////////////////////////////////////////////////////////////
888 Double_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 ///////////////////////////////////////////////////////////////////////////
898 Double_t AliTrack::GetEl()
899 {
900 // Provide long. energy value w.r.t. z-axis.
901 // Note : the returned value can also be negative.
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 ///////////////////////////////////////////////////////////////////////////
909 Double_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 ///////////////////////////////////////////////////////////////////////////
927 Double_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 ///////////////////////////////////////////////////////////////////////////
950 void AliTrack::SetImpactPoint(AliPosition& p,TString q)
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
964    if (!fImpactYZ)
965    {
966     fImpactYZ=new AliPositionObj(p);
967    }
968    else
969    {
970     fImpactYZ->Load(p);
971    }
972    break;
973
974   case 2: // Impact-point in the plane Y=0
975    if (!fImpactXZ)
976    {
977     fImpactXZ=new AliPositionObj(p);
978    }
979    else
980    {
981     fImpactXZ->Load(p);
982    }
983    break;
984
985   case 3: // Impact-point in the plane Z=0
986    if (!fImpactXY)
987    {
988     fImpactXY=new AliPositionObj(p);
989    }
990    else
991    {
992     fImpactXY->Load(p);
993    }
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 ///////////////////////////////////////////////////////////////////////////
1003 AliPosition* AliTrack::GetImpactPoint(TString q)
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.
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; 
1028    return 0;
1029  }
1030 }
1031 ///////////////////////////////////////////////////////////////////////////
1032 void AliTrack::SetId(Int_t id)
1033 {
1034 // Set a user defined unique identifier for this track.
1035  fUserId=id;
1036 }
1037 ///////////////////////////////////////////////////////////////////////////
1038 Int_t AliTrack::GetId()
1039 {
1040 // Provide the user defined unique identifier of this track.
1041  return fUserId;
1042 }
1043 ///////////////////////////////////////////////////////////////////////////
1044 void AliTrack::SetClosestPoint(AliPosition& p)
1045 {
1046 // Set position p as the point of closest approach w.r.t. some reference
1047  if (!fClosest)
1048  {
1049   fClosest=new AliPositionObj(p);
1050  }
1051  else
1052  {
1053   fClosest->Load(p);
1054  }
1055 }
1056 ///////////////////////////////////////////////////////////////////////////
1057 AliPosition* AliTrack::GetClosestPoint()
1058 {
1059 // Provide the point of closest approach w.r.t. some reference
1060  return fClosest;
1061 }
1062 ///////////////////////////////////////////////////////////////////////////
1063 void 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 ///////////////////////////////////////////////////////////////////////////
1076 void 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 ///////////////////////////////////////////////////////////////////////////
1089 Float_t AliTrack::GetChi2()
1090 {
1091 // Provide the chi-squared value of the track fit.
1092  return fChi2;
1093 }
1094 ///////////////////////////////////////////////////////////////////////////
1095 Int_t AliTrack::GetNdf()
1096 {
1097 // Provide the number of degrees of freedom for the track fit.
1098  return fNdf;
1099 }
1100 ///////////////////////////////////////////////////////////////////////////
1101 void AliTrack::SetParticleCode(Int_t code)
1102 {
1103 // Set the user defined particle id code (e.g. the PDF convention).
1104  fCode=code;
1105 }
1106 ///////////////////////////////////////////////////////////////////////////
1107 Int_t AliTrack::GetParticleCode()
1108 {
1109 // Provide the user defined particle id code.
1110  return fCode;
1111 }
1112 ///////////////////////////////////////////////////////////////////////////
1113 void AliTrack::SetParentTrack(AliTrack* t)
1114 {
1115 // Set pointer to the parent track.
1116  fParent=t;
1117 }
1118 ///////////////////////////////////////////////////////////////////////////
1119 AliTrack* AliTrack::GetParentTrack()
1120 {
1121 // Provide pointer to the parent track.
1122  return fParent;
1123 }
1124 ///////////////////////////////////////////////////////////////////////////
1125 void AliTrack::SetProb(Double_t prob)
1126 {
1127 // Set hypothesis probability for this track.
1128  fProb=prob;
1129 }
1130 ///////////////////////////////////////////////////////////////////////////
1131 Float_t AliTrack::GetProb()
1132 {
1133 // Provide the hypothesis probability for this track.
1134  return fProb;
1135 }
1136 ///////////////////////////////////////////////////////////////////////////
1137 TObject* AliTrack::Clone(const char* name)
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 ///////////////////////////////////////////////////////////////////////////