1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Handling of the attributes of a reconstructed particle track.
25 // Float_t a[4]={195.,1.2,-0.04,8.5};
27 // pmu.SetVector(a,"car");
29 // t1.Set4Momentum(pmu);
31 // Float_t b[3]={1.2,-0.04,8.5};
33 // p.SetVector(b,"car");
35 // t2.Set3Momentum(p);
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
47 // t2.Decay(m1,m2,thcms,phicms); // Track t2 decay : Lambda -> proton + pion
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
55 // AliSignal s1,s2,s3,s4;
57 // .... // Code (e.g. detector readout) to fill AliSignal data
59 // AliTrack trec; // Track which will be reconstructed from signals
60 // trec.AddSignal(s1);
61 // trec.AddSignal(s3);
62 // trec.AddSignal(s4);
67 // ... // Code which accesses signals from trec and reconstructs
68 // 3-momentum P, charge Q, mass M etc...
70 // trec.Set3Momentum(P);
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);
86 // Note : All quantities are in GeV, GeV/c or GeV/c**2
88 //--- Author: Nick van Eijndhoven 10-jul-1997 UU-SAP Utrecht
89 //- Modified: NvE $Date$ UU-SAP Utrecht
90 ///////////////////////////////////////////////////////////////////////////
94 ClassImp(AliTrack) // Class implementation to enable ROOT I/O
98 // Default constructor
99 // All variables initialised to 0
107 ///////////////////////////////////////////////////////////////////////////
108 AliTrack::~AliTrack()
110 // Destructor to delete memory allocated for decay tracks array
124 ///////////////////////////////////////////////////////////////////////////
125 void AliTrack::Reset()
127 // Reset all variables to 0 and delete all auto-generated decay tracks.
135 Double_t a[4]={0,0,0,0};
149 Double_t b[3]={0,0,0};
150 fBegin.SetPosition(b,"sph");
151 fEnd.SetPosition(b,"sph");
152 fImpactXY.SetPosition(b,"sph");
153 fImpactXZ.SetPosition(b,"sph");
154 fImpactYZ.SetPosition(b,"sph");
155 fClosest.SetPosition(b,"sph");
172 ///////////////////////////////////////////////////////////////////////////
173 void AliTrack::Set3Momentum(Ali3Vector& p)
175 // Set the track parameters according to the 3-momentum p
178 ///////////////////////////////////////////////////////////////////////////
179 void AliTrack::Set4Momentum(Ali4Vector& p)
181 // Set the track parameters according to the 4-momentum p
182 Double_t E=p.GetScalar();
183 Double_t dE=p.GetResultError();
184 Ali3Vector pv=p.Get3Vector();
188 ///////////////////////////////////////////////////////////////////////////
189 void AliTrack::SetMass(Double_t m,Double_t dm)
191 // Set the particle mass
192 // The default value for the error dm is 0.
193 Double_t inv=pow(m,2);
194 Double_t dinv=fabs(2.*m*dm);
195 SetInvariant(inv,dinv);
197 ///////////////////////////////////////////////////////////////////////////
198 void AliTrack::SetCharge(Float_t q)
200 // Set the particle charge
203 ///////////////////////////////////////////////////////////////////////////
204 void AliTrack::Info(TString f)
206 // Provide track information within the coordinate frame f
207 Double_t m=GetMass();
208 Double_t dm=GetResultError();
209 cout << " *AliTrack::Info* Id : " << fUserId << " Mass : " << m
210 << " error : " << dm << " Charge : " << fQ
211 << " Momentum : " << GetMomentum() << " Nmass hyp. : " << fNmasses
212 << " Ntracks : " << fNdec << " Nsignals : " << fNsig << endl;
213 for (Int_t i=0; i<fNmasses; i++)
215 cout << " Mass hypothesis " << (i+1) << " Mass : " << fMasses->At(i)
216 << " error : " << fDmasses->At(i) << " prob. : " << fPmasses->At(i)
221 ///////////////////////////////////////////////////////////////////////////
222 void AliTrack::List(TString f)
224 // Provide current track and decay level 1 information within coordinate frame f
226 Info(f); // Information of the current track
228 // Decay products of this track
230 for (Int_t id=1; id<=fNdec; id++)
232 td=GetDecayTrack(id);
235 cout << " ---Level 1 sec. track no. " << id << endl;
240 cout << " *AliTrack::List* Error : No decay track present." << endl;
244 ///////////////////////////////////////////////////////////////////////////
245 void AliTrack::ListAll(TString f)
247 // Provide complete track and decay information within the coordinate frame f
249 Info(f); // Information of the current track
250 cout << " Begin-point :"; fBegin.Info(f);
251 cout << " End-point :"; fEnd.Info(f);
252 for (Int_t is=1; is<=GetNsignals(); is++)
254 ((AliSignal*)GetSignal(is))->Info(f);
258 Dump(t,1,f); // Information of all decay products
260 //////////////////////////////////////////////////////////////////////////
261 void AliTrack::Dump(AliTrack* t,Int_t n,TString f)
263 // Recursively provide the info of all decay levels of this track
265 for (Int_t id=1; id<=t->GetNdecay(); id++)
267 td=t->GetDecayTrack(id);
270 cout << " ---Level " << n << " sec. track no. " << id << endl;
272 for (Int_t is=1; is<=td->GetNsignals(); is++)
274 ((AliSignal*)td->GetSignal(is))->Info(f);
277 // Go for next decay level of this decay track recursively
282 cout << " *AliTrack::Dump* Error : No decay track present." << endl;
286 //////////////////////////////////////////////////////////////////////////
287 Double_t AliTrack::GetMomentum()
289 // Provide the value of the track 3-momentum.
290 // The error can be obtained by invoking GetResultError() after
291 // invokation of GetMomentum().
292 Double_t norm=fV.GetNorm();
293 fDresult=fV.GetResultError();
296 ///////////////////////////////////////////////////////////////////////////
297 Ali3Vector AliTrack::Get3Momentum()
299 // Provide the track 3-momentum
300 return (Ali3Vector)Get3Vector();
302 ///////////////////////////////////////////////////////////////////////////
303 Double_t AliTrack::GetMass()
305 // Provide the particle mass.
306 // The error can be obtained by invoking GetResultError() after
307 // invokation of GetMass().
308 Double_t inv=GetInvariant();
309 Double_t dinv=GetResultError();
313 Double_t m=sqrt(inv);
314 if (m) dm=dinv/(2.*m);
320 cout << "*AliTrack::GetMass* Unphysical situation m**2 = " << inv << endl;
321 cout << " Value 0 will be returned." << endl;
326 ///////////////////////////////////////////////////////////////////////////
327 Float_t AliTrack::GetCharge()
329 // Provide the particle charge
332 ///////////////////////////////////////////////////////////////////////////
333 Double_t AliTrack::GetEnergy()
335 // Provide the particle's energy.
336 // The error can be obtained by invoking GetResultError() after
337 // invokation of GetEnergy().
338 Double_t E=GetScalar();
345 cout << "*AliTrack::GetEnergy* Unphysical situation E = " << E << endl;
346 cout << " Value 0 will be returned." << endl;
350 ///////////////////////////////////////////////////////////////////////////
351 void AliTrack::Decay(Double_t m1,Double_t m2,Double_t thcms,Double_t phicms)
353 // Perform 2-body decay of current track
354 // m1 : mass of decay product 1
355 // m2 : mass of decay product 2
356 // thcms : cms theta decay angle (in rad.) of m1
357 // phicms : cms phi decay angle (in rad.) of m1
359 fNdec=2; // it's a 2-body decay
361 Double_t M=GetMass();
363 // Compute the 4-momenta of the decay products in the cms
364 // Note : p2=p1=pnorm for a 2-body decay
366 if (M) e1=((M*M)+(m1*m1)-(m2*m2))/(2.*M);
368 if (M) e2=((M*M)+(m2*m2)-(m1*m1))/(2.*M);
369 Double_t pnorm=(e1*e1)-(m1*m1);
384 p.SetVector(a,"sph");
387 pprim1.SetVector(e1,p);
388 pprim1.SetInvariant(m1*m1);
392 pprim2.SetVector(e2,p);
393 pprim2.SetInvariant(m2*m2);
395 // Determine boost parameters from the parent particle
396 Double_t E=GetEnergy();
404 Ali4Vector p1=q.Inverse(pprim1); // Boost decay product 1
405 Ali4Vector p2=q.Inverse(pprim2); // Boost decay product 2
407 // Enter the boosted data into the decay tracks array
413 fDecays=new TObjArray();
415 fDecays->Add(new AliTrack);
416 ((AliTrack*)fDecays->At(0))->Set4Momentum(p1);
417 ((AliTrack*)fDecays->At(0))->SetMass(m1);
418 fDecays->Add(new AliTrack);
419 ((AliTrack*)fDecays->At(1))->Set4Momentum(p2);
420 ((AliTrack*)fDecays->At(1))->SetMass(m2);
422 ///////////////////////////////////////////////////////////////////////////
423 Int_t AliTrack::GetNdecay()
425 // Provide the number of decay produced tracks
428 ///////////////////////////////////////////////////////////////////////////
429 AliTrack* AliTrack::GetDecayTrack(Int_t j)
431 // Provide decay produced track number j
432 // Note : j=1 denotes the first decay track
433 if ((j >= 1) && (j <= fNdec))
435 return (AliTrack*)fDecays->At(j-1);
439 cout << " *AliTrack* decay track number : " << j << " out of range." << endl;
440 cout << " -- Decay track number 1 (if any) returned." << endl;
441 return (AliTrack*)fDecays->At(0);
444 ///////////////////////////////////////////////////////////////////////////
445 void AliTrack::AddSignal(AliSignal& s)
447 // Relate an AliSignal object to this track.
448 if (!fSignals) fSignals=new TObjArray();
452 ///////////////////////////////////////////////////////////////////////////
453 void AliTrack::RemoveSignal(AliSignal& s)
455 // Remove related AliSignal object to this track.
458 AliSignal* test=(AliSignal*)fSignals->Remove(&s);
462 fSignals->Compress();
466 ///////////////////////////////////////////////////////////////////////////
467 Int_t AliTrack::GetNsignals()
469 // Provide the number of related AliSignals.
472 ///////////////////////////////////////////////////////////////////////////
473 AliSignal* AliTrack::GetSignal(Int_t j)
475 // Provide the related AliSignal number j.
476 // Note : j=1 denotes the first signal.
477 if ((j >= 1) && (j <= fNsig))
479 return (AliSignal*)fSignals->At(j-1);
483 cout << " *AliTrack* signal number : " << j << " out of range." << endl;
484 cout << " -- Signal number 1 (if any) returned." << endl;
485 return (AliSignal*)fDecays->At(0);
488 ///////////////////////////////////////////////////////////////////////////
489 void AliTrack::SetBeginPoint(AliPosition p)
491 // Store the position of the track begin-point.
494 ///////////////////////////////////////////////////////////////////////////
495 AliPosition AliTrack::GetBeginPoint()
497 // Provide the position of the track begin-point.
500 ///////////////////////////////////////////////////////////////////////////
501 void AliTrack::SetEndPoint(AliPosition p)
503 // Store the position of the track end-point.
506 ///////////////////////////////////////////////////////////////////////////
507 AliPosition AliTrack::GetEndPoint()
509 // Provide the position of the track end-point.
512 ///////////////////////////////////////////////////////////////////////////
513 void AliTrack::AddMassHypothesis(Double_t prob,Double_t m,Double_t dm)
515 // Add a mass hypothesis for this current track.
516 // prob=probalility m=mass value dm=error on the mass value.
517 // The default value for the mass error dm is 0.
518 if (!fMasses) fMasses=new TArrayD();
519 if (!fDmasses) fDmasses=new TArrayD();
520 if (!fPmasses) fPmasses=new TArrayD();
523 fMasses->Set(fNmasses);
524 fDmasses->Set(fNmasses);
525 fPmasses->Set(fNmasses);
527 fMasses->AddAt(m,fNmasses-1);
528 fDmasses->AddAt(dm,fNmasses-1);
529 fPmasses->AddAt(prob,fNmasses-1);
531 ///////////////////////////////////////////////////////////////////////////
532 Int_t AliTrack::GetNMassHypotheses()
534 // Provide the number of mass hypotheses for this track.
537 ///////////////////////////////////////////////////////////////////////////
538 Double_t AliTrack::GetMassHypothesis(Int_t j)
540 // Provide the mass of the jth hypothesis for this track.
541 // Note : the first hypothesis is indicated by j=1.
542 // Default : j=0 ==> Hypothesis with highest probability.
543 // The error on the mass can be obtained by invoking GetResultError()
544 // after invokation of GetMassHypothesis(j).
546 Double_t m=0,dm=0,prob=0;
548 // Check validity of index j
549 if (j<0 || j>fNmasses)
551 cout << " *AliTrack::GetMassHypothesis* Invalid index j : " << j
552 << " Number of mass hypotheses : " << fNmasses << endl;
557 // Select mass hypothesis with highest probability
564 prob=fPmasses->At(0);
565 for (Int_t i=1; i<fNmasses; i++)
567 if (fPmasses->At(i)>prob)
578 // Provide data of requested mass hypothesis
580 fDresult=fDmasses->At(j-1);
583 ///////////////////////////////////////////////////////////////////////////
584 Double_t AliTrack::GetMassHypothesisProb(Int_t j)
586 // Provide the probability of the jth hypothesis for this track.
587 // Note : the first hypothesis is indicated by j=1.
588 // Default : j=0 ==> Hypothesis with highest probability.
592 // Check validity of index j
593 if (j<0 || j>fNmasses)
595 cout << " *AliTrack::GetMassHypothesisProb* Invalid index j : " << j
596 << " Number of mass hypotheses : " << fNmasses << endl;
600 // Select mass hypothesis with highest probability
605 prob=fPmasses->At(0);
606 for (Int_t i=1; i<fNmasses; i++)
608 if (fPmasses->At(i)>prob) prob=fPmasses->At(i);
614 // Provide probability of requested mass hypothesis
615 prob=fPmasses->At(j-1);
618 ///////////////////////////////////////////////////////////////////////////
619 void AliTrack::SetMass()
621 // Set the mass and error to the value of the hypothesis with highest prob.
623 Double_t m=0,dm=0,prob=0;
625 // Select mass hypothesis with highest probability
630 prob=fPmasses->At(0);
631 for (Int_t i=1; i<fNmasses; i++)
633 if (fPmasses->At(i)>prob)
643 cout << " *AliTrack::SetMass()* No hypothesis present => No action." << endl;
646 ///////////////////////////////////////////////////////////////////////////
647 void AliTrack::RemoveMassHypothesis(Int_t j)
649 // Remove the jth mass hypothesis for this track.
650 // Note : the first hypothesis is indicated by j=1.
652 if (j<=0 || j>fNmasses) // Check validity of index j
654 cout << " *AliTrack::RemoveMassHypothesis* Invalid index j : " << j
655 << " Number of mass hypotheses : " << fNmasses << endl;
661 fMasses->AddAt(fMasses->At(fNmasses-1),j-1);
662 fDmasses->AddAt(fDmasses->At(fNmasses-1),j-1);
663 fPmasses->AddAt(fPmasses->At(fNmasses-1),j-1);
665 fMasses->AddAt(0,fNmasses-1);
666 fDmasses->AddAt(0,fNmasses-1);
667 fPmasses->AddAt(0,fNmasses-1);
669 fMasses->Set(fNmasses);
670 fDmasses->Set(fNmasses);
671 fPmasses->Set(fNmasses);
674 ///////////////////////////////////////////////////////////////////////////
675 Double_t AliTrack::GetPt()
677 // Provide trans. momentum value w.r.t. z-axis.
678 // The error on the value can be obtained by GetResultError()
679 // after invokation of GetPt().
682 Double_t norm=v.GetNorm();
683 fDresult=v.GetResultError();
687 ///////////////////////////////////////////////////////////////////////////
688 Double_t AliTrack::GetPl()
690 // Provide long. momentum value w.r.t. z-axis.
691 // Note : the returned value can also be negative.
692 // The error on the value can be obtained by GetResultError()
693 // after invokation of GetPl().
697 Double_t pl=v.GetNorm();
698 fDresult=v.GetResultError();
701 v.GetVector(a,"sph");
702 if (cos(a[1])<0) pl=-pl;
706 ///////////////////////////////////////////////////////////////////////////
707 Double_t AliTrack::GetEt()
709 // Provide trans. energy value w.r.t. z-axis.
710 // The error on the value can be obtained by GetResultError()
711 // after invokation of GetEt().
712 Double_t et=GetScaTrans();
716 ///////////////////////////////////////////////////////////////////////////
717 Double_t AliTrack::GetEl()
719 // Provide long. energy value w.r.t. z-axis.
720 // Note : the returned value can also be negative.
721 // The error on the value can be obtained by GetResultError()
722 // after invokation of GetEl().
723 Double_t el=GetScaLong();
727 ///////////////////////////////////////////////////////////////////////////
728 Double_t AliTrack::GetMt()
730 // Provide transverse mass value w.r.t. z-axis.
731 // The error on the value can be obtained by GetResultError()
732 // after invokation of GetMt().
734 Double_t dpt=GetResultError();
735 Double_t m=GetMass();
736 Double_t dm=GetResultError();
738 Double_t mt=sqrt(pt*pt+m*m);
740 if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
745 ///////////////////////////////////////////////////////////////////////////
746 Double_t AliTrack::GetMt(Int_t j)
748 // Provide transverse mass value w.r.t. z-axis and jth mass hypothesis.
749 // Note : the first hypothesis is indicated by j=1.
750 // j=0 ==> Hypothesis with highest probability.
751 // The error on the value can be obtained by GetResultError()
752 // after invokation of GetMt(j).
754 Double_t dpt=GetResultError();
755 Double_t m=GetMassHypothesis(j);
756 Double_t dm=GetResultError();
758 Double_t mt=sqrt(pt*pt+m*m);
760 if (mt) dmt2=(pow((pt*dpt),2)+pow((m*dm),2))/(mt*mt);
765 ///////////////////////////////////////////////////////////////////////////
766 Double_t AliTrack::GetRapidity()
768 // Provide rapidity value w.r.t. z-axis.
769 // The error on the value can be obtained by GetResultError()
770 // after invokation of GetRapidity().
771 // Note : Also GetPseudoRapidity() is available since this class is
772 // derived from Ali4Vector.
773 Double_t e=GetEnergy();
774 Double_t de=GetResultError();
776 Double_t dpl=GetResultError();
780 Double_t y=9999,dy2=0;
781 if (sum && dif) y=0.5*log(sum/dif);
783 if (sum*dif) dy2=(1./(sum*dif))*(pow((pl*de),2)+pow((e*dpl),2));
788 ///////////////////////////////////////////////////////////////////////////
789 void AliTrack::SetImpactPoint(AliPosition p,TString q)
791 // Store the position of the impact-point in the plane "q=0".
792 // Here q denotes one of the axes X, Y or Z.
793 // Note : The character to denote the axis may be entered in lower or
796 if (q=="x" || q=="X") axis=1;
797 if (q=="y" || q=="Y") axis=2;
798 if (q=="z" || q=="Z") axis=3;
802 case 1: // Impact-point in the plane X=0
806 case 2: // Impact-point in the plane Y=0
810 case 3: // Impact-point in the plane Z=0
814 default: // Unsupported axis
815 cout << "*AliTrack::SetImpactPoint* Unsupported axis : " << q << endl
816 << " Possible axes are 'X', 'Y' and 'Z'." << endl;
820 ///////////////////////////////////////////////////////////////////////////
821 AliPosition AliTrack::GetImpactPoint(TString q)
823 // Provide the position of the impact-point in the plane "q=0".
824 // Here q denotes one of the axes X, Y or Z.
825 // Note : The character to denote the axis may be entered in lower or
829 if (q=="x" || q=="X") axis=1;
830 if (q=="y" || q=="Y") axis=2;
831 if (q=="z" || q=="Z") axis=3;
835 case 1: // Impact-point in the plane X=0
838 case 2: // Impact-point in the plane Y=0
841 case 3: // Impact-point in the plane Z=0
844 default: // Unsupported axis
845 cout << "*AliTrack::GetImpactPoint* Unsupported axis : " << q << endl
846 << " Possible axes are 'X', 'Y' and 'Z'." << endl;
850 ///////////////////////////////////////////////////////////////////////////
851 void AliTrack::SetId(Int_t id)
853 // Set a user defined identifier for this track.
856 ///////////////////////////////////////////////////////////////////////////
857 Int_t AliTrack::GetId()
859 // Provide the user defined identifier of this track.
862 ///////////////////////////////////////////////////////////////////////////
863 void AliTrack::SetClosestPoint(AliPosition p)
865 // Set position p as the point of closest approach w.r.t. some reference
868 ///////////////////////////////////////////////////////////////////////////
869 AliPosition AliTrack::GetClosestPoint()
871 // Provide the point of closest approach w.r.t. some reference
874 ///////////////////////////////////////////////////////////////////////////
875 void AliTrack::SetChi2(Float_t chi2)
877 // Set the chi-squared value of the track fit.
880 cout << " *AliTrack::SetChi2* Invalid chi2 value : " << chi2 << endl;
887 ///////////////////////////////////////////////////////////////////////////
888 void AliTrack::SetNdf(Int_t ndf)
890 // Set the number of degrees of freedom for the track fit.
893 cout << " *AliTrack::SetNdf* Invalid ndf value : " << ndf << endl;
900 ///////////////////////////////////////////////////////////////////////////
901 Float_t AliTrack::GetChi2()
903 // Provide the chi-squared value of the track fit.
906 ///////////////////////////////////////////////////////////////////////////
907 Int_t AliTrack::GetNdf()
909 // Provide the number of degrees of freedom for the track fit.
912 ///////////////////////////////////////////////////////////////////////////