Getters for the inner and outer track parameters. Fix of the PropagateToDCA (M.Ivanov)
[u/mrichter/AliRoot.git] / STEER / AliExternalTrackParam.cxx
CommitLineData
51ad6848 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
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
49d13e89 20// Implementation of the external track parameterisation class. //
51ad6848 21// //
49d13e89 22// This parameterisation is used to exchange tracks between the detectors. //
23// A set of functions returning the position and the momentum of tracks //
24// in the global coordinate system as well as the track impact parameters //
25// are implemented.
26// Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch //
51ad6848 27///////////////////////////////////////////////////////////////////////////////
51ad6848 28#include "AliExternalTrackParam.h"
29#include "AliKalmanTrack.h"
5b77d93c 30#include "AliTracker.h"
edc97986 31#include "AliStrLine.h"
5b77d93c 32
51ad6848 33
34ClassImp(AliExternalTrackParam)
35
51ad6848 36//_____________________________________________________________________________
90e48c0c 37AliExternalTrackParam::AliExternalTrackParam() :
90e48c0c 38 fX(0),
c9ec41e8 39 fAlpha(0)
51ad6848 40{
90e48c0c 41 //
42 // default constructor
43 //
c9ec41e8 44 for (Int_t i = 0; i < 5; i++) fP[i] = 0;
45 for (Int_t i = 0; i < 15; i++) fC[i] = 0;
51ad6848 46}
47
48//_____________________________________________________________________________
49AliExternalTrackParam::AliExternalTrackParam(Double_t x, Double_t alpha,
50 const Double_t param[5],
90e48c0c 51 const Double_t covar[15]) :
90e48c0c 52 fX(x),
c9ec41e8 53 fAlpha(alpha)
51ad6848 54{
90e48c0c 55 //
56 // create external track parameters from given arguments
57 //
c9ec41e8 58 for (Int_t i = 0; i < 5; i++) fP[i] = param[i];
59 for (Int_t i = 0; i < 15; i++) fC[i] = covar[i];
51ad6848 60}
61
90e48c0c 62//_____________________________________________________________________________
63AliExternalTrackParam::AliExternalTrackParam(const AliKalmanTrack& track) :
c9ec41e8 64 fAlpha(track.GetAlpha())
51ad6848 65{
66 //
67 //
c9ec41e8 68 track.GetExternalParameters(fX,fP);
69 track.GetExternalCovariance(fC);
51ad6848 70}
71
51ad6848 72//_____________________________________________________________________________
c9ec41e8 73void AliExternalTrackParam::Set(const AliKalmanTrack& track) {
74 //
75 //
76 fAlpha=track.GetAlpha();
77 track.GetExternalParameters(fX,fP);
78 track.GetExternalCovariance(fC);
51ad6848 79}
80
81//_____________________________________________________________________________
c9ec41e8 82void AliExternalTrackParam::Reset() {
83 fX=fAlpha=0.;
84 for (Int_t i = 0; i < 5; i++) fP[i] = 0;
85 for (Int_t i = 0; i < 15; i++) fC[i] = 0;
51ad6848 86}
87
c9ec41e8 88Double_t AliExternalTrackParam::GetP() const {
89 //---------------------------------------------------------------------
90 // This function returns the track momentum
91 // Results for (nearly) straight tracks are meaningless !
92 //---------------------------------------------------------------------
93 if (TMath::Abs(fP[4])<=0) return 0;
94 return TMath::Sqrt(1.+ fP[3]*fP[3])/TMath::Abs(fP[4]);
51ad6848 95}
96
c9ec41e8 97//_______________________________________________________________________
c7bafca9 98Double_t AliExternalTrackParam::GetD(Double_t x,Double_t y,Double_t b) const {
c9ec41e8 99 //------------------------------------------------------------------
100 // This function calculates the transverse impact parameter
101 // with respect to a point with global coordinates (x,y)
102 // in the magnetic field "b" (kG)
103 //------------------------------------------------------------------
49d13e89 104 Double_t rp4=kB2C*b*fP[4];
c9ec41e8 105
106 Double_t xt=fX, yt=fP[0];
107
108 Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
109 Double_t a = x*cs + y*sn;
110 y = -x*sn + y*cs; x=a;
111 xt-=x; yt-=y;
112
113 sn=rp4*xt - fP[2]; cs=rp4*yt + TMath::Sqrt(1.- fP[2]*fP[2]);
114 a=2*(xt*fP[2] - yt*TMath::Sqrt(1.- fP[2]*fP[2]))-rp4*(xt*xt + yt*yt);
115 if (rp4<0) a=-a;
116 return a/(1 + TMath::Sqrt(sn*sn + cs*cs));
51ad6848 117}
118
49d13e89 119//_______________________________________________________________________
120Double_t AliExternalTrackParam::GetLinearD(Double_t xv,Double_t yv) const {
121 //------------------------------------------------------------------
122 // This function calculates the transverse impact parameter
123 // with respect to a point with global coordinates (xv,yv)
124 // neglecting the track curvature.
125 //------------------------------------------------------------------
126 Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
127 Double_t x= xv*cs + yv*sn;
128 Double_t y=-xv*sn + yv*cs;
129
130 Double_t d = (fX-x)*fP[2] - (fP[0]-y)*TMath::Sqrt(1.- fP[2]*fP[2]);
131
132 return d;
133}
134
c7bafca9 135Bool_t AliExternalTrackParam::
136CorrectForMaterial(Double_t d, Double_t x0, Double_t mass) {
137 //------------------------------------------------------------------
138 // This function corrects the track parameters for the crossed material
139 // "d" - the thickness (fraction of the radiation length)
140 // "x0" - the radiation length (g/cm^2)
141 // "mass" - the mass of this particle (GeV/c^2)
142 //------------------------------------------------------------------
143 Double_t &fP2=fP[2];
144 Double_t &fP3=fP[3];
145 Double_t &fP4=fP[4];
146
147 Double_t &fC22=fC[5];
148 Double_t &fC33=fC[9];
149 Double_t &fC43=fC[13];
150 Double_t &fC44=fC[14];
151
152 Double_t p2=(1.+ fP3*fP3)/(fP4*fP4);
153 Double_t beta2=p2/(p2 + mass*mass);
154 d*=TMath::Sqrt((1.+ fP3*fP3)/(1.- fP2*fP2));
155
156 //Multiple scattering******************
157 if (d!=0) {
158 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(d);
159 //Double_t theta2=1.0259e-6*14*14/28/(beta2*p2)*TMath::Abs(d)*9.36*2.33;
160 fC22 += theta2*(1.- fP2*fP2)*(1. + fP3*fP3);
161 fC33 += theta2*(1. + fP3*fP3)*(1. + fP3*fP3);
162 fC43 += theta2*fP3*fP4*(1. + fP3*fP3);
163 fC44 += theta2*fP3*fP4*fP3*fP4;
164 }
165
166 //Energy losses************************
167 if (x0!=0.) {
168 d*=x0;
169 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d;
170 if (beta2/(1-beta2)>3.5*3.5)
171 dE=0.153e-3/beta2*(log(3.5*5940)+0.5*log(beta2/(1-beta2)) - beta2)*d;
172
173 fP4*=(1.- TMath::Sqrt(p2 + mass*mass)/p2*dE);
174 }
175
176 return kTRUE;
177}
178
49d13e89 179Bool_t AliExternalTrackParam::Rotate(Double_t alpha) {
180 //------------------------------------------------------------------
181 // Transform this track to the local coord. system rotated
182 // by angle "alpha" (rad) with respect to the global coord. system.
183 //------------------------------------------------------------------
184 if (alpha < -TMath::Pi()) alpha += 2*TMath::Pi();
185 else if (alpha >= TMath::Pi()) alpha -= 2*TMath::Pi();
186
187 Double_t &fP0=fP[0];
188 Double_t &fP2=fP[2];
189 Double_t &fC00=fC[0];
190 Double_t &fC10=fC[1];
191 Double_t &fC20=fC[3];
192 Double_t &fC21=fC[4];
193 Double_t &fC22=fC[5];
194 Double_t &fC30=fC[6];
195 Double_t &fC32=fC[8];
196 Double_t &fC40=fC[10];
197 Double_t &fC42=fC[12];
198
199 Double_t x=fX;
200 Double_t ca=TMath::Cos(alpha-fAlpha), sa=TMath::Sin(alpha-fAlpha);
201 Double_t sf=fP2, cf=TMath::Sqrt(1.- fP2*fP2);
202
203 fAlpha = alpha;
204 fX = x*ca + fP0*sa;
205 fP0= -x*sa + fP0*ca;
206 fP2= sf*ca - cf*sa;
207
208 Double_t rr=(ca+sf/cf*sa);
209
210 fC00 *= (ca*ca);
211 fC10 *= ca;
212 fC20 *= ca*rr;
213 fC21 *= rr;
214 fC22 *= rr*rr;
215 fC30 *= ca;
216 fC32 *= rr;
217 fC40 *= ca;
218 fC42 *= rr;
219
220 return kTRUE;
221}
222
223Bool_t AliExternalTrackParam::PropagateTo(Double_t xk, Double_t b) {
224 //----------------------------------------------------------------
225 // Propagate this track to the plane X=xk (cm) in the field "b" (kG)
226 //----------------------------------------------------------------
227 Double_t crv=kB2C*b*fP[4];
228 Double_t dx=xk-fX;
229 Double_t f1=fP[2], f2=f1 + crv*dx;
bbefa4c4 230 if (TMath::Abs(f1) >= kAlmost1) return kFALSE;
49d13e89 231 if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
232
233 Double_t &fP0=fP[0], &fP1=fP[1], &fP2=fP[2], &fP3=fP[3], &fP4=fP[4];
234 Double_t
235 &fC00=fC[0],
236 &fC10=fC[1], &fC11=fC[2],
237 &fC20=fC[3], &fC21=fC[4], &fC22=fC[5],
238 &fC30=fC[6], &fC31=fC[7], &fC32=fC[8], &fC33=fC[9],
239 &fC40=fC[10], &fC41=fC[11], &fC42=fC[12], &fC43=fC[13], &fC44=fC[14];
240
241 Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
242
243 fX=xk;
244 fP0 += dx*(f1+f2)/(r1+r2);
245 fP1 += dx*(f1+f2)/(f1*r2 + f2*r1)*fP3;
246 fP2 += dx*crv;
247
248 //f = F - 1
249
250 Double_t f02= dx/(r1*r1*r1); Double_t cc=crv/fP4;
251 Double_t f04=0.5*dx*dx/(r1*r1*r1); f04*=cc;
252 Double_t f12= dx*fP3*f1/(r1*r1*r1);
253 Double_t f14=0.5*dx*dx*fP3*f1/(r1*r1*r1); f14*=cc;
254 Double_t f13= dx/r1;
255 Double_t f24= dx; f24*=cc;
256
257 //b = C*ft
258 Double_t b00=f02*fC20 + f04*fC40, b01=f12*fC20 + f14*fC40 + f13*fC30;
259 Double_t b02=f24*fC40;
260 Double_t b10=f02*fC21 + f04*fC41, b11=f12*fC21 + f14*fC41 + f13*fC31;
261 Double_t b12=f24*fC41;
262 Double_t b20=f02*fC22 + f04*fC42, b21=f12*fC22 + f14*fC42 + f13*fC32;
263 Double_t b22=f24*fC42;
264 Double_t b40=f02*fC42 + f04*fC44, b41=f12*fC42 + f14*fC44 + f13*fC43;
265 Double_t b42=f24*fC44;
266 Double_t b30=f02*fC32 + f04*fC43, b31=f12*fC32 + f14*fC43 + f13*fC33;
267 Double_t b32=f24*fC43;
268
269 //a = f*b = f*C*ft
270 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a02=f02*b22+f04*b42;
271 Double_t a11=f12*b21+f14*b41+f13*b31,a12=f12*b22+f14*b42+f13*b32;
272 Double_t a22=f24*b42;
273
274 //F*C*Ft = C + (b + bt + a)
275 fC00 += b00 + b00 + a00;
276 fC10 += b10 + b01 + a01;
277 fC20 += b20 + b02 + a02;
278 fC30 += b30;
279 fC40 += b40;
280 fC11 += b11 + b11 + a11;
281 fC21 += b21 + b12 + a12;
282 fC31 += b31;
283 fC41 += b41;
284 fC22 += b22 + b22 + a22;
285 fC32 += b32;
286 fC42 += b42;
287
288 return kTRUE;
289}
290
291Double_t
292AliExternalTrackParam::GetPredictedChi2(Double_t p[2],Double_t cov[3]) const {
293 //----------------------------------------------------------------
294 // Estimate the chi2 of the space point "p" with the cov. matrix "cov"
295 //----------------------------------------------------------------
296 Double_t sdd = fC[0] + cov[0];
297 Double_t sdz = fC[1] + cov[1];
298 Double_t szz = fC[2] + cov[2];
299 Double_t det = sdd*szz - sdz*sdz;
300
301 if (TMath::Abs(det) < kAlmost0) return kVeryBig;
302
303 Double_t d = fP[0] - p[0];
304 Double_t z = fP[1] - p[1];
305
306 return (d*szz*d - 2*d*sdz*z + z*sdd*z)/det;
307}
308
309Bool_t AliExternalTrackParam::Update(Double_t p[2], Double_t cov[3]) {
310 //------------------------------------------------------------------
311 // Update the track parameters with the space point "p" having
312 // the covariance matrix "cov"
313 //------------------------------------------------------------------
314 Double_t &fP0=fP[0], &fP1=fP[1], &fP2=fP[2], &fP3=fP[3], &fP4=fP[4];
315 Double_t
316 &fC00=fC[0],
317 &fC10=fC[1], &fC11=fC[2],
318 &fC20=fC[3], &fC21=fC[4], &fC22=fC[5],
319 &fC30=fC[6], &fC31=fC[7], &fC32=fC[8], &fC33=fC[9],
320 &fC40=fC[10], &fC41=fC[11], &fC42=fC[12], &fC43=fC[13], &fC44=fC[14];
321
322 Double_t r00=cov[0], r01=cov[1], r11=cov[2];
323 r00+=fC00; r01+=fC10; r11+=fC11;
324 Double_t det=r00*r11 - r01*r01;
325
326 if (TMath::Abs(det) < kAlmost0) return kFALSE;
327
328
329 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
330
331 Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
332 Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
333 Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
334 Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
335 Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
336
337 Double_t dy=p[0] - fP0, dz=p[1] - fP1;
338 Double_t sf=fP2 + k20*dy + k21*dz;
339 if (TMath::Abs(sf) > kAlmost1) return kFALSE;
340
341 fP0 += k00*dy + k01*dz;
342 fP1 += k10*dy + k11*dz;
343 fP2 = sf;
344 fP3 += k30*dy + k31*dz;
345 fP4 += k40*dy + k41*dz;
346
347 Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
348 Double_t c12=fC21, c13=fC31, c14=fC41;
349
350 fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
351 fC20-=k00*c02+k01*c12; fC30-=k00*c03+k01*c13;
352 fC40-=k00*c04+k01*c14;
353
354 fC11-=k10*c01+k11*fC11;
355 fC21-=k10*c02+k11*c12; fC31-=k10*c03+k11*c13;
356 fC41-=k10*c04+k11*c14;
357
358 fC22-=k20*c02+k21*c12; fC32-=k20*c03+k21*c13;
359 fC42-=k20*c04+k21*c14;
360
361 fC33-=k30*c03+k31*c13;
362 fC43-=k30*c04+k31*c14;
363
364 fC44-=k40*c04+k41*c14;
365
366 return kTRUE;
367}
368
c7bafca9 369void
370AliExternalTrackParam::GetHelixParameters(Double_t hlx[6], Double_t b) const {
371 //--------------------------------------------------------------------
372 // External track parameters -> helix parameters
373 // "b" - magnetic field (kG)
374 //--------------------------------------------------------------------
375 Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
376
377 hlx[0]=fP[0]; hlx[1]=fP[1]; hlx[2]=fP[2]; hlx[3]=fP[3]; hlx[4]=fP[4];
378
379 hlx[5]=fX*cs - hlx[0]*sn; // x0
380 hlx[0]=fX*sn + hlx[0]*cs; // y0
381//hlx[1]= // z0
382 hlx[2]=TMath::ASin(hlx[2]) + fAlpha; // phi0
383//hlx[3]= // tgl
384 hlx[4]=hlx[4]*kB2C*b; // C
385}
386
387
388static void Evaluate(const Double_t *h, Double_t t,
389 Double_t r[3], //radius vector
390 Double_t g[3], //first defivatives
391 Double_t gg[3]) //second derivatives
392{
393 //--------------------------------------------------------------------
394 // Calculate position of a point on a track and some derivatives
395 //--------------------------------------------------------------------
396 Double_t phase=h[4]*t+h[2];
397 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
398
399 r[0] = h[5] + (sn - h[6])/h[4];
400 r[1] = h[0] - (cs - h[7])/h[4];
401 r[2] = h[1] + h[3]*t;
402
403 g[0] = cs; g[1]=sn; g[2]=h[3];
404
405 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
406}
407
408Double_t AliExternalTrackParam::GetDCA(const AliExternalTrackParam *p,
409Double_t b, Double_t &xthis, Double_t &xp) const {
410 //------------------------------------------------------------
411 // Returns the (weighed !) distance of closest approach between
412 // this track and the track "p".
413 // Other returned values:
414 // xthis, xt - coordinates of tracks' reference planes at the DCA
415 //-----------------------------------------------------------
416 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
417 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
418 Double_t dx2=dy2;
419
420 //dx2=dy2=dz2=1.;
421
422 Double_t p1[8]; GetHelixParameters(p1,b);
423 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
424 Double_t p2[8]; p->GetHelixParameters(p2,b);
425 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
426
427
428 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
429 Evaluate(p1,t1,r1,g1,gg1);
430 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
431 Evaluate(p2,t2,r2,g2,gg2);
432
433 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
434 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
435
436 Int_t max=27;
437 while (max--) {
438 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
439 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
440 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
441 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
442 (g1[2]*g1[2] - dz*gg1[2])/dz2;
443 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
444 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
445 (g2[2]*g2[2] + dz*gg2[2])/dz2;
446 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
447
448 Double_t det=h11*h22-h12*h12;
449
450 Double_t dt1,dt2;
451 if (TMath::Abs(det)<1.e-33) {
452 //(quasi)singular Hessian
453 dt1=-gt1; dt2=-gt2;
454 } else {
455 dt1=-(gt1*h22 - gt2*h12)/det;
456 dt2=-(h11*gt2 - h12*gt1)/det;
457 }
458
459 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
460
461 //check delta(phase1) ?
462 //check delta(phase2) ?
463
464 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
465 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
466 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
467 AliWarning(" stopped at not a stationary point !");
468 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
469 if (lmb < 0.)
470 AliWarning(" stopped at not a minimum !");
471 break;
472 }
473
474 Double_t dd=dm;
475 for (Int_t div=1 ; ; div*=2) {
476 Evaluate(p1,t1+dt1,r1,g1,gg1);
477 Evaluate(p2,t2+dt2,r2,g2,gg2);
478 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
479 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
480 if (dd<dm) break;
481 dt1*=0.5; dt2*=0.5;
482 if (div>512) {
483 AliWarning(" overshoot !"); break;
484 }
485 }
486 dm=dd;
487
488 t1+=dt1;
489 t2+=dt2;
490
491 }
492
493 if (max<=0) AliWarning(" too many iterations !");
494
495 Double_t cs=TMath::Cos(GetAlpha());
496 Double_t sn=TMath::Sin(GetAlpha());
497 xthis=r1[0]*cs + r1[1]*sn;
498
499 cs=TMath::Cos(p->GetAlpha());
500 sn=TMath::Sin(p->GetAlpha());
501 xp=r2[0]*cs + r2[1]*sn;
502
503 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
504}
505
506Double_t AliExternalTrackParam::
507PropagateToDCA(AliExternalTrackParam *p, Double_t b) {
508 //--------------------------------------------------------------
509 // Propagates this track and the argument track to the position of the
510 // distance of closest approach.
511 // Returns the (weighed !) distance of closest approach.
512 //--------------------------------------------------------------
513 Double_t xthis,xp;
514 Double_t dca=GetDCA(p,b,xthis,xp);
515
516 if (!PropagateTo(xthis,b)) {
517 //AliWarning(" propagation failed !");
518 return 1e+33;
519 }
520
521 if (!p->PropagateTo(xp,b)) {
522 //AliWarning(" propagation failed !";
523 return 1e+33;
524 }
525
526 return dca;
527}
528
529
530
c9ec41e8 531Bool_t Local2GlobalMomentum(Double_t p[3],Double_t alpha) {
532 //----------------------------------------------------------------
533 // This function performs local->global transformation of the
534 // track momentum.
535 // When called, the arguments are:
536 // p[0] = 1/pt of the track;
537 // p[1] = sine of local azim. angle of the track momentum;
538 // p[2] = tangent of the track momentum dip angle;
539 // alpha - rotation angle.
540 // The result is returned as:
541 // p[0] = px
542 // p[1] = py
543 // p[2] = pz
544 // Results for (nearly) straight tracks are meaningless !
545 //----------------------------------------------------------------
546 if (TMath::Abs(p[0])<=0) return kFALSE;
49d13e89 547 if (TMath::Abs(p[1])> kAlmost1) return kFALSE;
c9ec41e8 548
549 Double_t pt=1./TMath::Abs(p[0]);
550 Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha);
551 Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
552 p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
a5e407e9 553
554 return kTRUE;
555}
556
c9ec41e8 557Bool_t Local2GlobalPosition(Double_t r[3],Double_t alpha) {
558 //----------------------------------------------------------------
559 // This function performs local->global transformation of the
560 // track position.
561 // When called, the arguments are:
562 // r[0] = local x
563 // r[1] = local y
564 // r[2] = local z
565 // alpha - rotation angle.
566 // The result is returned as:
567 // r[0] = global x
568 // r[1] = global y
569 // r[2] = global z
570 //----------------------------------------------------------------
571 Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha), x=r[0];
572 r[0]=x*cs - r[1]*sn; r[1]=x*sn + r[1]*cs;
a5e407e9 573
a5e407e9 574 return kTRUE;
51ad6848 575}
576
c9ec41e8 577Bool_t AliExternalTrackParam::GetPxPyPz(Double_t *p) const {
578 //---------------------------------------------------------------------
579 // This function returns the global track momentum components
580 // Results for (nearly) straight tracks are meaningless !
581 //---------------------------------------------------------------------
582 p[0]=fP[4]; p[1]=fP[2]; p[2]=fP[3];
583 return Local2GlobalMomentum(p,fAlpha);
584}
a5e407e9 585
c9ec41e8 586Bool_t AliExternalTrackParam::GetXYZ(Double_t *r) const {
587 //---------------------------------------------------------------------
588 // This function returns the global track position
589 //---------------------------------------------------------------------
590 r[0]=fX; r[1]=fP[0]; r[2]=fP[1];
591 return Local2GlobalPosition(r,fAlpha);
51ad6848 592}
593
c9ec41e8 594Bool_t AliExternalTrackParam::GetCovarianceXYZPxPyPz(Double_t cv[21]) const {
595 //---------------------------------------------------------------------
596 // This function returns the global covariance matrix of the track params
597 //
598 // Cov(x,x) ... : cv[0]
599 // Cov(y,x) ... : cv[1] cv[2]
600 // Cov(z,x) ... : cv[3] cv[4] cv[5]
601 // Cov(px,x)... : cv[6] cv[7] cv[8] cv[9]
602 // Cov(py,x)... : cv[10] cv[11] cv[12] cv[13] cv[14]
603 // Cov(pz,x)... : cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
a5e407e9 604 //
c9ec41e8 605 // Results for (nearly) straight tracks are meaningless !
606 //---------------------------------------------------------------------
607 if (TMath::Abs(fP[4])<=0) {
608 for (Int_t i=0; i<21; i++) cv[i]=0.;
609 return kFALSE;
a5e407e9 610 }
49d13e89 611 if (TMath::Abs(fP[2]) > kAlmost1) {
c9ec41e8 612 for (Int_t i=0; i<21; i++) cv[i]=0.;
613 return kFALSE;
614 }
615 Double_t pt=1./TMath::Abs(fP[4]);
616 Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
617 Double_t r=TMath::Sqrt(1-fP[2]*fP[2]);
618
619 Double_t m00=-sn, m10=cs;
620 Double_t m23=-pt*(sn + fP[2]*cs/r), m43=-pt*pt*(r*cs - fP[2]*sn);
621 Double_t m24= pt*(cs - fP[2]*sn/r), m44=-pt*pt*(r*sn + fP[2]*cs);
622 Double_t m35=pt, m45=-pt*pt*fP[3];
623
624 cv[0 ] = fC[0]*m00*m00;
625 cv[1 ] = fC[0]*m00*m10;
626 cv[2 ] = fC[0]*m10*m10;
627 cv[3 ] = fC[1]*m00;
628 cv[4 ] = fC[1]*m10;
629 cv[5 ] = fC[2];
630 cv[6 ] = m00*(fC[3]*m23 + fC[10]*m43);
631 cv[7 ] = m10*(fC[3]*m23 + fC[10]*m43);
632 cv[8 ] = fC[4]*m23 + fC[11]*m43;
633 cv[9 ] = m23*(fC[5]*m23 + fC[12]*m43) + m43*(fC[12]*m23 + fC[14]*m43);
634 cv[10] = m00*(fC[3]*m24 + fC[10]*m44);
635 cv[11] = m10*(fC[3]*m24 + fC[10]*m44);
636 cv[12] = fC[4]*m24 + fC[11]*m44;
637 cv[13] = m23*(fC[5]*m24 + fC[12]*m44) + m43*(fC[12]*m24 + fC[14]*m44);
638 cv[14] = m24*(fC[5]*m24 + fC[12]*m44) + m44*(fC[12]*m24 + fC[14]*m44);
639 cv[15] = m00*(fC[6]*m35 + fC[10]*m45);
640 cv[16] = m10*(fC[6]*m35 + fC[10]*m45);
641 cv[17] = fC[7]*m35 + fC[11]*m45;
642 cv[18] = m23*(fC[8]*m35 + fC[12]*m45) + m43*(fC[13]*m35 + fC[14]*m45);
643 cv[19] = m24*(fC[8]*m35 + fC[12]*m45) + m44*(fC[13]*m35 + fC[14]*m45);
644 cv[20] = m35*(fC[9]*m35 + fC[13]*m45) + m45*(fC[13]*m35 + fC[14]*m45);
51ad6848 645
c9ec41e8 646 return kTRUE;
51ad6848 647}
648
51ad6848 649
c9ec41e8 650Bool_t
651AliExternalTrackParam::GetPxPyPzAt(Double_t x, Double_t b, Double_t *p) const {
652 //---------------------------------------------------------------------
653 // This function returns the global track momentum extrapolated to
654 // the radial position "x" (cm) in the magnetic field "b" (kG)
655 //---------------------------------------------------------------------
c9ec41e8 656 p[0]=fP[4];
49d13e89 657 p[1]=fP[2]+(x-fX)*fP[4]*b*kB2C;
c9ec41e8 658 p[2]=fP[3];
659 return Local2GlobalMomentum(p,fAlpha);
51ad6848 660}
661
c9ec41e8 662Bool_t
663AliExternalTrackParam::GetXYZAt(Double_t x, Double_t b, Double_t *r) const {
664 //---------------------------------------------------------------------
665 // This function returns the global track position extrapolated to
666 // the radial position "x" (cm) in the magnetic field "b" (kG)
667 //---------------------------------------------------------------------
c9ec41e8 668 Double_t dx=x-fX;
49d13e89 669 Double_t f1=fP[2], f2=f1 + dx*fP[4]*b*kB2C;
c9ec41e8 670
49d13e89 671 if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
c9ec41e8 672
673 Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
674 r[0] = x;
675 r[1] = fP[0] + dx*(f1+f2)/(r1+r2);
676 r[2] = fP[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fP[3];
677 return Local2GlobalPosition(r,fAlpha);
51ad6848 678}
679
680
681//_____________________________________________________________________________
edc97986 682void AliExternalTrackParam::ApproximateHelixWithLine(Double_t xk, Double_t b, AliStrLine *line)
683{
684 //------------------------------------------------------------
685 // Approximate the track (helix) with a straight line tangent to the
686 // helix in the point defined by r (F. Prino, prino@to.infn.it)
687 //------------------------------------------------------------
688 Double_t mom[3];
689 Double_t azim = TMath::ASin(fP[2])+fAlpha;
690 Double_t theta = TMath::Pi()/2. - TMath::ATan(fP[3]);
691 mom[0] = TMath::Sin(theta)*TMath::Cos(azim);
692 mom[1] = TMath::Sin(theta)*TMath::Sin(azim);
693 mom[2] = TMath::Cos(theta);
694 Double_t pos[3];
695 GetXYZAt(xk,b,pos);
696 line->SetP0(pos);
697 line->SetCd(mom);
698}
699//_____________________________________________________________________________
51ad6848 700void AliExternalTrackParam::Print(Option_t* /*option*/) const
701{
702// print the parameters and the covariance matrix
703
704 printf("AliExternalTrackParam: x = %-12g alpha = %-12g\n", fX, fAlpha);
705 printf(" parameters: %12g %12g %12g %12g %12g\n",
c9ec41e8 706 fP[0], fP[1], fP[2], fP[3], fP[4]);
707 printf(" covariance: %12g\n", fC[0]);
708 printf(" %12g %12g\n", fC[1], fC[2]);
709 printf(" %12g %12g %12g\n", fC[3], fC[4], fC[5]);
51ad6848 710 printf(" %12g %12g %12g %12g\n",
c9ec41e8 711 fC[6], fC[7], fC[8], fC[9]);
51ad6848 712 printf(" %12g %12g %12g %12g %12g\n",
c9ec41e8 713 fC[10], fC[11], fC[12], fC[13], fC[14]);
51ad6848 714}
5b77d93c 715
716
717Bool_t AliExternalTrackParam::PropagateTo(Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t rotateTo){
718 //----------------------------------------------------------------
719 // Propagate this track to the plane X=xk (cm)
720 // correction for unhomogenity of the magnetic field and the
721 // the correction for the material is included
722 //
723 // Require acces to magnetic field and geomanager
724 //
725 // mass - mass used in propagation - used for energy loss correction
726 // maxStep - maximal step for propagation
727 //----------------------------------------------------------------
728 const Double_t kEpsilon = 0.00001;
729 Double_t xpos = GetX();
730 Double_t dir = (xpos<xToGo) ? 1.:-1.;
731 //
732 while ( (xToGo-xpos)*dir > kEpsilon){
733 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
734 Double_t x = xpos+step;
735 Double_t xyz0[3],xyz1[3],param[7];
736 GetXYZ(xyz0); //starting global position
737 Float_t pos0[3] = {xyz0[0],xyz0[1],xyz0[2]};
738 Double_t magZ = AliTracker::GetBz(pos0);
739 if (!GetXYZAt(x,magZ,xyz1)) return kFALSE; // no prolongation
740 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
741 if (!PropagateTo(x,magZ)) return kFALSE;
742 Double_t distance = param[4];
743 if (!CorrectForMaterial(distance,param[1],param[0],mass)) return kFALSE;
744 if (rotateTo){
745 GetXYZ(xyz0); // global position
746 Double_t alphan = TMath::ATan2(xyz0[1], xyz0[0]);
747 if (!Rotate(alphan)) return kFALSE;
748 }
749 xpos = GetX();
750 }
751 return kTRUE;
752}
753
754//_____________________________________________________________________________
755Bool_t AliExternalTrackParam::CorrectForMaterial(Double_t d, Double_t x0, Double_t rho, Double_t mass)
756{
757 //
758 // Take into account material effects assuming:
759 // x0 - mean rad length
760 // rho - mean density
761
762 //
763 // multiple scattering
764 //
765 if (mass<=0) {
766 AliError("Non-positive mass");
767 return kFALSE;
768 }
769 Double_t p2=(1.+ fP[3]*fP[3])/(fP[4]*fP[4]);
770 Double_t beta2=p2/(p2 + mass*mass);
771 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
772 //
773 fC[5] += theta2*(1.- fP[2]*fP[2])*(1. + fP[3]*fP[3]);
774 fC[9] += theta2*(1. + fP[3]*fP[3])*(1. + fP[3]*fP[3]);
775 fC[13] += theta2*fP[3]*fP[4]*(1. + fP[3]*fP[3]);
776 fC[14] += theta2*fP[3]*fP[4]*fP[3]*fP[4];
777 //
778 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
779 fP[4] *=(1.- TMath::Sqrt(p2+mass*mass)/p2*dE);
780 //
781 Double_t sigmade = 0.02*TMath::Sqrt(TMath::Abs(dE)); // energy loss fluctuation
782 Double_t sigmac2 = sigmade*sigmade*fP[4]*fP[4]*(p2+mass*mass)/(p2*p2);
783 fC[14] += sigmac2;
784 return kTRUE;
785}
786
787