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