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"
28 #include "AliRunLoader.h"
32 ClassImp(AliKalmanTrack)
34 Double_t AliKalmanTrack::fgConvConst;
36 //_______________________________________________________________________
37 AliKalmanTrack::AliKalmanTrack():
44 // Default constructor
47 Warning("AliKalmanTrack()", "The magnetic field has not been set!");
51 fStartTimeIntegral = kFALSE;
52 fIntegratedLength = 0;
53 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
56 //_______________________________________________________________________
57 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
68 Warning("AliKalmanTrack(const AliKalmanTrack&)",
69 "The magnetic field has not been set!");
73 fStartTimeIntegral = t.fStartTimeIntegral;
74 fIntegratedLength = t.fIntegratedLength;
76 for (Int_t i=0; i<5; i++)
77 fIntegratedTime[i] = t.fIntegratedTime[i];
81 //_______________________________________________________________________
82 void AliKalmanTrack::SetConvConst()
84 // Sets the conversion constants for the magnetic field
85 // (Momentum in GeV/c -> curvature in mm)
86 ::Info("SetConvConst()", "tryinig to get the magnetic field from the AliRun object...");
87 AliRunLoader* loader = AliRunLoader::GetRunLoader();
88 if (!loader) ::Fatal("SetConvConst()", "No run loader found");
89 if (!loader->GetAliRun()) loader->LoadgAlice();
90 AliRun* alirun = loader->GetAliRun();
91 if (!alirun) ::Fatal("SetConvConst()", "No AliRun object found");
93 Double_t field = alirun->Field()->SolenoidField();
94 SetConvConst(1000/0.299792458/field);
95 ::Info("SetConvConst()", "Magnetic field set to %f kGauss\n", field);
98 //_______________________________________________________________________
99 Double_t AliKalmanTrack::GetX() const
101 // Returns the X coordinate of the current track position
102 Warning("GetX()","Method must be overloaded !\n");
105 //_______________________________________________________________________
106 Double_t AliKalmanTrack::GetdEdx() const
108 // Returns the dE/dx of the track
109 Warning("GetdEdx()","Method must be overloaded !\n");
113 //_______________________________________________________________________
114 Double_t AliKalmanTrack::GetY() const
116 // Returns the Y coordinate of the current track position
118 Double_t localX = GetX();
119 GetExternalParameters(localX, par);
122 //_______________________________________________________________________
123 Double_t AliKalmanTrack::GetZ() const
125 // Returns the Z coordinate of the current track position
127 Double_t localX = GetX();
128 GetExternalParameters(localX, par);
131 //_______________________________________________________________________
132 Double_t AliKalmanTrack::GetSnp() const
134 // Returns the Sin(phi), where phi is the angle between the transverse
135 // momentum (in xOy plane) and the X axis
137 Double_t localX = GetX();
138 GetExternalParameters(localX, par);
141 //_______________________________________________________________________
142 Double_t AliKalmanTrack::GetTgl() const
144 // Returns the Tan(lambda), where lambda is the dip angle (between
145 // the bending plane (xOy) and the momentum of the track
147 Double_t localX = GetX();
148 GetExternalParameters(localX, par);
151 //_______________________________________________________________________
152 Double_t AliKalmanTrack::Get1Pt() const
156 Double_t localX = GetX();
157 GetExternalParameters(localX, par);
161 //_______________________________________________________________________
162 Double_t AliKalmanTrack::Phi() const
164 // return global phi of track
167 Double_t localX = GetX();
168 GetExternalParameters(localX, par);
169 if (par[2] > 1.) par[2] = 1.;
170 if (par[2] < -1.) par[2] = -1.;
171 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
172 while (phi < 0) phi += TMath::TwoPi();
173 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
176 //_______________________________________________________________________
177 Double_t AliKalmanTrack::SigmaPhi() const
179 // return error of global phi of track
183 Double_t localX = GetX();
184 GetExternalParameters(localX, par);
185 GetExternalCovariance(cov);
186 return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
188 //_______________________________________________________________________
189 Double_t AliKalmanTrack::Theta() const
191 // return global theta of track
194 Double_t localX = GetX();
195 GetExternalParameters(localX, par);
196 return TMath::Pi()/2. - TMath::ATan(par[3]);
198 //_______________________________________________________________________
199 Double_t AliKalmanTrack::SigmaTheta() const
201 // return error of global theta of track
205 Double_t localX = GetX();
206 GetExternalParameters(localX, par);
207 GetExternalCovariance(cov);
208 return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
210 //_______________________________________________________________________
211 Double_t AliKalmanTrack::Eta() const
213 // return global eta of track
215 return -TMath::Log(TMath::Tan(Theta()/2.));
217 //_______________________________________________________________________
218 Double_t AliKalmanTrack::Px() const
220 // return x component of track momentum
223 Double_t localX = GetX();
224 GetExternalParameters(localX, par);
225 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
226 return TMath::Cos(phi) / TMath::Abs(par[4]);
228 //_______________________________________________________________________
229 Double_t AliKalmanTrack::Py() const
231 // return y component of track momentum
234 Double_t localX = GetX();
235 GetExternalParameters(localX, par);
236 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
237 return TMath::Sin(phi) / TMath::Abs(par[4]);
239 //_______________________________________________________________________
240 Double_t AliKalmanTrack::Pz() const
242 // return z component of track momentum
245 Double_t localX = GetX();
246 GetExternalParameters(localX, par);
247 return par[3] / TMath::Abs(par[4]);
249 //_______________________________________________________________________
250 Double_t AliKalmanTrack::Pt() const
252 // return transverse component of track momentum
255 Double_t localX = GetX();
256 GetExternalParameters(localX, par);
257 return 1. / TMath::Abs(par[4]);
259 //_______________________________________________________________________
260 Double_t AliKalmanTrack::SigmaPt() const
262 // return error of transverse component of track momentum
266 Double_t localX = GetX();
267 GetExternalParameters(localX, par);
268 GetExternalCovariance(cov);
269 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
271 //_______________________________________________________________________
272 Double_t AliKalmanTrack::P() const
274 // return total track momentum
277 Double_t localX = GetX();
278 GetExternalParameters(localX, par);
279 return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
281 //_______________________________________________________________________
282 void AliKalmanTrack::StartTimeIntegral()
284 // Sylwester Radomski, GSI
287 // Start time integration
288 // To be called at Vertex by ITS tracker
291 //if (fStartTimeIntegral)
292 // Warning("StartTimeIntegral", "Reseting Recorded Time.");
294 fStartTimeIntegral = kTRUE;
295 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
296 fIntegratedLength = 0;
298 //_______________________________________________________________________
299 void AliKalmanTrack:: AddTimeStep(Double_t length)
302 // Add step to integrated time
303 // this method should be called by a sublasses at the end
304 // of the PropagateTo function or by a tracker
305 // each time step is made.
307 // If integration not started function does nothing
310 // dt = dl * sqrt(p^2 + m^2) / p
311 // p = pT * (1 + tg^2 (lambda) )
313 // pt = 1/external parameter [4]
314 // tg lambda = external parameter [3]
317 // Sylwester Radomski, GSI
321 static const Double_t kcc = 2.99792458e-2;
323 if (!fStartTimeIntegral) return;
325 fIntegratedLength += length;
327 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
328 TDatabasePDG *db = TDatabasePDG::Instance();
330 Double_t xr, param[5];
333 GetExternalParameters(xr, param);
337 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
339 if (length > 100) return;
341 for (Int_t i=0; i<fgkTypes; i++) {
343 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
344 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
345 Double_t time = length * correction / kcc;
347 //cout << mass << "\t" << pt << "\t" << p << "\t"
348 // << correction << endl;
350 fIntegratedTime[i] += time;
354 //_______________________________________________________________________
356 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
358 // Sylwester Radomski, GSI
361 // Return integrated time hypothesis for a given particle
365 // pdg - Pdg code of a particle type
369 if (!fStartTimeIntegral) {
370 Warning("GetIntegratedTime","Time integration not started");
374 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
376 for (Int_t i=0; i<fgkTypes; i++)
377 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
379 Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
383 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
384 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
387 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
388 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
391 //_______________________________________________________________________
393 void AliKalmanTrack::PrintTime() const
395 // Sylwester Radomski, GSI
399 // Prints time for all hypothesis
402 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
404 for (Int_t i=0; i<fgkTypes; i++)
405 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
409 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
410 //--------------------------------------------------------------------
411 // External track parameters -> helix parameters
412 //--------------------------------------------------------------------
413 Double_t alpha,x,cs,sn;
414 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
416 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
417 helix[5]=x*cs - helix[0]*sn; // x0
418 helix[0]=x*sn + helix[0]*cs; // y0
420 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
422 helix[4]=helix[4]/t->GetConvConst(); // C
425 static void Evaluate(const Double_t *h, Double_t t,
426 Double_t r[3], //radius vector
427 Double_t g[3], //first defivatives
428 Double_t gg[3]) //second derivatives
430 //--------------------------------------------------------------------
431 // Calculate position of a point on a track and some derivatives
432 //--------------------------------------------------------------------
433 Double_t phase=h[4]*t+h[2];
434 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
436 r[0] = h[5] + (sn - h[6])/h[4];
437 r[1] = h[0] - (cs - h[7])/h[4];
438 r[2] = h[1] + h[3]*t;
440 g[0] = cs; g[1]=sn; g[2]=h[3];
442 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
445 Double_t AliKalmanTrack::
446 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
447 //------------------------------------------------------------
448 // Returns the (weighed !) distance of closest approach between
449 // this track and the track passed as the argument.
450 // Other returned values:
451 // xthis, xt - coordinates of tracks' reference planes at the DCA
452 //-----------------------------------------------------------
453 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
454 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
459 Double_t p1[8]; External2Helix(this,p1);
460 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
461 Double_t p2[8]; External2Helix(p,p2);
462 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
465 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
466 Evaluate(p1,t1,r1,g1,gg1);
467 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
468 Evaluate(p2,t2,r2,g2,gg2);
470 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
471 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
475 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
476 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
477 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
478 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
479 (g1[2]*g1[2] - dz*gg1[2])/dz2;
480 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
481 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
482 (g2[2]*g2[2] + dz*gg2[2])/dz2;
483 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
485 Double_t det=h11*h22-h12*h12;
488 if (TMath::Abs(det)<1.e-33) {
489 //(quasi)singular Hessian
492 dt1=-(gt1*h22 - gt2*h12)/det;
493 dt2=-(h11*gt2 - h12*gt1)/det;
496 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
498 //check delta(phase1) ?
499 //check delta(phase2) ?
501 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
502 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
503 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
504 Warning("GetDCA"," stopped at not a stationary point !\n");
505 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
507 Warning("GetDCA"," stopped at not a minimum !\n");
512 for (Int_t div=1 ; ; div*=2) {
513 Evaluate(p1,t1+dt1,r1,g1,gg1);
514 Evaluate(p2,t2+dt2,r2,g2,gg2);
515 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
516 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
520 Warning("GetDCA"," overshoot !\n"); break;
530 if (max<=0) Warning("GetDCA"," too many iterations !\n");
532 Double_t cs=TMath::Cos(GetAlpha());
533 Double_t sn=TMath::Sin(GetAlpha());
534 xthis=r1[0]*cs + r1[1]*sn;
536 cs=TMath::Cos(p->GetAlpha());
537 sn=TMath::Sin(p->GetAlpha());
538 xp=r2[0]*cs + r2[1]*sn;
540 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
543 Double_t AliKalmanTrack::
544 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
545 //--------------------------------------------------------------
546 // Propagates this track and the argument track to the position of the
547 // distance of closest approach.
548 // Returns the (weighed !) distance of closest approach.
549 //--------------------------------------------------------------
551 Double_t dca=GetDCA(p,xthis,xp);
553 if (!PropagateTo(xthis,d,x0)) {
554 //Warning("PropagateToDCA"," propagation failed !\n");
558 if (!p->PropagateTo(xp,d,x0)) {
559 //Warning("PropagateToDCA"," propagation failed !\n";