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 !\n");
46 fStartTimeIntegral = kFALSE;
47 fIntegratedLength = 0;
48 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
51 //_______________________________________________________________________
52 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
63 Fatal("AliKalmanTrack(const AliKalmanTrack&)",
64 "The magnetic field has not been set !\n");
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 Double_t AliKalmanTrack::GetX() const
76 Warning("GetX()","Method must be overloaded !\n");
79 //_______________________________________________________________________
80 Double_t AliKalmanTrack::GetdEdx() const
82 Warning("GetdEdx()","Method must be overloaded !\n");
86 //_______________________________________________________________________
87 Double_t AliKalmanTrack::GetY() const
90 Double_t localX = GetX();
91 GetExternalParameters(localX, par);
94 //_______________________________________________________________________
95 Double_t AliKalmanTrack::GetZ() const
98 Double_t localX = GetX();
99 GetExternalParameters(localX, par);
102 //_______________________________________________________________________
103 Double_t AliKalmanTrack::GetSnp() const
106 Double_t localX = GetX();
107 GetExternalParameters(localX, par);
110 //_______________________________________________________________________
111 Double_t AliKalmanTrack::GetTgl() const
114 Double_t localX = GetX();
115 GetExternalParameters(localX, par);
118 //_______________________________________________________________________
119 Double_t AliKalmanTrack::Get1Pt() const
122 Double_t localX = GetX();
123 GetExternalParameters(localX, par);
127 //_______________________________________________________________________
128 Double_t AliKalmanTrack::Phi() const
130 // return global phi of track
133 Double_t localX = GetX();
134 GetExternalParameters(localX, par);
135 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
136 while (phi < 0) phi += TMath::TwoPi();
137 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
140 //_______________________________________________________________________
141 Double_t AliKalmanTrack::SigmaPhi() const
143 // return error of global phi of track
147 Double_t localX = GetX();
148 GetExternalParameters(localX, par);
149 GetExternalCovariance(cov);
150 return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
152 //_______________________________________________________________________
153 Double_t AliKalmanTrack::Theta() const
155 // return global theta of track
158 Double_t localX = GetX();
159 GetExternalParameters(localX, par);
160 return TMath::Pi()/2. - TMath::ATan(par[3]);
162 //_______________________________________________________________________
163 Double_t AliKalmanTrack::SigmaTheta() const
165 // return error of global theta of track
169 Double_t localX = GetX();
170 GetExternalParameters(localX, par);
171 GetExternalCovariance(cov);
172 return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
174 //_______________________________________________________________________
175 Double_t AliKalmanTrack::Px() const
177 // return x component of track momentum
180 Double_t localX = GetX();
181 GetExternalParameters(localX, par);
182 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
183 return TMath::Cos(phi) / TMath::Abs(par[4]);
185 //_______________________________________________________________________
186 Double_t AliKalmanTrack::Py() const
188 // return y component of track momentum
191 Double_t localX = GetX();
192 GetExternalParameters(localX, par);
193 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
194 return TMath::Sin(phi) / TMath::Abs(par[4]);
196 //_______________________________________________________________________
197 Double_t AliKalmanTrack::Pz() const
199 // return z component of track momentum
202 Double_t localX = GetX();
203 GetExternalParameters(localX, par);
204 return par[3] / TMath::Abs(par[4]);
206 //_______________________________________________________________________
207 Double_t AliKalmanTrack::Pt() const
209 // return transverse component of track momentum
212 Double_t localX = GetX();
213 GetExternalParameters(localX, par);
214 return 1. / TMath::Abs(par[4]);
216 //_______________________________________________________________________
217 Double_t AliKalmanTrack::SigmaPt() const
219 // return error of transverse component of track momentum
223 Double_t localX = GetX();
224 GetExternalParameters(localX, par);
225 GetExternalCovariance(cov);
226 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
228 //_______________________________________________________________________
229 Double_t AliKalmanTrack::P() const
231 // return total track momentum
234 Double_t localX = GetX();
235 GetExternalParameters(localX, par);
236 return 1. / TMath::Abs(par[4] * TMath::Sin(TMath::ATan(par[3])));
238 //_______________________________________________________________________
239 void AliKalmanTrack::StartTimeIntegral()
241 // Sylwester Radomski, GSI
244 // Start time integration
245 // To be called at Vertex by ITS tracker
248 //if (fStartTimeIntegral)
249 // Warning("StartTimeIntegral", "Reseting Recorded Time.");
251 fStartTimeIntegral = kTRUE;
252 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
253 fIntegratedLength = 0;
255 //_______________________________________________________________________
256 void AliKalmanTrack:: AddTimeStep(Double_t length)
259 // Add step to integrated time
260 // this method should be called by a sublasses at the end
261 // of the PropagateTo function or by a tracker
262 // each time step is made.
264 // If integration not started function does nothing
267 // dt = dl * sqrt(p^2 + m^2) / p
268 // p = pT * (1 + tg^2 (lambda) )
270 // pt = 1/external parameter [4]
271 // tg lambda = external parameter [3]
274 // Sylwester Radomski, GSI
278 static const Double_t kcc = 2.99792458e-2;
280 if (!fStartTimeIntegral) return;
282 fIntegratedLength += length;
284 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
285 TDatabasePDG *db = TDatabasePDG::Instance();
287 Double_t xr, param[5];
290 GetExternalParameters(xr, param);
294 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
296 if (length > 100) return;
298 for (Int_t i=0; i<fgkTypes; i++) {
300 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
301 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
302 Double_t time = length * correction / kcc;
304 //cout << mass << "\t" << pt << "\t" << p << "\t"
305 // << correction << endl;
307 fIntegratedTime[i] += time;
311 //_______________________________________________________________________
313 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
315 // Sylwester Radomski, GSI
318 // Return integrated time hypothesis for a given particle
322 // pdg - Pdg code of a particle type
326 if (!fStartTimeIntegral) {
327 Warning("GetIntegratedTime","Time integration not started");
331 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
333 for (Int_t i=0; i<fgkTypes; i++)
334 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
336 Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
340 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
341 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
344 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
345 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
348 //_______________________________________________________________________
350 void AliKalmanTrack::PrintTime() const
352 // Sylwester Radomski, GSI
356 // Prints time for all hypothesis
359 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
361 for (Int_t i=0; i<fgkTypes; i++)
362 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
366 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
367 //--------------------------------------------------------------------
368 // External track parameters -> helix parameters
369 //--------------------------------------------------------------------
370 Double_t alpha,x,cs,sn;
371 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
373 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
374 helix[5]=x*cs - helix[0]*sn; // x0
375 helix[0]=x*sn + helix[0]*cs; // y0
377 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
379 helix[4]=helix[4]/t->GetConvConst(); // C
382 static void Evaluate(const Double_t *h, Double_t t,
383 Double_t r[3], //radius vector
384 Double_t g[3], //first defivatives
385 Double_t gg[3]) //second derivatives
387 //--------------------------------------------------------------------
388 // Calculate position of a point on a track and some derivatives
389 //--------------------------------------------------------------------
390 Double_t phase=h[4]*t+h[2];
391 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
393 r[0] = h[5] + (sn - h[6])/h[4];
394 r[1] = h[0] - (cs - h[7])/h[4];
395 r[2] = h[1] + h[3]*t;
397 g[0] = cs; g[1]=sn; g[2]=h[3];
399 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
402 Double_t AliKalmanTrack::
403 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
404 //------------------------------------------------------------
405 // Returns the (weighed !) distance of closest approach between
406 // this track and the track passed as the argument.
407 // Other returned values:
408 // xthis, xt - coordinates of tracks' reference planes at the DCA
409 //-----------------------------------------------------------
410 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
411 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
416 Double_t p1[8]; External2Helix(this,p1);
417 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
418 Double_t p2[8]; External2Helix(p,p2);
419 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
422 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
423 Evaluate(p1,t1,r1,g1,gg1);
424 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
425 Evaluate(p2,t2,r2,g2,gg2);
427 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
428 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
432 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
433 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
434 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
435 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
436 (g1[2]*g1[2] - dz*gg1[2])/dz2;
437 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
438 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
439 (g2[2]*g2[2] + dz*gg2[2])/dz2;
440 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
442 Double_t det=h11*h22-h12*h12;
445 if (TMath::Abs(det)<1.e-33) {
446 //(quasi)singular Hessian
449 dt1=-(gt1*h22 - gt2*h12)/det;
450 dt2=-(h11*gt2 - h12*gt1)/det;
453 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
455 //check delta(phase1) ?
456 //check delta(phase2) ?
458 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
459 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
460 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
461 Warning("GetDCA"," stopped at not a stationary point !\n");
462 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
464 Warning("GetDCA"," stopped at not a minimum !\n");
469 for (Int_t div=1 ; ; div*=2) {
470 Evaluate(p1,t1+dt1,r1,g1,gg1);
471 Evaluate(p2,t2+dt2,r2,g2,gg2);
472 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
473 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
477 Warning("GetDCA"," overshoot !\n"); break;
487 if (max<=0) Warning("GetDCA"," too many iterations !\n");
489 Double_t cs=TMath::Cos(GetAlpha());
490 Double_t sn=TMath::Sin(GetAlpha());
491 xthis=r1[0]*cs + r1[1]*sn;
493 cs=TMath::Cos(p->GetAlpha());
494 sn=TMath::Sin(p->GetAlpha());
495 xp=r2[0]*cs + r2[1]*sn;
497 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
500 Double_t AliKalmanTrack::
501 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
502 //--------------------------------------------------------------
503 // Propagates this track and the argument track to the position of the
504 // distance of closest approach.
505 // Returns the (weighed !) distance of closest approach.
506 //--------------------------------------------------------------
508 Double_t dca=GetDCA(p,xthis,xp);
510 if (!PropagateTo(xthis,d,x0)) {
511 //Warning("PropagateToDCA"," propagation failed !\n");
515 if (!p->PropagateTo(xp,d,x0)) {
516 //Warning("PropagateToDCA"," propagation failed !\n";