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