Names changed in order to avoid clash with FLUKA
[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 //
43 if (fgConvConst==0)
e2afb3b6 44 Fatal("AliKalmanTrack()","The magnetic field has not been set !\n");
74f9526e 45
46 fStartTimeIntegral = kFALSE;
47 fIntegratedLength = 0;
48 for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
e2afb3b6 49}
50
51//_______________________________________________________________________
52AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
53 TObject(t),
54 fLab(t.fLab),
55 fChi2(t.fChi2),
56 fMass(t.fMass),
57 fN(t.fN)
58{
116cbefd 59 //
60 // Copy constructor
61 //
62 if (fgConvConst==0)
e2afb3b6 63 Fatal("AliKalmanTrack(const AliKalmanTrack&)",
64 "The magnetic field has not been set !\n");
74f9526e 65
66 fStartTimeIntegral = t.fStartTimeIntegral;
67 fIntegratedLength = t.fIntegratedLength;
68
69 for (Int_t i=0; i<5; i++)
70 fIntegratedTime[i] = t.fIntegratedTime[i];
71}
c5507f6d 72
73//_______________________________________________________________________
74Double_t AliKalmanTrack::GetX() const
75{
76 Warning("GetX()","Method must be overloaded !\n");
77 return 0.;
78}
79//_______________________________________________________________________
80Double_t AliKalmanTrack::GetdEdx() const
81{
82 Warning("GetdEdx()","Method must be overloaded !\n");
83 return 0.;
84}
85
86//_______________________________________________________________________
87Double_t AliKalmanTrack::GetY() const
88{
89 Double_t par[5];
90 Double_t localX = GetX();
91 GetExternalParameters(localX, par);
92 return par[0];
93}
94//_______________________________________________________________________
95Double_t AliKalmanTrack::GetZ() const
96{
97 Double_t par[5];
98 Double_t localX = GetX();
99 GetExternalParameters(localX, par);
100 return par[1];
101}
102//_______________________________________________________________________
103Double_t AliKalmanTrack::GetSnp() const
104{
105 Double_t par[5];
106 Double_t localX = GetX();
107 GetExternalParameters(localX, par);
108 return par[2];
109}
110//_______________________________________________________________________
111Double_t AliKalmanTrack::GetTgl() const
112{
113 Double_t par[5];
114 Double_t localX = GetX();
115 GetExternalParameters(localX, par);
116 return par[3];
117}
118//_______________________________________________________________________
119Double_t AliKalmanTrack::Get1Pt() const
120{
121 Double_t par[5];
122 Double_t localX = GetX();
123 GetExternalParameters(localX, par);
124 return par[4];
125}
126
127//_______________________________________________________________________
128Double_t AliKalmanTrack::Phi() const
129{
130// return global phi of track
131
132 Double_t par[5];
133 Double_t localX = GetX();
134 GetExternalParameters(localX, par);
79e94bf8 135 if (par[2] > 1.) par[2] = 1.;
136 if (par[2] < -1.) par[2] = -1.;
c5507f6d 137 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
138 while (phi < 0) phi += TMath::TwoPi();
139 while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
140 return phi;
141}
142//_______________________________________________________________________
143Double_t AliKalmanTrack::SigmaPhi() const
144{
145// return error of global phi of track
146
147 Double_t par[5];
148 Double_t cov[15];
149 Double_t localX = GetX();
150 GetExternalParameters(localX, par);
151 GetExternalCovariance(cov);
152 return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
153}
154//_______________________________________________________________________
155Double_t AliKalmanTrack::Theta() const
156{
157// return global theta of track
158
159 Double_t par[5];
160 Double_t localX = GetX();
161 GetExternalParameters(localX, par);
162 return TMath::Pi()/2. - TMath::ATan(par[3]);
163}
164//_______________________________________________________________________
165Double_t AliKalmanTrack::SigmaTheta() const
166{
167// return error of global theta of track
168
169 Double_t par[5];
170 Double_t cov[15];
171 Double_t localX = GetX();
172 GetExternalParameters(localX, par);
173 GetExternalCovariance(cov);
174 return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
175}
176//_______________________________________________________________________
177Double_t AliKalmanTrack::Px() const
178{
179// return x component of track momentum
180
181 Double_t par[5];
182 Double_t localX = GetX();
183 GetExternalParameters(localX, par);
184 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
185 return TMath::Cos(phi) / TMath::Abs(par[4]);
186}
187//_______________________________________________________________________
188Double_t AliKalmanTrack::Py() const
189{
190// return y component of track momentum
191
192 Double_t par[5];
193 Double_t localX = GetX();
194 GetExternalParameters(localX, par);
195 Double_t phi = TMath::ASin(par[2]) + GetAlpha();
196 return TMath::Sin(phi) / TMath::Abs(par[4]);
197}
198//_______________________________________________________________________
199Double_t AliKalmanTrack::Pz() const
200{
201// return z component of track momentum
202
203 Double_t par[5];
204 Double_t localX = GetX();
205 GetExternalParameters(localX, par);
206 return par[3] / TMath::Abs(par[4]);
207}
208//_______________________________________________________________________
209Double_t AliKalmanTrack::Pt() const
210{
211// return transverse component of track momentum
212
213 Double_t par[5];
214 Double_t localX = GetX();
215 GetExternalParameters(localX, par);
216 return 1. / TMath::Abs(par[4]);
217}
218//_______________________________________________________________________
219Double_t AliKalmanTrack::SigmaPt() const
220{
221// return error of transverse component of track momentum
222
223 Double_t par[5];
224 Double_t cov[15];
225 Double_t localX = GetX();
226 GetExternalParameters(localX, par);
227 GetExternalCovariance(cov);
228 return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
229}
230//_______________________________________________________________________
231Double_t AliKalmanTrack::P() const
232{
233// return total track momentum
234
235 Double_t par[5];
236 Double_t localX = GetX();
237 GetExternalParameters(localX, par);
79e94bf8 238 return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
c5507f6d 239}
240//_______________________________________________________________________
74f9526e 241void AliKalmanTrack::StartTimeIntegral()
242{
49a7a79a 243 // Sylwester Radomski, GSI
244 // S.Radomski@gsi.de
74f9526e 245 //
246 // Start time integration
247 // To be called at Vertex by ITS tracker
248 //
249
250 //if (fStartTimeIntegral)
251 // Warning("StartTimeIntegral", "Reseting Recorded Time.");
252
253 fStartTimeIntegral = kTRUE;
5d8718b8 254 for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;
74f9526e 255 fIntegratedLength = 0;
256}
257//_______________________________________________________________________
258void AliKalmanTrack:: AddTimeStep(Double_t length)
259{
260 //
261 // Add step to integrated time
262 // this method should be called by a sublasses at the end
263 // of the PropagateTo function or by a tracker
264 // each time step is made.
265 //
266 // If integration not started function does nothing
267 //
268 // Formula
269 // dt = dl * sqrt(p^2 + m^2) / p
270 // p = pT * (1 + tg^2 (lambda) )
271 //
272 // pt = 1/external parameter [4]
273 // tg lambda = external parameter [3]
274 //
275 //
276 // Sylwester Radomski, GSI
277 // S.Radomski@gsi.de
278 //
279
5d8718b8 280 static const Double_t kcc = 2.99792458e-2;
74f9526e 281
282 if (!fStartTimeIntegral) return;
283
284 fIntegratedLength += length;
285
5d8718b8 286 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
74f9526e 287 TDatabasePDG *db = TDatabasePDG::Instance();
288
289 Double_t xr, param[5];
290 Double_t pt, tgl;
291
292 GetExternalParameters(xr, param);
293 pt = 1/param[4] ;
294 tgl = param[3];
295
296 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
297
298 if (length > 100) return;
299
5d8718b8 300 for (Int_t i=0; i<fgkTypes; i++) {
74f9526e 301
302 Double_t mass = db->GetParticle(pdgCode[i])->Mass();
303 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
5d8718b8 304 Double_t time = length * correction / kcc;
74f9526e 305
306 //cout << mass << "\t" << pt << "\t" << p << "\t"
307 // << correction << endl;
308
309 fIntegratedTime[i] += time;
310 }
e2afb3b6 311}
312
74f9526e 313//_______________________________________________________________________
314
315Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
316{
49a7a79a 317 // Sylwester Radomski, GSI
318 // S.Radomski@gsi.de
74f9526e 319 //
320 // Return integrated time hypothesis for a given particle
321 // type assumption.
322 //
323 // Input parameter:
324 // pdg - Pdg code of a particle type
325 //
326
327
328 if (!fStartTimeIntegral) {
329 Warning("GetIntegratedTime","Time integration not started");
330 return 0.;
331 }
332
5d8718b8 333 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
74f9526e 334
5d8718b8 335 for (Int_t i=0; i<fgkTypes; i++)
74f9526e 336 if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
337
338 Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
339 return 0;
340}
ae982df3 341
342void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
343 for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
344}
345
346void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
347 for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
348}
349
74f9526e 350//_______________________________________________________________________
351
352void AliKalmanTrack::PrintTime() const
353{
49a7a79a 354 // Sylwester Radomski, GSI
355 // S.Radomski@gsi.de
356 //
74f9526e 357 // For testing
358 // Prints time for all hypothesis
359 //
360
5d8718b8 361 static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
74f9526e 362
5d8718b8 363 for (Int_t i=0; i<fgkTypes; i++)
74f9526e 364 printf("%d: %.2f ", pdgCode[i], fIntegratedTime[i]);
365 printf("\n");
366}
367
49a7a79a 368static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) {
369 //--------------------------------------------------------------------
370 // External track parameters -> helix parameters
371 //--------------------------------------------------------------------
372 Double_t alpha,x,cs,sn;
373 t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
374
375 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
376 helix[5]=x*cs - helix[0]*sn; // x0
377 helix[0]=x*sn + helix[0]*cs; // y0
378//helix[1]= // z0
379 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
380//helix[3]= // tgl
381 helix[4]=helix[4]/t->GetConvConst(); // C
382}
383
384static void Evaluate(const Double_t *h, Double_t t,
385 Double_t r[3], //radius vector
386 Double_t g[3], //first defivatives
387 Double_t gg[3]) //second derivatives
388{
389 //--------------------------------------------------------------------
390 // Calculate position of a point on a track and some derivatives
391 //--------------------------------------------------------------------
392 Double_t phase=h[4]*t+h[2];
393 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
394
395 r[0] = h[5] + (sn - h[6])/h[4];
396 r[1] = h[0] - (cs - h[7])/h[4];
397 r[2] = h[1] + h[3]*t;
398
399 g[0] = cs; g[1]=sn; g[2]=h[3];
400
401 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
402}
403
404Double_t AliKalmanTrack::
405GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
406 //------------------------------------------------------------
407 // Returns the (weighed !) distance of closest approach between
408 // this track and the track passed as the argument.
409 // Other returned values:
410 // xthis, xt - coordinates of tracks' reference planes at the DCA
411 //-----------------------------------------------------------
412 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
413 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
414 Double_t dx2=dy2;
415
416 //dx2=dy2=dz2=1.;
417
418 Double_t p1[8]; External2Helix(this,p1);
419 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
420 Double_t p2[8]; External2Helix(p,p2);
421 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
422
423
424 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
425 Evaluate(p1,t1,r1,g1,gg1);
426 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
427 Evaluate(p2,t2,r2,g2,gg2);
74f9526e 428
49a7a79a 429 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
430 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
431
432 Int_t max=27;
433 while (max--) {
434 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
435 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
436 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
437 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
438 (g1[2]*g1[2] - dz*gg1[2])/dz2;
439 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
440 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
441 (g2[2]*g2[2] + dz*gg2[2])/dz2;
442 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
443
444 Double_t det=h11*h22-h12*h12;
445
446 Double_t dt1,dt2;
447 if (TMath::Abs(det)<1.e-33) {
448 //(quasi)singular Hessian
449 dt1=-gt1; dt2=-gt2;
450 } else {
451 dt1=-(gt1*h22 - gt2*h12)/det;
452 dt2=-(h11*gt2 - h12*gt1)/det;
453 }
454
455 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
456
457 //check delta(phase1) ?
458 //check delta(phase2) ?
459
460 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
461 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
462 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
463 Warning("GetDCA"," stopped at not a stationary point !\n");
464 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
465 if (lmb < 0.)
466 Warning("GetDCA"," stopped at not a minimum !\n");
467 break;
468 }
469
470 Double_t dd=dm;
471 for (Int_t div=1 ; ; div*=2) {
472 Evaluate(p1,t1+dt1,r1,g1,gg1);
473 Evaluate(p2,t2+dt2,r2,g2,gg2);
474 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
475 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
476 if (dd<dm) break;
477 dt1*=0.5; dt2*=0.5;
478 if (div>512) {
479 Warning("GetDCA"," overshoot !\n"); break;
480 }
481 }
482 dm=dd;
483
484 t1+=dt1;
485 t2+=dt2;
486
487 }
488
489 if (max<=0) Warning("GetDCA"," too many iterations !\n");
490
491 Double_t cs=TMath::Cos(GetAlpha());
492 Double_t sn=TMath::Sin(GetAlpha());
493 xthis=r1[0]*cs + r1[1]*sn;
494
495 cs=TMath::Cos(p->GetAlpha());
496 sn=TMath::Sin(p->GetAlpha());
497 xp=r2[0]*cs + r2[1]*sn;
498
499 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
500}
501
502Double_t AliKalmanTrack::
503PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
504 //--------------------------------------------------------------
505 // Propagates this track and the argument track to the position of the
506 // distance of closest approach.
507 // Returns the (weighed !) distance of closest approach.
508 //--------------------------------------------------------------
509 Double_t xthis,xp;
510 Double_t dca=GetDCA(p,xthis,xp);
511
512 if (!PropagateTo(xthis,d,x0)) {
513 //Warning("PropagateToDCA"," propagation failed !\n");
514 return 1e+33;
515 }
516
517 if (!p->PropagateTo(xp,d,x0)) {
518 //Warning("PropagateToDCA"," propagation failed !\n";
519 return 1e+33;
520 }
521
522 return dca;
523}