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 #include "TDatabasePDG.h"
29 ClassImp(AliKalmanTrack)
31 Double_t AliKalmanTrack::fgConvConst;
33 //_______________________________________________________________________
34 AliKalmanTrack::AliKalmanTrack():
41 // Default constructor
44 Fatal("AliKalmanTrack()", "The magnetic field has not been set!");
47 fStartTimeIntegral = kFALSE;
48 fIntegratedLength = 0;
49 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
52 //_______________________________________________________________________
53 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
64 Fatal("AliKalmanTrack(const AliKalmanTrack&)",
65 "The magnetic field has not been set!");
68 fStartTimeIntegral = t.fStartTimeIntegral;
69 fIntegratedLength = t.fIntegratedLength;
71 for (Int_t i=0; i<5; i++)
72 fIntegratedTime[i] = t.fIntegratedTime[i];
75 //_______________________________________________________________________
76 Double_t AliKalmanTrack::GetX() const
78 // Returns the X coordinate of the current track position
79 Warning("GetX()","Method must be overloaded !\n");
82 //_______________________________________________________________________
83 Double_t AliKalmanTrack::GetdEdx() const
85 // Returns the dE/dx of the track
86 Warning("GetdEdx()","Method must be overloaded !\n");
90 //_______________________________________________________________________
91 Double_t AliKalmanTrack::GetY() const
93 // Returns the Y coordinate of the current track position
95 Double_t localX = GetX();
96 GetExternalParameters(localX, par);
99 //_______________________________________________________________________
100 Double_t AliKalmanTrack::GetZ() const
102 // Returns the Z coordinate of the current track position
104 Double_t localX = GetX();
105 GetExternalParameters(localX, par);
108 //_______________________________________________________________________
109 Double_t AliKalmanTrack::GetSnp() const
111 // Returns the Sin(phi), where phi is the angle between the transverse
112 // momentum (in xOy plane) and the X axis
114 Double_t localX = GetX();
115 GetExternalParameters(localX, par);
118 //_______________________________________________________________________
119 Double_t AliKalmanTrack::GetTgl() const
121 // Returns the Tan(lambda), where lambda is the dip angle (between
122 // the bending plane (xOy) and the momentum of the track
124 Double_t localX = GetX();
125 GetExternalParameters(localX, par);
128 //_______________________________________________________________________
129 Double_t AliKalmanTrack::Get1Pt() const
133 Double_t localX = GetX();
134 GetExternalParameters(localX, par);
138 //_______________________________________________________________________
139 Double_t AliKalmanTrack::Phi() const
141 // return global phi of track
144 Double_t localX = GetX();
145 GetExternalParameters(localX, par);
146 if (par[2] > 1.) par[2] = 1.;
147 if (par[2] < -1.) par[2] = -1.;
148 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
149 while (phi < 0) phi += TMath::TwoPi();
150 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
153 //_______________________________________________________________________
154 Double_t AliKalmanTrack::SigmaPhi() const
156 // return error of global phi of track
160 Double_t localX = GetX();
161 GetExternalParameters(localX, par);
162 GetExternalCovariance(cov);
163 return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
165 //_______________________________________________________________________
166 Double_t AliKalmanTrack::Theta() const
168 // return global theta of track
171 Double_t localX = GetX();
172 GetExternalParameters(localX, par);
173 return TMath::Pi()/2. - TMath::ATan(par[3]);
175 //_______________________________________________________________________
176 Double_t AliKalmanTrack::SigmaTheta() const
178 // return error of global theta of track
182 Double_t localX = GetX();
183 GetExternalParameters(localX, par);
184 GetExternalCovariance(cov);
185 return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
187 //_______________________________________________________________________
188 Double_t AliKalmanTrack::Eta() const
190 // return global eta of track
192 return -TMath::Log(TMath::Tan(Theta()/2.));
194 //_______________________________________________________________________
195 Double_t AliKalmanTrack::Px() const
197 // return x component of track momentum
200 Double_t localX = GetX();
201 GetExternalParameters(localX, par);
202 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
203 return TMath::Cos(phi) / TMath::Abs(par[4]);
205 //_______________________________________________________________________
206 Double_t AliKalmanTrack::Py() const
208 // return y component of track momentum
211 Double_t localX = GetX();
212 GetExternalParameters(localX, par);
213 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
214 return TMath::Sin(phi) / TMath::Abs(par[4]);
216 //_______________________________________________________________________
217 Double_t AliKalmanTrack::Pz() const
219 // return z component of track momentum
222 Double_t localX = GetX();
223 GetExternalParameters(localX, par);
224 return par[3] / TMath::Abs(par[4]);
226 //_______________________________________________________________________
227 Double_t AliKalmanTrack::Pt() const
229 // return transverse component of track momentum
232 Double_t localX = GetX();
233 GetExternalParameters(localX, par);
234 return 1. / TMath::Abs(par[4]);
236 //_______________________________________________________________________
237 Double_t AliKalmanTrack::SigmaPt() const
239 // return error of transverse component of track momentum
243 Double_t localX = GetX();
244 GetExternalParameters(localX, par);
245 GetExternalCovariance(cov);
246 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
248 //_______________________________________________________________________
249 Double_t AliKalmanTrack::P() const
251 // return total track momentum
254 Double_t localX = GetX();
255 GetExternalParameters(localX, par);
256 return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
258 //_______________________________________________________________________
259 void AliKalmanTrack::StartTimeIntegral()
261 // Sylwester Radomski, GSI
264 // Start time integration
265 // To be called at Vertex by ITS tracker
268 //if (fStartTimeIntegral)
269 // Warning("StartTimeIntegral", "Reseting Recorded Time.");
271 fStartTimeIntegral = kTRUE;
272 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
273 fIntegratedLength = 0;
275 //_______________________________________________________________________
276 void AliKalmanTrack:: AddTimeStep(Double_t length)
279 // Add step to integrated time
280 // this method should be called by a sublasses at the end
281 // of the PropagateTo function or by a tracker
282 // each time step is made.
284 // If integration not started function does nothing
287 // dt = dl * sqrt(p^2 + m^2) / p
288 // p = pT * (1 + tg^2 (lambda) )
290 // pt = 1/external parameter [4]
291 // tg lambda = external parameter [3]
294 // Sylwester Radomski, GSI
298 static const Double_t kcc = 2.99792458e-2;
300 if (!fStartTimeIntegral) return;
302 fIntegratedLength += length;
304 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
305 TDatabasePDG *db = TDatabasePDG::Instance();
307 Double_t xr, param[5];
310 GetExternalParameters(xr, param);
314 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
316 if (length > 100) return;
318 for (Int_t i=0; i<fgkTypes; i++) {
320 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
321 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
322 Double_t time = length * correction / kcc;
324 fIntegratedTime[i] += time;
328 //_______________________________________________________________________
330 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
332 // Sylwester Radomski, GSI
335 // Return integrated time hypothesis for a given particle
339 // pdg - Pdg code of a particle type
343 if (!fStartTimeIntegral) {
344 Warning("GetIntegratedTime","Time integration not started");
348 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
350 for (Int_t i=0; i<fgkTypes; i++)
351 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
353 Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
357 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
358 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
361 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
362 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
365 //_______________________________________________________________________
367 void AliKalmanTrack::PrintTime() const
369 // Sylwester Radomski, GSI
373 // Prints time for all hypothesis
376 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
378 for (Int_t i=0; i<fgkTypes; i++)
379 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
383 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
384 //--------------------------------------------------------------------
385 // External track parameters -> helix parameters
386 //--------------------------------------------------------------------
387 Double_t alpha,x,cs,sn;
388 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
390 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
391 helix[5]=x*cs - helix[0]*sn; // x0
392 helix[0]=x*sn + helix[0]*cs; // y0
394 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
396 helix[4]=helix[4]/t->GetConvConst(); // C
399 static void Evaluate(const Double_t *h, Double_t t,
400 Double_t r[3], //radius vector
401 Double_t g[3], //first defivatives
402 Double_t gg[3]) //second derivatives
404 //--------------------------------------------------------------------
405 // Calculate position of a point on a track and some derivatives
406 //--------------------------------------------------------------------
407 Double_t phase=h[4]*t+h[2];
408 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
410 r[0] = h[5] + (sn - h[6])/h[4];
411 r[1] = h[0] - (cs - h[7])/h[4];
412 r[2] = h[1] + h[3]*t;
414 g[0] = cs; g[1]=sn; g[2]=h[3];
416 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
419 Double_t AliKalmanTrack::
420 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
421 //------------------------------------------------------------
422 // Returns the (weighed !) distance of closest approach between
423 // this track and the track passed as the argument.
424 // Other returned values:
425 // xthis, xt - coordinates of tracks' reference planes at the DCA
426 //-----------------------------------------------------------
427 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
428 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
433 Double_t p1[8]; External2Helix(this,p1);
434 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
435 Double_t p2[8]; External2Helix(p,p2);
436 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
439 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
440 Evaluate(p1,t1,r1,g1,gg1);
441 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
442 Evaluate(p2,t2,r2,g2,gg2);
444 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
445 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
449 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
450 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
451 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
452 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
453 (g1[2]*g1[2] - dz*gg1[2])/dz2;
454 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
455 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
456 (g2[2]*g2[2] + dz*gg2[2])/dz2;
457 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
459 Double_t det=h11*h22-h12*h12;
462 if (TMath::Abs(det)<1.e-33) {
463 //(quasi)singular Hessian
466 dt1=-(gt1*h22 - gt2*h12)/det;
467 dt2=-(h11*gt2 - h12*gt1)/det;
470 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
472 //check delta(phase1) ?
473 //check delta(phase2) ?
475 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
476 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
477 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
478 Warning("GetDCA"," stopped at not a stationary point !\n");
479 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
481 Warning("GetDCA"," stopped at not a minimum !\n");
486 for (Int_t div=1 ; ; div*=2) {
487 Evaluate(p1,t1+dt1,r1,g1,gg1);
488 Evaluate(p2,t2+dt2,r2,g2,gg2);
489 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
490 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
494 Warning("GetDCA"," overshoot !\n"); break;
504 if (max<=0) Warning("GetDCA"," too many iterations !\n");
506 Double_t cs=TMath::Cos(GetAlpha());
507 Double_t sn=TMath::Sin(GetAlpha());
508 xthis=r1[0]*cs + r1[1]*sn;
510 cs=TMath::Cos(p->GetAlpha());
511 sn=TMath::Sin(p->GetAlpha());
512 xp=r2[0]*cs + r2[1]*sn;
514 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
517 Double_t AliKalmanTrack::
518 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
519 //--------------------------------------------------------------
520 // Propagates this track and the argument track to the position of the
521 // distance of closest approach.
522 // Returns the (weighed !) distance of closest approach.
523 //--------------------------------------------------------------
525 Double_t dca=GetDCA(p,xthis,xp);
527 if (!PropagateTo(xthis,d,x0)) {
528 //Warning("PropagateToDCA"," propagation failed !\n");
532 if (!p->PropagateTo(xp,d,x0)) {
533 //Warning("PropagateToDCA"," propagation failed !\n";