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