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 ///////////////////////////////////////////////////////////////////////////////
20 // Implementation of the external track parameterisation class. //
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 //
26 // Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch //
27 ///////////////////////////////////////////////////////////////////////////////
28 #include "AliExternalTrackParam.h"
29 #include "AliKalmanTrack.h"
31 ClassImp(AliExternalTrackParam)
33 //_____________________________________________________________________________
34 AliExternalTrackParam::AliExternalTrackParam() :
39 // default constructor
41 for (Int_t i = 0; i < 5; i++) fP[i] = 0;
42 for (Int_t i = 0; i < 15; i++) fC[i] = 0;
45 //_____________________________________________________________________________
46 AliExternalTrackParam::AliExternalTrackParam(Double_t x, Double_t alpha,
47 const Double_t param[5],
48 const Double_t covar[15]) :
53 // create external track parameters from given arguments
55 for (Int_t i = 0; i < 5; i++) fP[i] = param[i];
56 for (Int_t i = 0; i < 15; i++) fC[i] = covar[i];
59 //_____________________________________________________________________________
60 AliExternalTrackParam::AliExternalTrackParam(const AliKalmanTrack& track) :
61 fAlpha(track.GetAlpha())
65 track.GetExternalParameters(fX,fP);
66 track.GetExternalCovariance(fC);
69 //_____________________________________________________________________________
70 void AliExternalTrackParam::Set(const AliKalmanTrack& track) {
73 fAlpha=track.GetAlpha();
74 track.GetExternalParameters(fX,fP);
75 track.GetExternalCovariance(fC);
78 //_____________________________________________________________________________
79 void AliExternalTrackParam::Reset() {
81 for (Int_t i = 0; i < 5; i++) fP[i] = 0;
82 for (Int_t i = 0; i < 15; i++) fC[i] = 0;
85 Double_t AliExternalTrackParam::GetP() const {
86 //---------------------------------------------------------------------
87 // This function returns the track momentum
88 // Results for (nearly) straight tracks are meaningless !
89 //---------------------------------------------------------------------
90 if (TMath::Abs(fP[4])<=0) return 0;
91 return TMath::Sqrt(1.+ fP[3]*fP[3])/TMath::Abs(fP[4]);
94 //_______________________________________________________________________
95 Double_t AliExternalTrackParam::GetD(Double_t b,Double_t x,Double_t y) const {
96 //------------------------------------------------------------------
97 // This function calculates the transverse impact parameter
98 // with respect to a point with global coordinates (x,y)
99 // in the magnetic field "b" (kG)
100 //------------------------------------------------------------------
101 Double_t rp4=kB2C*b*fP[4];
103 Double_t xt=fX, yt=fP[0];
105 Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
106 Double_t a = x*cs + y*sn;
107 y = -x*sn + y*cs; x=a;
110 sn=rp4*xt - fP[2]; cs=rp4*yt + TMath::Sqrt(1.- fP[2]*fP[2]);
111 a=2*(xt*fP[2] - yt*TMath::Sqrt(1.- fP[2]*fP[2]))-rp4*(xt*xt + yt*yt);
113 return a/(1 + TMath::Sqrt(sn*sn + cs*cs));
116 //_______________________________________________________________________
117 Double_t AliExternalTrackParam::GetLinearD(Double_t xv,Double_t yv) const {
118 //------------------------------------------------------------------
119 // This function calculates the transverse impact parameter
120 // with respect to a point with global coordinates (xv,yv)
121 // neglecting the track curvature.
122 //------------------------------------------------------------------
123 Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
124 Double_t x= xv*cs + yv*sn;
125 Double_t y=-xv*sn + yv*cs;
127 Double_t d = (fX-x)*fP[2] - (fP[0]-y)*TMath::Sqrt(1.- fP[2]*fP[2]);
132 Bool_t AliExternalTrackParam::Rotate(Double_t alpha) {
133 //------------------------------------------------------------------
134 // Transform this track to the local coord. system rotated
135 // by angle "alpha" (rad) with respect to the global coord. system.
136 //------------------------------------------------------------------
137 if (alpha < -TMath::Pi()) alpha += 2*TMath::Pi();
138 else if (alpha >= TMath::Pi()) alpha -= 2*TMath::Pi();
142 Double_t &fC00=fC[0];
143 Double_t &fC10=fC[1];
144 Double_t &fC20=fC[3];
145 Double_t &fC21=fC[4];
146 Double_t &fC22=fC[5];
147 Double_t &fC30=fC[6];
148 Double_t &fC32=fC[8];
149 Double_t &fC40=fC[10];
150 Double_t &fC42=fC[12];
153 Double_t ca=TMath::Cos(alpha-fAlpha), sa=TMath::Sin(alpha-fAlpha);
154 Double_t sf=fP2, cf=TMath::Sqrt(1.- fP2*fP2);
161 Double_t rr=(ca+sf/cf*sa);
176 Bool_t AliExternalTrackParam::PropagateTo(Double_t xk, Double_t b) {
177 //----------------------------------------------------------------
178 // Propagate this track to the plane X=xk (cm) in the field "b" (kG)
179 //----------------------------------------------------------------
180 Double_t crv=kB2C*b*fP[4];
182 Double_t f1=fP[2], f2=f1 + crv*dx;
183 if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
185 Double_t &fP0=fP[0], &fP1=fP[1], &fP2=fP[2], &fP3=fP[3], &fP4=fP[4];
188 &fC10=fC[1], &fC11=fC[2],
189 &fC20=fC[3], &fC21=fC[4], &fC22=fC[5],
190 &fC30=fC[6], &fC31=fC[7], &fC32=fC[8], &fC33=fC[9],
191 &fC40=fC[10], &fC41=fC[11], &fC42=fC[12], &fC43=fC[13], &fC44=fC[14];
193 Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
196 fP0 += dx*(f1+f2)/(r1+r2);
197 fP1 += dx*(f1+f2)/(f1*r2 + f2*r1)*fP3;
202 Double_t f02= dx/(r1*r1*r1); Double_t cc=crv/fP4;
203 Double_t f04=0.5*dx*dx/(r1*r1*r1); f04*=cc;
204 Double_t f12= dx*fP3*f1/(r1*r1*r1);
205 Double_t f14=0.5*dx*dx*fP3*f1/(r1*r1*r1); f14*=cc;
207 Double_t f24= dx; f24*=cc;
210 Double_t b00=f02*fC20 + f04*fC40, b01=f12*fC20 + f14*fC40 + f13*fC30;
211 Double_t b02=f24*fC40;
212 Double_t b10=f02*fC21 + f04*fC41, b11=f12*fC21 + f14*fC41 + f13*fC31;
213 Double_t b12=f24*fC41;
214 Double_t b20=f02*fC22 + f04*fC42, b21=f12*fC22 + f14*fC42 + f13*fC32;
215 Double_t b22=f24*fC42;
216 Double_t b40=f02*fC42 + f04*fC44, b41=f12*fC42 + f14*fC44 + f13*fC43;
217 Double_t b42=f24*fC44;
218 Double_t b30=f02*fC32 + f04*fC43, b31=f12*fC32 + f14*fC43 + f13*fC33;
219 Double_t b32=f24*fC43;
222 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a02=f02*b22+f04*b42;
223 Double_t a11=f12*b21+f14*b41+f13*b31,a12=f12*b22+f14*b42+f13*b32;
224 Double_t a22=f24*b42;
226 //F*C*Ft = C + (b + bt + a)
227 fC00 += b00 + b00 + a00;
228 fC10 += b10 + b01 + a01;
229 fC20 += b20 + b02 + a02;
232 fC11 += b11 + b11 + a11;
233 fC21 += b21 + b12 + a12;
236 fC22 += b22 + b22 + a22;
244 AliExternalTrackParam::GetPredictedChi2(Double_t p[2],Double_t cov[3]) const {
245 //----------------------------------------------------------------
246 // Estimate the chi2 of the space point "p" with the cov. matrix "cov"
247 //----------------------------------------------------------------
248 Double_t sdd = fC[0] + cov[0];
249 Double_t sdz = fC[1] + cov[1];
250 Double_t szz = fC[2] + cov[2];
251 Double_t det = sdd*szz - sdz*sdz;
253 if (TMath::Abs(det) < kAlmost0) return kVeryBig;
255 Double_t d = fP[0] - p[0];
256 Double_t z = fP[1] - p[1];
258 return (d*szz*d - 2*d*sdz*z + z*sdd*z)/det;
261 Bool_t AliExternalTrackParam::Update(Double_t p[2], Double_t cov[3]) {
262 //------------------------------------------------------------------
263 // Update the track parameters with the space point "p" having
264 // the covariance matrix "cov"
265 //------------------------------------------------------------------
266 Double_t &fP0=fP[0], &fP1=fP[1], &fP2=fP[2], &fP3=fP[3], &fP4=fP[4];
269 &fC10=fC[1], &fC11=fC[2],
270 &fC20=fC[3], &fC21=fC[4], &fC22=fC[5],
271 &fC30=fC[6], &fC31=fC[7], &fC32=fC[8], &fC33=fC[9],
272 &fC40=fC[10], &fC41=fC[11], &fC42=fC[12], &fC43=fC[13], &fC44=fC[14];
274 Double_t r00=cov[0], r01=cov[1], r11=cov[2];
275 r00+=fC00; r01+=fC10; r11+=fC11;
276 Double_t det=r00*r11 - r01*r01;
278 if (TMath::Abs(det) < kAlmost0) return kFALSE;
281 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
283 Double_t k00=fC00*r00+fC10*r01, k01=fC00*r01+fC10*r11;
284 Double_t k10=fC10*r00+fC11*r01, k11=fC10*r01+fC11*r11;
285 Double_t k20=fC20*r00+fC21*r01, k21=fC20*r01+fC21*r11;
286 Double_t k30=fC30*r00+fC31*r01, k31=fC30*r01+fC31*r11;
287 Double_t k40=fC40*r00+fC41*r01, k41=fC40*r01+fC41*r11;
289 Double_t dy=p[0] - fP0, dz=p[1] - fP1;
290 Double_t sf=fP2 + k20*dy + k21*dz;
291 if (TMath::Abs(sf) > kAlmost1) return kFALSE;
293 fP0 += k00*dy + k01*dz;
294 fP1 += k10*dy + k11*dz;
296 fP3 += k30*dy + k31*dz;
297 fP4 += k40*dy + k41*dz;
299 Double_t c01=fC10, c02=fC20, c03=fC30, c04=fC40;
300 Double_t c12=fC21, c13=fC31, c14=fC41;
302 fC00-=k00*fC00+k01*fC10; fC10-=k00*c01+k01*fC11;
303 fC20-=k00*c02+k01*c12; fC30-=k00*c03+k01*c13;
304 fC40-=k00*c04+k01*c14;
306 fC11-=k10*c01+k11*fC11;
307 fC21-=k10*c02+k11*c12; fC31-=k10*c03+k11*c13;
308 fC41-=k10*c04+k11*c14;
310 fC22-=k20*c02+k21*c12; fC32-=k20*c03+k21*c13;
311 fC42-=k20*c04+k21*c14;
313 fC33-=k30*c03+k31*c13;
314 fC43-=k30*c04+k31*c14;
316 fC44-=k40*c04+k41*c14;
321 Bool_t Local2GlobalMomentum(Double_t p[3],Double_t alpha) {
322 //----------------------------------------------------------------
323 // This function performs local->global transformation of the
325 // When called, the arguments are:
326 // p[0] = 1/pt of the track;
327 // p[1] = sine of local azim. angle of the track momentum;
328 // p[2] = tangent of the track momentum dip angle;
329 // alpha - rotation angle.
330 // The result is returned as:
334 // Results for (nearly) straight tracks are meaningless !
335 //----------------------------------------------------------------
336 if (TMath::Abs(p[0])<=0) return kFALSE;
337 if (TMath::Abs(p[1])> kAlmost1) return kFALSE;
339 Double_t pt=1./TMath::Abs(p[0]);
340 Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha);
341 Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
342 p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
347 Bool_t Local2GlobalPosition(Double_t r[3],Double_t alpha) {
348 //----------------------------------------------------------------
349 // This function performs local->global transformation of the
351 // When called, the arguments are:
355 // alpha - rotation angle.
356 // The result is returned as:
360 //----------------------------------------------------------------
361 Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha), x=r[0];
362 r[0]=x*cs - r[1]*sn; r[1]=x*sn + r[1]*cs;
367 Bool_t AliExternalTrackParam::GetPxPyPz(Double_t *p) const {
368 //---------------------------------------------------------------------
369 // This function returns the global track momentum components
370 // Results for (nearly) straight tracks are meaningless !
371 //---------------------------------------------------------------------
372 p[0]=fP[4]; p[1]=fP[2]; p[2]=fP[3];
373 return Local2GlobalMomentum(p,fAlpha);
376 Bool_t AliExternalTrackParam::GetXYZ(Double_t *r) const {
377 //---------------------------------------------------------------------
378 // This function returns the global track position
379 //---------------------------------------------------------------------
380 r[0]=fX; r[1]=fP[0]; r[2]=fP[1];
381 return Local2GlobalPosition(r,fAlpha);
384 Bool_t AliExternalTrackParam::GetCovarianceXYZPxPyPz(Double_t cv[21]) const {
385 //---------------------------------------------------------------------
386 // This function returns the global covariance matrix of the track params
388 // Cov(x,x) ... : cv[0]
389 // Cov(y,x) ... : cv[1] cv[2]
390 // Cov(z,x) ... : cv[3] cv[4] cv[5]
391 // Cov(px,x)... : cv[6] cv[7] cv[8] cv[9]
392 // Cov(py,x)... : cv[10] cv[11] cv[12] cv[13] cv[14]
393 // Cov(pz,x)... : cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
395 // Results for (nearly) straight tracks are meaningless !
396 //---------------------------------------------------------------------
397 if (TMath::Abs(fP[4])<=0) {
398 for (Int_t i=0; i<21; i++) cv[i]=0.;
401 if (TMath::Abs(fP[2]) > kAlmost1) {
402 for (Int_t i=0; i<21; i++) cv[i]=0.;
405 Double_t pt=1./TMath::Abs(fP[4]);
406 Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
407 Double_t r=TMath::Sqrt(1-fP[2]*fP[2]);
409 Double_t m00=-sn, m10=cs;
410 Double_t m23=-pt*(sn + fP[2]*cs/r), m43=-pt*pt*(r*cs - fP[2]*sn);
411 Double_t m24= pt*(cs - fP[2]*sn/r), m44=-pt*pt*(r*sn + fP[2]*cs);
412 Double_t m35=pt, m45=-pt*pt*fP[3];
414 cv[0 ] = fC[0]*m00*m00;
415 cv[1 ] = fC[0]*m00*m10;
416 cv[2 ] = fC[0]*m10*m10;
420 cv[6 ] = m00*(fC[3]*m23 + fC[10]*m43);
421 cv[7 ] = m10*(fC[3]*m23 + fC[10]*m43);
422 cv[8 ] = fC[4]*m23 + fC[11]*m43;
423 cv[9 ] = m23*(fC[5]*m23 + fC[12]*m43) + m43*(fC[12]*m23 + fC[14]*m43);
424 cv[10] = m00*(fC[3]*m24 + fC[10]*m44);
425 cv[11] = m10*(fC[3]*m24 + fC[10]*m44);
426 cv[12] = fC[4]*m24 + fC[11]*m44;
427 cv[13] = m23*(fC[5]*m24 + fC[12]*m44) + m43*(fC[12]*m24 + fC[14]*m44);
428 cv[14] = m24*(fC[5]*m24 + fC[12]*m44) + m44*(fC[12]*m24 + fC[14]*m44);
429 cv[15] = m00*(fC[6]*m35 + fC[10]*m45);
430 cv[16] = m10*(fC[6]*m35 + fC[10]*m45);
431 cv[17] = fC[7]*m35 + fC[11]*m45;
432 cv[18] = m23*(fC[8]*m35 + fC[12]*m45) + m43*(fC[13]*m35 + fC[14]*m45);
433 cv[19] = m24*(fC[8]*m35 + fC[12]*m45) + m44*(fC[13]*m35 + fC[14]*m45);
434 cv[20] = m35*(fC[9]*m35 + fC[13]*m45) + m45*(fC[13]*m35 + fC[14]*m45);
441 AliExternalTrackParam::GetPxPyPzAt(Double_t x, Double_t b, Double_t *p) const {
442 //---------------------------------------------------------------------
443 // This function returns the global track momentum extrapolated to
444 // the radial position "x" (cm) in the magnetic field "b" (kG)
445 //---------------------------------------------------------------------
447 p[1]=fP[2]+(x-fX)*fP[4]*b*kB2C;
449 return Local2GlobalMomentum(p,fAlpha);
453 AliExternalTrackParam::GetXYZAt(Double_t x, Double_t b, Double_t *r) const {
454 //---------------------------------------------------------------------
455 // This function returns the global track position extrapolated to
456 // the radial position "x" (cm) in the magnetic field "b" (kG)
457 //---------------------------------------------------------------------
459 Double_t f1=fP[2], f2=f1 + dx*fP[4]*b*kB2C;
461 if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
463 Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
465 r[1] = fP[0] + dx*(f1+f2)/(r1+r2);
466 r[2] = fP[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fP[3];
467 return Local2GlobalPosition(r,fAlpha);
471 //_____________________________________________________________________________
472 void AliExternalTrackParam::Print(Option_t* /*option*/) const
474 // print the parameters and the covariance matrix
476 printf("AliExternalTrackParam: x = %-12g alpha = %-12g\n", fX, fAlpha);
477 printf(" parameters: %12g %12g %12g %12g %12g\n",
478 fP[0], fP[1], fP[2], fP[3], fP[4]);
479 printf(" covariance: %12g\n", fC[0]);
480 printf(" %12g %12g\n", fC[1], fC[2]);
481 printf(" %12g %12g %12g\n", fC[3], fC[4], fC[5]);
482 printf(" %12g %12g %12g %12g\n",
483 fC[6], fC[7], fC[8], fC[9]);
484 printf(" %12g %12g %12g %12g %12g\n",
485 fC[10], fC[11], fC[12], fC[13], fC[14]);