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