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 //-------------------------------------------------------------------------
19 // Implementation of the AliKalmanTrack class
20 // that is the base for AliTPCtrack, AliITStrackV2 and AliTRDtrack
21 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-------------------------------------------------------------------------
24 #include "AliKalmanTrack.h"
27 ClassImp(AliKalmanTrack)
29 Double_t AliKalmanTrack::fgConvConst;
31 //_______________________________________________________________________
32 AliKalmanTrack::AliKalmanTrack():
35 fMass(AliPID::ParticleMass(AliPID::kPion)),
39 // Default constructor
42 AliFatal("The magnetic field has not been set!");
45 fStartTimeIntegral = kFALSE;
46 fIntegratedLength = 0;
47 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
50 //_______________________________________________________________________
51 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
54 fFakeRatio(t.fFakeRatio),
63 AliFatal("The magnetic field has not been set!");
66 fStartTimeIntegral = t.fStartTimeIntegral;
67 fIntegratedLength = t.fIntegratedLength;
69 for (Int_t i=0; i<5; i++)
70 fIntegratedTime[i] = t.fIntegratedTime[i];
73 //_______________________________________________________________________
74 void AliKalmanTrack::StartTimeIntegral()
76 // Sylwester Radomski, GSI
79 // Start time integration
80 // To be called at Vertex by ITS tracker
83 //if (fStartTimeIntegral)
84 // AliWarning("Reseting Recorded Time.");
86 fStartTimeIntegral = kTRUE;
87 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
88 fIntegratedLength = 0;
90 //_______________________________________________________________________
91 void AliKalmanTrack:: AddTimeStep(Double_t length)
94 // Add step to integrated time
95 // this method should be called by a sublasses at the end
96 // of the PropagateTo function or by a tracker
97 // each time step is made.
99 // If integration not started function does nothing
102 // dt = dl * sqrt(p^2 + m^2) / p
103 // p = pT * (1 + tg^2 (lambda) )
105 // pt = 1/external parameter [4]
106 // tg lambda = external parameter [3]
109 // Sylwester Radomski, GSI
113 static const Double_t kcc = 2.99792458e-2;
115 if (!fStartTimeIntegral) return;
117 fIntegratedLength += length;
119 Double_t xr, param[5];
122 GetExternalParameters(xr, param);
126 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
128 if (length > 100) return;
130 for (Int_t i=0; i<AliPID::kSPECIES; i++) {
132 Double_t mass = AliPID::ParticleMass(i);
133 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
134 Double_t time = length * correction / kcc;
136 fIntegratedTime[i] += time;
140 //_______________________________________________________________________
142 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
144 // Sylwester Radomski, GSI
147 // Return integrated time hypothesis for a given particle
151 // pdg - Pdg code of a particle type
155 if (!fStartTimeIntegral) {
156 AliWarning("Time integration not started");
160 for (Int_t i=0; i<AliPID::kSPECIES; i++)
161 if (AliPID::ParticleCode(i) == TMath::Abs(pdg)) return fIntegratedTime[i];
163 AliWarning(Form("Particle type [%d] not found", pdg));
167 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
168 for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fIntegratedTime[i];
171 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
172 for (Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i]=times[i];
175 //_______________________________________________________________________
177 void AliKalmanTrack::PrintTime() const
179 // Sylwester Radomski, GSI
183 // Prints time for all hypothesis
186 for (Int_t i=0; i<AliPID::kSPECIES; i++)
187 printf("%d: %.2f ", AliPID::ParticleCode(i), fIntegratedTime[i]);
191 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
192 //--------------------------------------------------------------------
193 // External track parameters -> helix parameters
194 //--------------------------------------------------------------------
195 Double_t alpha,x,cs,sn;
196 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
198 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
199 helix[5]=x*cs - helix[0]*sn; // x0
200 helix[0]=x*sn + helix[0]*cs; // y0
202 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
204 helix[4]=helix[4]/t->GetConvConst(); // C
207 static void Evaluate(const Double_t *h, Double_t t,
208 Double_t r[3], //radius vector
209 Double_t g[3], //first defivatives
210 Double_t gg[3]) //second derivatives
212 //--------------------------------------------------------------------
213 // Calculate position of a point on a track and some derivatives
214 //--------------------------------------------------------------------
215 Double_t phase=h[4]*t+h[2];
216 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
218 r[0] = h[5] + (sn - h[6])/h[4];
219 r[1] = h[0] - (cs - h[7])/h[4];
220 r[2] = h[1] + h[3]*t;
222 g[0] = cs; g[1]=sn; g[2]=h[3];
224 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
227 Double_t AliKalmanTrack::
228 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
229 //------------------------------------------------------------
230 // Returns the (weighed !) distance of closest approach between
231 // this track and the track passed as the argument.
232 // Other returned values:
233 // xthis, xt - coordinates of tracks' reference planes at the DCA
234 //-----------------------------------------------------------
235 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
236 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
241 Double_t p1[8]; External2Helix(this,p1);
242 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
243 Double_t p2[8]; External2Helix(p,p2);
244 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
247 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
248 Evaluate(p1,t1,r1,g1,gg1);
249 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
250 Evaluate(p2,t2,r2,g2,gg2);
252 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
253 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
257 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
258 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
259 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
260 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
261 (g1[2]*g1[2] - dz*gg1[2])/dz2;
262 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
263 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
264 (g2[2]*g2[2] + dz*gg2[2])/dz2;
265 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
267 Double_t det=h11*h22-h12*h12;
270 if (TMath::Abs(det)<1.e-33) {
271 //(quasi)singular Hessian
274 dt1=-(gt1*h22 - gt2*h12)/det;
275 dt2=-(h11*gt2 - h12*gt1)/det;
278 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
280 //check delta(phase1) ?
281 //check delta(phase2) ?
283 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
284 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
285 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
286 AliWarning(" stopped at not a stationary point !");
287 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
289 AliWarning(" stopped at not a minimum !");
294 for (Int_t div=1 ; ; div*=2) {
295 Evaluate(p1,t1+dt1,r1,g1,gg1);
296 Evaluate(p2,t2+dt2,r2,g2,gg2);
297 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
298 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
302 AliWarning(" overshoot !"); break;
312 if (max<=0) AliWarning(" too many iterations !");
314 Double_t cs=TMath::Cos(GetAlpha());
315 Double_t sn=TMath::Sin(GetAlpha());
316 xthis=r1[0]*cs + r1[1]*sn;
318 cs=TMath::Cos(p->GetAlpha());
319 sn=TMath::Sin(p->GetAlpha());
320 xp=r2[0]*cs + r2[1]*sn;
322 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
325 Double_t AliKalmanTrack::
326 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
327 //--------------------------------------------------------------
328 // Propagates this track and the argument track to the position of the
329 // distance of closest approach.
330 // Returns the (weighed !) distance of closest approach.
331 //--------------------------------------------------------------
333 Double_t dca=GetDCA(p,xthis,xp);
335 if (!PropagateTo(xthis,d,x0)) {
336 //AliWarning(" propagation failed !");
340 if (!p->PropagateTo(xp,d,x0)) {
341 //AliWarning(" propagation failed !";