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 ::Info("SetConvConst()", "tryinig to get the magnetic field from the AliRun object...");
85 AliRunLoader* loader = AliRunLoader::GetRunLoader();
86 if (!loader) ::Fatal("SetConvConst()", "No run loader found");
87 if (!loader->GetAliRun()) loader->LoadgAlice();
88 AliRun* alirun = loader->GetAliRun();
89 if (!alirun) ::Fatal("SetConvConst()", "No AliRun object found");
91 Double_t field = alirun->Field()->SolenoidField();
92 SetConvConst(1000/0.299792458/field);
93 ::Info("SetConvConst()", "Magnetic field set to %f kGauss\n", field);
96 //_______________________________________________________________________
97 Double_t AliKalmanTrack::GetX() const
99 Warning("GetX()","Method must be overloaded !\n");
102 //_______________________________________________________________________
103 Double_t AliKalmanTrack::GetdEdx() const
105 Warning("GetdEdx()","Method must be overloaded !\n");
109 //_______________________________________________________________________
110 Double_t AliKalmanTrack::GetY() const
113 Double_t localX = GetX();
114 GetExternalParameters(localX, par);
117 //_______________________________________________________________________
118 Double_t AliKalmanTrack::GetZ() const
121 Double_t localX = GetX();
122 GetExternalParameters(localX, par);
125 //_______________________________________________________________________
126 Double_t AliKalmanTrack::GetSnp() const
129 Double_t localX = GetX();
130 GetExternalParameters(localX, par);
133 //_______________________________________________________________________
134 Double_t AliKalmanTrack::GetTgl() const
137 Double_t localX = GetX();
138 GetExternalParameters(localX, par);
141 //_______________________________________________________________________
142 Double_t AliKalmanTrack::Get1Pt() const
145 Double_t localX = GetX();
146 GetExternalParameters(localX, par);
150 //_______________________________________________________________________
151 Double_t AliKalmanTrack::Phi() const
153 // return global phi of track
156 Double_t localX = GetX();
157 GetExternalParameters(localX, par);
158 if (par[2] > 1.) par[2] = 1.;
159 if (par[2] < -1.) par[2] = -1.;
160 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
161 while (phi < 0) phi += TMath::TwoPi();
162 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
165 //_______________________________________________________________________
166 Double_t AliKalmanTrack::SigmaPhi() const
168 // return error of global phi of track
172 Double_t localX = GetX();
173 GetExternalParameters(localX, par);
174 GetExternalCovariance(cov);
175 return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
177 //_______________________________________________________________________
178 Double_t AliKalmanTrack::Theta() const
180 // return global theta of track
183 Double_t localX = GetX();
184 GetExternalParameters(localX, par);
185 return TMath::Pi()/2. - TMath::ATan(par[3]);
187 //_______________________________________________________________________
188 Double_t AliKalmanTrack::SigmaTheta() const
190 // return error of global theta of track
194 Double_t localX = GetX();
195 GetExternalParameters(localX, par);
196 GetExternalCovariance(cov);
197 return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
199 //_______________________________________________________________________
200 Double_t AliKalmanTrack::Eta() const
202 // return global eta of track
204 return -TMath::Log(TMath::Tan(Theta()/2.));
206 //_______________________________________________________________________
207 Double_t AliKalmanTrack::Px() const
209 // return x 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::Cos(phi) / TMath::Abs(par[4]);
217 //_______________________________________________________________________
218 Double_t AliKalmanTrack::Py() const
220 // return y 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::Sin(phi) / TMath::Abs(par[4]);
228 //_______________________________________________________________________
229 Double_t AliKalmanTrack::Pz() const
231 // return z component of track momentum
234 Double_t localX = GetX();
235 GetExternalParameters(localX, par);
236 return par[3] / TMath::Abs(par[4]);
238 //_______________________________________________________________________
239 Double_t AliKalmanTrack::Pt() const
241 // return transverse component of track momentum
244 Double_t localX = GetX();
245 GetExternalParameters(localX, par);
246 return 1. / TMath::Abs(par[4]);
248 //_______________________________________________________________________
249 Double_t AliKalmanTrack::SigmaPt() const
251 // return error of transverse component of track momentum
255 Double_t localX = GetX();
256 GetExternalParameters(localX, par);
257 GetExternalCovariance(cov);
258 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
260 //_______________________________________________________________________
261 Double_t AliKalmanTrack::P() const
263 // return total track momentum
266 Double_t localX = GetX();
267 GetExternalParameters(localX, par);
268 return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
270 //_______________________________________________________________________
271 void AliKalmanTrack::StartTimeIntegral()
273 // Sylwester Radomski, GSI
276 // Start time integration
277 // To be called at Vertex by ITS tracker
280 //if (fStartTimeIntegral)
281 // Warning("StartTimeIntegral", "Reseting Recorded Time.");
283 fStartTimeIntegral = kTRUE;
284 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
285 fIntegratedLength = 0;
287 //_______________________________________________________________________
288 void AliKalmanTrack:: AddTimeStep(Double_t length)
291 // Add step to integrated time
292 // this method should be called by a sublasses at the end
293 // of the PropagateTo function or by a tracker
294 // each time step is made.
296 // If integration not started function does nothing
299 // dt = dl * sqrt(p^2 + m^2) / p
300 // p = pT * (1 + tg^2 (lambda) )
302 // pt = 1/external parameter [4]
303 // tg lambda = external parameter [3]
306 // Sylwester Radomski, GSI
310 static const Double_t kcc = 2.99792458e-2;
312 if (!fStartTimeIntegral) return;
314 fIntegratedLength += length;
316 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
317 TDatabasePDG *db = TDatabasePDG::Instance();
319 Double_t xr, param[5];
322 GetExternalParameters(xr, param);
326 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
328 if (length > 100) return;
330 for (Int_t i=0; i<fgkTypes; i++) {
332 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
333 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
334 Double_t time = length * correction / kcc;
336 //cout << mass << "\t" << pt << "\t" << p << "\t"
337 // << correction << endl;
339 fIntegratedTime[i] += time;
343 //_______________________________________________________________________
345 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
347 // Sylwester Radomski, GSI
350 // Return integrated time hypothesis for a given particle
354 // pdg - Pdg code of a particle type
358 if (!fStartTimeIntegral) {
359 Warning("GetIntegratedTime","Time integration not started");
363 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
365 for (Int_t i=0; i<fgkTypes; i++)
366 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
368 Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
372 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
373 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
376 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
377 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
380 //_______________________________________________________________________
382 void AliKalmanTrack::PrintTime() const
384 // Sylwester Radomski, GSI
388 // Prints time for all hypothesis
391 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
393 for (Int_t i=0; i<fgkTypes; i++)
394 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
398 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
399 //--------------------------------------------------------------------
400 // External track parameters -> helix parameters
401 //--------------------------------------------------------------------
402 Double_t alpha,x,cs,sn;
403 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
405 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
406 helix[5]=x*cs - helix[0]*sn; // x0
407 helix[0]=x*sn + helix[0]*cs; // y0
409 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
411 helix[4]=helix[4]/t->GetConvConst(); // C
414 static void Evaluate(const Double_t *h, Double_t t,
415 Double_t r[3], //radius vector
416 Double_t g[3], //first defivatives
417 Double_t gg[3]) //second derivatives
419 //--------------------------------------------------------------------
420 // Calculate position of a point on a track and some derivatives
421 //--------------------------------------------------------------------
422 Double_t phase=h[4]*t+h[2];
423 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
425 r[0] = h[5] + (sn - h[6])/h[4];
426 r[1] = h[0] - (cs - h[7])/h[4];
427 r[2] = h[1] + h[3]*t;
429 g[0] = cs; g[1]=sn; g[2]=h[3];
431 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
434 Double_t AliKalmanTrack::
435 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
436 //------------------------------------------------------------
437 // Returns the (weighed !) distance of closest approach between
438 // this track and the track passed as the argument.
439 // Other returned values:
440 // xthis, xt - coordinates of tracks' reference planes at the DCA
441 //-----------------------------------------------------------
442 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
443 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
448 Double_t p1[8]; External2Helix(this,p1);
449 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
450 Double_t p2[8]; External2Helix(p,p2);
451 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
454 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
455 Evaluate(p1,t1,r1,g1,gg1);
456 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
457 Evaluate(p2,t2,r2,g2,gg2);
459 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
460 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
464 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
465 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
466 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
467 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
468 (g1[2]*g1[2] - dz*gg1[2])/dz2;
469 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
470 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
471 (g2[2]*g2[2] + dz*gg2[2])/dz2;
472 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
474 Double_t det=h11*h22-h12*h12;
477 if (TMath::Abs(det)<1.e-33) {
478 //(quasi)singular Hessian
481 dt1=-(gt1*h22 - gt2*h12)/det;
482 dt2=-(h11*gt2 - h12*gt1)/det;
485 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
487 //check delta(phase1) ?
488 //check delta(phase2) ?
490 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
491 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
492 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
493 Warning("GetDCA"," stopped at not a stationary point !\n");
494 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
496 Warning("GetDCA"," stopped at not a minimum !\n");
501 for (Int_t div=1 ; ; div*=2) {
502 Evaluate(p1,t1+dt1,r1,g1,gg1);
503 Evaluate(p2,t2+dt2,r2,g2,gg2);
504 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
505 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
509 Warning("GetDCA"," overshoot !\n"); break;
519 if (max<=0) Warning("GetDCA"," too many iterations !\n");
521 Double_t cs=TMath::Cos(GetAlpha());
522 Double_t sn=TMath::Sin(GetAlpha());
523 xthis=r1[0]*cs + r1[1]*sn;
525 cs=TMath::Cos(p->GetAlpha());
526 sn=TMath::Sin(p->GetAlpha());
527 xp=r2[0]*cs + r2[1]*sn;
529 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
532 Double_t AliKalmanTrack::
533 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
534 //--------------------------------------------------------------
535 // Propagates this track and the argument track to the position of the
536 // distance of closest approach.
537 // Returns the (weighed !) distance of closest approach.
538 //--------------------------------------------------------------
540 Double_t dca=GetDCA(p,xthis,xp);
542 if (!PropagateTo(xthis,d,x0)) {
543 //Warning("PropagateToDCA"," propagation failed !\n");
547 if (!p->PropagateTo(xp,d,x0)) {
548 //Warning("PropagateToDCA"," propagation failed !\n";