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