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"
28 #include "TDatabasePDG.h"
30 ClassImp(AliKalmanTrack)
32 Double_t AliKalmanTrack::fgConvConst;
34 //_______________________________________________________________________
35 AliKalmanTrack::AliKalmanTrack():
42 // Default constructor
45 AliFatal("The magnetic field has not been set!");
48 fStartTimeIntegral = kFALSE;
49 fIntegratedLength = 0;
50 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
53 //_______________________________________________________________________
54 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
57 fFakeRatio(t.fFakeRatio),
66 AliFatal("The magnetic field has not been set!");
69 fStartTimeIntegral = t.fStartTimeIntegral;
70 fIntegratedLength = t.fIntegratedLength;
72 for (Int_t i=0; i<5; i++)
73 fIntegratedTime[i] = t.fIntegratedTime[i];
76 //_______________________________________________________________________
77 Double_t AliKalmanTrack::GetX() const
79 // Returns the X coordinate of the current track position
80 AliWarning("Method must be overloaded !");
83 //_______________________________________________________________________
84 Double_t AliKalmanTrack::GetdEdx() const
86 // Returns the dE/dx of the track
87 AliWarning("Method must be overloaded !");
91 //_______________________________________________________________________
92 Double_t AliKalmanTrack::GetY() const
94 // Returns the Y coordinate of the current track position
96 Double_t localX = GetX();
97 GetExternalParameters(localX, par);
100 //_______________________________________________________________________
101 Double_t AliKalmanTrack::GetZ() const
103 // Returns the Z coordinate of the current track position
105 Double_t localX = GetX();
106 GetExternalParameters(localX, par);
109 //_______________________________________________________________________
110 Double_t AliKalmanTrack::GetSnp() const
112 // Returns the Sin(phi), where phi is the angle between the transverse
113 // momentum (in xOy plane) and the X axis
115 Double_t localX = GetX();
116 GetExternalParameters(localX, par);
119 //_______________________________________________________________________
120 Double_t AliKalmanTrack::GetTgl() const
122 // Returns the Tan(lambda), where lambda is the dip angle (between
123 // the bending plane (xOy) and the momentum of the track
125 Double_t localX = GetX();
126 GetExternalParameters(localX, par);
129 //_______________________________________________________________________
130 Double_t AliKalmanTrack::Get1Pt() const
134 Double_t localX = GetX();
135 GetExternalParameters(localX, par);
139 //_______________________________________________________________________
140 Double_t AliKalmanTrack::Phi() const
142 // return global phi of track
145 Double_t localX = GetX();
146 GetExternalParameters(localX, par);
147 if (par[2] > 1.) par[2] = 1.;
148 if (par[2] < -1.) par[2] = -1.;
149 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
150 while (phi < 0) phi += TMath::TwoPi();
151 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
154 //_______________________________________________________________________
155 Double_t AliKalmanTrack::SigmaPhi() const
157 // return error of global phi of track
161 Double_t localX = GetX();
162 GetExternalParameters(localX, par);
163 GetExternalCovariance(cov);
164 return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
166 //_______________________________________________________________________
167 Double_t AliKalmanTrack::Theta() const
169 // return global theta of track
172 Double_t localX = GetX();
173 GetExternalParameters(localX, par);
174 return TMath::Pi()/2. - TMath::ATan(par[3]);
176 //_______________________________________________________________________
177 Double_t AliKalmanTrack::SigmaTheta() const
179 // return error of global theta of track
183 Double_t localX = GetX();
184 GetExternalParameters(localX, par);
185 GetExternalCovariance(cov);
186 return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
188 //_______________________________________________________________________
189 Double_t AliKalmanTrack::Eta() const
191 // return global eta of track
193 return -TMath::Log(TMath::Tan(Theta()/2.));
195 //_______________________________________________________________________
196 Double_t AliKalmanTrack::Px() const
198 // return x component of track momentum
201 Double_t localX = GetX();
202 GetExternalParameters(localX, par);
203 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
204 return TMath::Cos(phi) / TMath::Abs(par[4]);
206 //_______________________________________________________________________
207 Double_t AliKalmanTrack::Py() const
209 // return y component of track momentum
212 Double_t localX = GetX();
213 GetExternalParameters(localX, par);
214 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
215 return TMath::Sin(phi) / TMath::Abs(par[4]);
217 //_______________________________________________________________________
218 Double_t AliKalmanTrack::Pz() const
220 // return z component of track momentum
223 Double_t localX = GetX();
224 GetExternalParameters(localX, par);
225 return par[3] / TMath::Abs(par[4]);
227 //_______________________________________________________________________
228 Double_t AliKalmanTrack::Pt() const
230 // return transverse component of track momentum
233 Double_t localX = GetX();
234 GetExternalParameters(localX, par);
235 return 1. / TMath::Abs(par[4]);
237 //_______________________________________________________________________
238 Double_t AliKalmanTrack::SigmaPt() const
240 // return error of transverse component of track momentum
244 Double_t localX = GetX();
245 GetExternalParameters(localX, par);
246 GetExternalCovariance(cov);
247 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
249 //_______________________________________________________________________
250 Double_t AliKalmanTrack::P() const
252 // return total track momentum
255 Double_t localX = GetX();
256 GetExternalParameters(localX, par);
257 return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
259 //_______________________________________________________________________
260 void AliKalmanTrack::StartTimeIntegral()
262 // Sylwester Radomski, GSI
265 // Start time integration
266 // To be called at Vertex by ITS tracker
269 //if (fStartTimeIntegral)
270 // AliWarning("Reseting Recorded Time.");
272 fStartTimeIntegral = kTRUE;
273 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
274 fIntegratedLength = 0;
276 //_______________________________________________________________________
277 void AliKalmanTrack:: AddTimeStep(Double_t length)
280 // Add step to integrated time
281 // this method should be called by a sublasses at the end
282 // of the PropagateTo function or by a tracker
283 // each time step is made.
285 // If integration not started function does nothing
288 // dt = dl * sqrt(p^2 + m^2) / p
289 // p = pT * (1 + tg^2 (lambda) )
291 // pt = 1/external parameter [4]
292 // tg lambda = external parameter [3]
295 // Sylwester Radomski, GSI
299 static const Double_t kcc = 2.99792458e-2;
301 if (!fStartTimeIntegral) return;
303 fIntegratedLength += length;
305 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
306 TDatabasePDG *db = TDatabasePDG::Instance();
308 Double_t xr, param[5];
311 GetExternalParameters(xr, param);
315 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
317 if (length > 100) return;
319 for (Int_t i=0; i<fgkTypes; i++) {
321 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
322 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
323 Double_t time = length * correction / kcc;
325 fIntegratedTime[i] += time;
329 //_______________________________________________________________________
331 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
333 // Sylwester Radomski, GSI
336 // Return integrated time hypothesis for a given particle
340 // pdg - Pdg code of a particle type
344 if (!fStartTimeIntegral) {
345 AliWarning("Time integration not started");
349 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
351 for (Int_t i=0; i<fgkTypes; i++)
352 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
354 AliWarning(Form("Particle type [%d] not found", pdg));
358 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
359 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
362 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
363 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
366 //_______________________________________________________________________
368 void AliKalmanTrack::PrintTime() const
370 // Sylwester Radomski, GSI
374 // Prints time for all hypothesis
377 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
379 for (Int_t i=0; i<fgkTypes; i++)
380 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
384 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
385 //--------------------------------------------------------------------
386 // External track parameters -> helix parameters
387 //--------------------------------------------------------------------
388 Double_t alpha,x,cs,sn;
389 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
391 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
392 helix[5]=x*cs - helix[0]*sn; // x0
393 helix[0]=x*sn + helix[0]*cs; // y0
395 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
397 helix[4]=helix[4]/t->GetConvConst(); // C
400 static void Evaluate(const Double_t *h, Double_t t,
401 Double_t r[3], //radius vector
402 Double_t g[3], //first defivatives
403 Double_t gg[3]) //second derivatives
405 //--------------------------------------------------------------------
406 // Calculate position of a point on a track and some derivatives
407 //--------------------------------------------------------------------
408 Double_t phase=h[4]*t+h[2];
409 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
411 r[0] = h[5] + (sn - h[6])/h[4];
412 r[1] = h[0] - (cs - h[7])/h[4];
413 r[2] = h[1] + h[3]*t;
415 g[0] = cs; g[1]=sn; g[2]=h[3];
417 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
420 Double_t AliKalmanTrack::
421 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
422 //------------------------------------------------------------
423 // Returns the (weighed !) distance of closest approach between
424 // this track and the track passed as the argument.
425 // Other returned values:
426 // xthis, xt - coordinates of tracks' reference planes at the DCA
427 //-----------------------------------------------------------
428 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
429 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
434 Double_t p1[8]; External2Helix(this,p1);
435 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
436 Double_t p2[8]; External2Helix(p,p2);
437 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
440 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
441 Evaluate(p1,t1,r1,g1,gg1);
442 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
443 Evaluate(p2,t2,r2,g2,gg2);
445 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
446 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
450 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
451 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
452 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
453 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
454 (g1[2]*g1[2] - dz*gg1[2])/dz2;
455 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
456 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
457 (g2[2]*g2[2] + dz*gg2[2])/dz2;
458 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
460 Double_t det=h11*h22-h12*h12;
463 if (TMath::Abs(det)<1.e-33) {
464 //(quasi)singular Hessian
467 dt1=-(gt1*h22 - gt2*h12)/det;
468 dt2=-(h11*gt2 - h12*gt1)/det;
471 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
473 //check delta(phase1) ?
474 //check delta(phase2) ?
476 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
477 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
478 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
479 AliWarning(" stopped at not a stationary point !");
480 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
482 AliWarning(" stopped at not a minimum !");
487 for (Int_t div=1 ; ; div*=2) {
488 Evaluate(p1,t1+dt1,r1,g1,gg1);
489 Evaluate(p2,t2+dt2,r2,g2,gg2);
490 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
491 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
495 AliWarning(" overshoot !"); break;
505 if (max<=0) AliWarning(" too many iterations !");
507 Double_t cs=TMath::Cos(GetAlpha());
508 Double_t sn=TMath::Sin(GetAlpha());
509 xthis=r1[0]*cs + r1[1]*sn;
511 cs=TMath::Cos(p->GetAlpha());
512 sn=TMath::Sin(p->GetAlpha());
513 xp=r2[0]*cs + r2[1]*sn;
515 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
518 Double_t AliKalmanTrack::
519 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
520 //--------------------------------------------------------------
521 // Propagates this track and the argument track to the position of the
522 // distance of closest approach.
523 // Returns the (weighed !) distance of closest approach.
524 //--------------------------------------------------------------
526 Double_t dca=GetDCA(p,xthis,xp);
528 if (!PropagateTo(xthis,d,x0)) {
529 //AliWarning(" propagation failed !");
533 if (!p->PropagateTo(xp,d,x0)) {
534 //AliWarning(" propagation failed !";