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 = 0;
31 //_______________________________________________________________________
32 AliKalmanTrack::AliKalmanTrack():
37 fMass(AliPID::ParticleMass(AliPID::kPion)),
39 fStartTimeIntegral(kFALSE),
43 // Default constructor
46 AliFatal("The magnetic field has not been set!");
49 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
52 //_______________________________________________________________________
53 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
56 fFakeRatio(t.fFakeRatio),
60 fStartTimeIntegral(t.fStartTimeIntegral),
61 fIntegratedLength(t.fIntegratedLength)
67 AliFatal("The magnetic field has not been set!");
71 for (Int_t i=0; i<5; i++)
72 fIntegratedTime[i] = t.fIntegratedTime[i];
75 //_______________________________________________________________________
76 void AliKalmanTrack::StartTimeIntegral()
78 // Sylwester Radomski, GSI
81 // Start time integration
82 // To be called at Vertex by ITS tracker
85 //if (fStartTimeIntegral)
86 // AliWarning("Reseting Recorded Time.");
88 fStartTimeIntegral = kTRUE;
89 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
90 fIntegratedLength = 0;
92 //_______________________________________________________________________
93 void AliKalmanTrack:: AddTimeStep(Double_t length)
96 // Add step to integrated time
97 // this method should be called by a sublasses at the end
98 // of the PropagateTo function or by a tracker
99 // each time step is made.
101 // If integration not started function does nothing
104 // dt = dl * sqrt(p^2 + m^2) / p
105 // p = pT * (1 + tg^2 (lambda) )
107 // pt = 1/external parameter [4]
108 // tg lambda = external parameter [3]
111 // Sylwester Radomski, GSI
115 static const Double_t kcc = 2.99792458e-2;
117 if (!fStartTimeIntegral) return;
119 fIntegratedLength += length;
121 Double_t xr, param[5];
124 GetExternalParameters(xr, param);
128 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
130 if (length > 100) return;
132 for (Int_t i=0; i<AliPID::kSPECIES; i++) {
134 Double_t mass = AliPID::ParticleMass(i);
135 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
136 Double_t time = length * correction / kcc;
138 fIntegratedTime[i] += time;
142 //_______________________________________________________________________
144 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
146 // Sylwester Radomski, GSI
149 // Return integrated time hypothesis for a given particle
153 // pdg - Pdg code of a particle type
157 if (!fStartTimeIntegral) {
158 AliWarning("Time integration not started");
162 for (Int_t i=0; i<AliPID::kSPECIES; i++)
163 if (AliPID::ParticleCode(i) == TMath::Abs(pdg)) return fIntegratedTime[i];
165 AliWarning(Form("Particle type [%d] not found", pdg));
169 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
170 for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fIntegratedTime[i];
173 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
174 for (Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i]=times[i];
177 //_______________________________________________________________________
179 void AliKalmanTrack::PrintTime() const
181 // Sylwester Radomski, GSI
185 // Prints time for all hypothesis
188 for (Int_t i=0; i<AliPID::kSPECIES; i++)
189 printf("%d: %.2f ", AliPID::ParticleCode(i), fIntegratedTime[i]);
193 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
194 //--------------------------------------------------------------------
195 // External track parameters -> helix parameters
196 //--------------------------------------------------------------------
197 Double_t alpha,x,cs,sn;
198 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
200 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
201 helix[5]=x*cs - helix[0]*sn; // x0
202 helix[0]=x*sn + helix[0]*cs; // y0
204 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
206 helix[4]=helix[4]/t->GetConvConst(); // C
209 static void Evaluate(const Double_t *h, Double_t t,
210 Double_t r[3], //radius vector
211 Double_t g[3], //first defivatives
212 Double_t gg[3]) //second derivatives
214 //--------------------------------------------------------------------
215 // Calculate position of a point on a track and some derivatives
216 //--------------------------------------------------------------------
217 Double_t phase=h[4]*t+h[2];
218 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
220 r[0] = h[5] + (sn - h[6])/h[4];
221 r[1] = h[0] - (cs - h[7])/h[4];
222 r[2] = h[1] + h[3]*t;
224 g[0] = cs; g[1]=sn; g[2]=h[3];
226 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
229 Double_t AliKalmanTrack::
230 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
231 //------------------------------------------------------------
232 // Returns the (weighed !) distance of closest approach between
233 // this track and the track passed as the argument.
234 // Other returned values:
235 // xthis, xt - coordinates of tracks' reference planes at the DCA
236 //-----------------------------------------------------------
237 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
238 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
243 Double_t p1[8]; External2Helix(this,p1);
244 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
245 Double_t p2[8]; External2Helix(p,p2);
246 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
249 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
250 Evaluate(p1,t1,r1,g1,gg1);
251 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
252 Evaluate(p2,t2,r2,g2,gg2);
254 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
255 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
259 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
260 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
261 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
262 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
263 (g1[2]*g1[2] - dz*gg1[2])/dz2;
264 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
265 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
266 (g2[2]*g2[2] + dz*gg2[2])/dz2;
267 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
269 Double_t det=h11*h22-h12*h12;
272 if (TMath::Abs(det)<1.e-33) {
273 //(quasi)singular Hessian
276 dt1=-(gt1*h22 - gt2*h12)/det;
277 dt2=-(h11*gt2 - h12*gt1)/det;
280 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
282 //check delta(phase1) ?
283 //check delta(phase2) ?
285 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
286 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
287 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
288 AliWarning(" stopped at not a stationary point !");
289 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
291 AliWarning(" stopped at not a minimum !");
296 for (Int_t div=1 ; ; div*=2) {
297 Evaluate(p1,t1+dt1,r1,g1,gg1);
298 Evaluate(p2,t2+dt2,r2,g2,gg2);
299 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
300 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
304 AliWarning(" overshoot !"); break;
314 if (max<=0) AliWarning(" too many iterations !");
316 Double_t cs=TMath::Cos(GetAlpha());
317 Double_t sn=TMath::Sin(GetAlpha());
318 xthis=r1[0]*cs + r1[1]*sn;
320 cs=TMath::Cos(p->GetAlpha());
321 sn=TMath::Sin(p->GetAlpha());
322 xp=r2[0]*cs + r2[1]*sn;
324 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
327 Double_t AliKalmanTrack::
328 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
329 //--------------------------------------------------------------
330 // Propagates this track and the argument track to the position of the
331 // distance of closest approach.
332 // Returns the (weighed !) distance of closest approach.
333 //--------------------------------------------------------------
335 Double_t dca=GetDCA(p,xthis,xp);
337 if (!PropagateTo(xthis,d,x0)) {
338 //AliWarning(" propagation failed !");
342 if (!p->PropagateTo(xp,d,x0)) {
343 //AliWarning(" propagation failed !";