]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliKalmanTrack.cxx
Moving lib*.pkg
[u/mrichter/AliRoot.git] / STEER / AliKalmanTrack.cxx
CommitLineData
87594435 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
acd84897 16/* $Id$ */
fb17acd4 17
87594435 18//-------------------------------------------------------------------------
19// Implementation of the AliKalmanTrack class
066782e8 20// that is the base for AliTPCtrack, AliITStrackV2 and AliTRDtrack
87594435 21// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22//-------------------------------------------------------------------------
23
24#include "AliKalmanTrack.h"
74f9526e 25#include "AliPDG.h"
26#include "TPDGCode.h"
27#include "TDatabasePDG.h"
87594435 28
29ClassImp(AliKalmanTrack)
30
116cbefd 31Double_t AliKalmanTrack::fgConvConst;
9b280d80 32
e2afb3b6 33//_______________________________________________________________________
34AliKalmanTrack::AliKalmanTrack():
35 fLab(-3141593),
36 fChi2(0),
37 fMass(0.13957),
38 fN(0)
39{
116cbefd 40 //
41 // Default constructor
42 //
8de97894 43 if (fgConvConst==0) {
9b859005 44 Fatal("AliKalmanTrack()", "The magnetic field has not been set!");
8de97894 45 }
74f9526e 46
47 fStartTimeIntegral = kFALSE;
48 fIntegratedLength = 0;
49 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
e2afb3b6 50}
51
52//_______________________________________________________________________
53AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
54 TObject(t),
55 fLab(t.fLab),
babd135a 56 fFakeRatio(t.fFakeRatio),
e2afb3b6 57 fChi2(t.fChi2),
58 fMass(t.fMass),
59 fN(t.fN)
60{
116cbefd 61 //
62 // Copy constructor
63 //
8de97894 64 if (fgConvConst==0) {
9b859005 65 Fatal("AliKalmanTrack(const AliKalmanTrack&)",
8de97894 66 "The magnetic field has not been set!");
8de97894 67 }
74f9526e 68
69 fStartTimeIntegral = t.fStartTimeIntegral;
70 fIntegratedLength = t.fIntegratedLength;
71
72 for (Int_t i=0; i<5; i++)
73 fIntegratedTime[i] = t.fIntegratedTime[i];
74}
c5507f6d 75
76//_______________________________________________________________________
77Double_t AliKalmanTrack::GetX() const
78{
fc7be9e3 79 // Returns the X coordinate of the current track position
c5507f6d 80 Warning("GetX()","Method must be overloaded !\n");
81 return 0.;
82}
83//_______________________________________________________________________
84Double_t AliKalmanTrack::GetdEdx() const
85{
fc7be9e3 86 // Returns the dE/dx of the track
c5507f6d 87 Warning("GetdEdx()","Method must be overloaded !\n");
88 return 0.;
89}
90
91//_______________________________________________________________________
92Double_t AliKalmanTrack::GetY() const
93{
fc7be9e3 94 // Returns the Y coordinate of the current track position
c5507f6d 95 Double_t par[5];
96 Double_t localX = GetX();
97 GetExternalParameters(localX, par);
98 return par[0];
99}
100//_______________________________________________________________________
101Double_t AliKalmanTrack::GetZ() const
102{
fc7be9e3 103 // Returns the Z coordinate of the current track position
c5507f6d 104 Double_t par[5];
105 Double_t localX = GetX();
106 GetExternalParameters(localX, par);
107 return par[1];
108}
109//_______________________________________________________________________
110Double_t AliKalmanTrack::GetSnp() const
111{
fc7be9e3 112 // Returns the Sin(phi), where phi is the angle between the transverse
113 // momentum (in xOy plane) and the X axis
c5507f6d 114 Double_t par[5];
115 Double_t localX = GetX();
116 GetExternalParameters(localX, par);
117 return par[2];
118}
119//_______________________________________________________________________
120Double_t AliKalmanTrack::GetTgl() const
121{
fc7be9e3 122 // Returns the Tan(lambda), where lambda is the dip angle (between
123 // the bending plane (xOy) and the momentum of the track
c5507f6d 124 Double_t par[5];
125 Double_t localX = GetX();
126 GetExternalParameters(localX, par);
127 return par[3];
128}
129//_______________________________________________________________________
130Double_t AliKalmanTrack::Get1Pt() const
131{
fc7be9e3 132 // Returns 1/pT
c5507f6d 133 Double_t par[5];
134 Double_t localX = GetX();
135 GetExternalParameters(localX, par);
136 return par[4];
137}
138
139//_______________________________________________________________________
140Double_t AliKalmanTrack::Phi() const
141{
142// return global phi of track
143
144 Double_t par[5];
145 Double_t localX = GetX();
146 GetExternalParameters(localX, par);
79e94bf8 147 if (par[2] > 1.) par[2] = 1.;
148 if (par[2] < -1.) par[2] = -1.;
c5507f6d 149 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
150 while (phi < 0) phi += TMath::TwoPi();
151 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
152 return phi;
153}
154//_______________________________________________________________________
155Double_t AliKalmanTrack::SigmaPhi() const
156{
157// return error of global phi of track
158
159 Double_t par[5];
160 Double_t cov[15];
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])));
165}
166//_______________________________________________________________________
167Double_t AliKalmanTrack::Theta() const
168{
169// return global theta of track
170
171 Double_t par[5];
172 Double_t localX = GetX();
173 GetExternalParameters(localX, par);
174 return TMath::Pi()/2. - TMath::ATan(par[3]);
175}
176//_______________________________________________________________________
177Double_t AliKalmanTrack::SigmaTheta() const
178{
179// return error of global theta of track
180
181 Double_t par[5];
182 Double_t cov[15];
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]);
187}
188//_______________________________________________________________________
8de97894 189Double_t AliKalmanTrack::Eta() const
190{
191// return global eta of track
192
193 return -TMath::Log(TMath::Tan(Theta()/2.));
194}
195//_______________________________________________________________________
c5507f6d 196Double_t AliKalmanTrack::Px() const
197{
198// return x component of track momentum
199
200 Double_t par[5];
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]);
205}
206//_______________________________________________________________________
207Double_t AliKalmanTrack::Py() const
208{
209// return y component of track momentum
210
211 Double_t par[5];
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]);
216}
217//_______________________________________________________________________
218Double_t AliKalmanTrack::Pz() const
219{
220// return z component of track momentum
221
222 Double_t par[5];
223 Double_t localX = GetX();
224 GetExternalParameters(localX, par);
225 return par[3] / TMath::Abs(par[4]);
226}
227//_______________________________________________________________________
228Double_t AliKalmanTrack::Pt() const
229{
230// return transverse component of track momentum
231
232 Double_t par[5];
233 Double_t localX = GetX();
234 GetExternalParameters(localX, par);
235 return 1. / TMath::Abs(par[4]);
236}
237//_______________________________________________________________________
238Double_t AliKalmanTrack::SigmaPt() const
239{
240// return error of transverse component of track momentum
241
242 Double_t par[5];
243 Double_t cov[15];
244 Double_t localX = GetX();
245 GetExternalParameters(localX, par);
246 GetExternalCovariance(cov);
247 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
248}
249//_______________________________________________________________________
250Double_t AliKalmanTrack::P() const
251{
252// return total track momentum
253
254 Double_t par[5];
255 Double_t localX = GetX();
256 GetExternalParameters(localX, par);
79e94bf8 257 return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
c5507f6d 258}
74f9526e 259//_______________________________________________________________________
260void AliKalmanTrack::StartTimeIntegral()
261{
49a7a79a 262 // Sylwester Radomski, GSI
263 // S.Radomski@gsi.de
74f9526e 264 //
265 // Start time integration
266 // To be called at Vertex by ITS tracker
267 //
268
269 //if (fStartTimeIntegral)
270 // Warning("StartTimeIntegral", "Reseting Recorded Time.");
271
272 fStartTimeIntegral = kTRUE;
5d8718b8 273 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
74f9526e 274 fIntegratedLength = 0;
275}
276//_______________________________________________________________________
277void AliKalmanTrack:: AddTimeStep(Double_t length)
278{
279 //
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.
284 //
285 // If integration not started function does nothing
286 //
287 // Formula
288 // dt = dl * sqrt(p^2 + m^2) / p
289 // p = pT * (1 + tg^2 (lambda) )
290 //
291 // pt = 1/external parameter [4]
292 // tg lambda = external parameter [3]
293 //
294 //
295 // Sylwester Radomski, GSI
296 // S.Radomski@gsi.de
297 //
298
5d8718b8 299 static const Double_t kcc = 2.99792458e-2;
74f9526e 300
301 if (!fStartTimeIntegral) return;
302
303 fIntegratedLength += length;
304
5d8718b8 305 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
74f9526e 306 TDatabasePDG *db = TDatabasePDG::Instance();
307
308 Double_t xr, param[5];
309 Double_t pt, tgl;
310
311 GetExternalParameters(xr, param);
312 pt = 1/param[4] ;
313 tgl = param[3];
314
315 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
316
317 if (length > 100) return;
318
5d8718b8 319 for (Int_t i=0; i<fgkTypes; i++) {
74f9526e 320
321 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
322 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
5d8718b8 323 Double_t time = length * correction / kcc;
74f9526e 324
74f9526e 325 fIntegratedTime[i] += time;
326 }
e2afb3b6 327}
328
74f9526e 329//_______________________________________________________________________
330
331Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
332{
49a7a79a 333 // Sylwester Radomski, GSI
334 // S.Radomski@gsi.de
74f9526e 335 //
336 // Return integrated time hypothesis for a given particle
337 // type assumption.
338 //
339 // Input parameter:
340 // pdg - Pdg code of a particle type
341 //
342
343
344 if (!fStartTimeIntegral) {
345 Warning("GetIntegratedTime","Time integration not started");
346 return 0.;
347 }
348
5d8718b8 349 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
74f9526e 350
5d8718b8 351 for (Int_t i=0; i<fgkTypes; i++)
74f9526e 352 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
353
354 Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
355 return 0;
356}
ae982df3 357
358void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
359 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
360}
361
362void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
363 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
364}
365
74f9526e 366//_______________________________________________________________________
367
368void AliKalmanTrack::PrintTime() const
369{
49a7a79a 370 // Sylwester Radomski, GSI
371 // S.Radomski@gsi.de
372 //
74f9526e 373 // For testing
374 // Prints time for all hypothesis
375 //
376
5d8718b8 377 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
74f9526e 378
5d8718b8 379 for (Int_t i=0; i<fgkTypes; i++)
74f9526e 380 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
381 printf("\n");
382}
383
49a7a79a 384static 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();
390
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
394//helix[1]= // z0
395 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
396//helix[3]= // tgl
397 helix[4]=helix[4]/t->GetConvConst(); // C
398}
399
400static 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
404{
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);
410
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;
414
415 g[0] = cs; g[1]=sn; g[2]=h[3];
416
417 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
418}
419
420Double_t AliKalmanTrack::
421GetDCA(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();
430 Double_t dx2=dy2;
431
432 //dx2=dy2=dz2=1.;
433
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]);
438
439
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);
74f9526e 444
49a7a79a 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;
447
448 Int_t max=27;
449 while (max--) {
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);
459
460 Double_t det=h11*h22-h12*h12;
461
462 Double_t dt1,dt2;
463 if (TMath::Abs(det)<1.e-33) {
464 //(quasi)singular Hessian
465 dt1=-gt1; dt2=-gt2;
466 } else {
467 dt1=-(gt1*h22 - gt2*h12)/det;
468 dt2=-(h11*gt2 - h12*gt1)/det;
469 }
470
471 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
472
473 //check delta(phase1) ?
474 //check delta(phase2) ?
475
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 Warning("GetDCA"," stopped at not a stationary point !\n");
480 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
481 if (lmb < 0.)
482 Warning("GetDCA"," stopped at not a minimum !\n");
483 break;
484 }
485
486 Double_t dd=dm;
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;
492 if (dd<dm) break;
493 dt1*=0.5; dt2*=0.5;
494 if (div>512) {
495 Warning("GetDCA"," overshoot !\n"); break;
496 }
497 }
498 dm=dd;
499
500 t1+=dt1;
501 t2+=dt2;
502
503 }
504
505 if (max<=0) Warning("GetDCA"," too many iterations !\n");
506
507 Double_t cs=TMath::Cos(GetAlpha());
508 Double_t sn=TMath::Sin(GetAlpha());
509 xthis=r1[0]*cs + r1[1]*sn;
510
511 cs=TMath::Cos(p->GetAlpha());
512 sn=TMath::Sin(p->GetAlpha());
513 xp=r2[0]*cs + r2[1]*sn;
514
515 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
516}
517
518Double_t AliKalmanTrack::
519PropagateToDCA(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 //--------------------------------------------------------------
525 Double_t xthis,xp;
526 Double_t dca=GetDCA(p,xthis,xp);
527
528 if (!PropagateTo(xthis,d,x0)) {
529 //Warning("PropagateToDCA"," propagation failed !\n");
530 return 1e+33;
531 }
532
533 if (!p->PropagateTo(xp,d,x0)) {
534 //Warning("PropagateToDCA"," propagation failed !\n";
535 return 1e+33;
536 }
537
538 return dca;
539}