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