2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
8 // for The ALICE HLT Project. *
10 // Permission to use, copy, modify and distribute this software and its *
11 // documentation strictly for non-commercial purposes is hereby granted *
12 // without fee, provided that the above copyright notice appears in all *
13 // copies and that both the copyright notice and this permission notice *
14 // appear in the supporting documentation. The authors make no claims *
15 // about the suitability of this software for any purpose. It is *
16 // provided "as is" without express or implied warranty. *
18 //***************************************************************************
21 #include "AliHLTTPCCATrackParam.h"
22 #include "AliHLTTPCCAMath.h"
23 #include "AliHLTTPCCATrackLinearisation.h"
29 // kCLight = 0.000299792458;
30 // Kappa = -Bz*kCLight*QPt;
31 // R = 1/TMath::Abs(Kappa);
32 // Xc = X - sin(Phi)/Kappa;
33 // Yc = Y + cos(Phi)/Kappa;
36 GPUd() float AliHLTTPCCATrackParam::GetDist2( const AliHLTTPCCATrackParam &t ) const
38 // get squared distance between tracks
40 float dx = GetX() - t.GetX();
41 float dy = GetY() - t.GetY();
42 float dz = GetZ() - t.GetZ();
43 return dx*dx + dy*dy + dz*dz;
46 GPUd() float AliHLTTPCCATrackParam::GetDistXZ2( const AliHLTTPCCATrackParam &t ) const
48 // get squared distance between tracks in X&Z
50 float dx = GetX() - t.GetX();
51 float dz = GetZ() - t.GetZ();
56 GPUd() float AliHLTTPCCATrackParam::GetS( float x, float y, float Bz ) const
58 //* Get XY path length to the given point
60 float k = GetKappa( Bz );
61 float ex = GetCosPhi();
62 float ey = GetSinPhi();
65 float dS = x * ex + y * ey;
66 if ( CAMath::Abs( k ) > 1.e-4 ) dS = CAMath::ATan2( k * dS, 1 + k * ( x * ey - y * ex ) ) / k;
70 GPUd() void AliHLTTPCCATrackParam::GetDCAPoint( float x, float y, float z,
71 float &xp, float &yp, float &zp,
74 //* Get the track point closest to the (x,y,z)
78 float k = GetKappa( Bz );
79 float ex = GetCosPhi();
80 float ey = GetSinPhi();
83 float ax = dx * k + ey;
84 float ay = dy * k - ex;
85 float a = sqrt( ax * ax + ay * ay );
86 xp = x0 + ( dx - ey * ( ( dx * dx + dy * dy ) * k - 2 * ( -dx * ey + dy * ex ) ) / ( a + 1 ) ) / a;
87 yp = y0 + ( dy + ex * ( ( dx * dx + dy * dy ) * k - 2 * ( -dx * ey + dy * ex ) ) / ( a + 1 ) ) / a;
88 float s = GetS( x, y, Bz );
89 zp = GetZ() + GetDzDs() * s;
90 if ( CAMath::Abs( k ) > 1.e-2 ) {
91 float dZ = CAMath::Abs( GetDzDs() * CAMath::TwoPi() / k );
93 zp += CAMath::Nint( ( z - zp ) / dZ ) * dZ;
100 //* Transport routines
104 GPUd() bool AliHLTTPCCATrackParam::TransportToX( float x, AliHLTTPCCATrackLinearisation &t0, float Bz, float maxSinPhi, float *DL )
106 //* Transport the track parameters to X=x, using linearization at t0, and the field value Bz
107 //* maxSinPhi is the max. allowed value for |t0.SinPhi()|
108 //* linearisation of trajectory t0 is also transported to X=x,
112 float ex = t0.CosPhi();
113 float ey = t0.SinPhi();
114 float k =-t0.QPt() * Bz;
117 float ey1 = k * dx + ey;
120 // check for intersection with X=x
122 if ( CAMath::Abs( ey1 ) > maxSinPhi ) return 0;
124 ex1 = CAMath::Sqrt( 1 - ey1 * ey1 );
125 if ( ex < 0 ) ex1 = -ex1;
131 if ( CAMath::Abs( cc ) < 1.e-4 || CAMath::Abs( ex ) < 1.e-4 || CAMath::Abs( ex1 ) < 1.e-4 ) return 0;
133 float tg = ss / cc; // tan((phi1+phi)/2)
136 float dl = dx * CAMath::Sqrt( 1 + tg * tg );
138 if ( cc < 0 ) dl = -dl;
139 float dSin = dl * k / 2;
140 if ( dSin > 1 ) dSin = 1;
141 if ( dSin < -1 ) dSin = -1;
142 float dS = ( CAMath::Abs( k ) > 1.e-4 ) ? ( 2 * CAMath::ASin( dSin ) / k ) : dl;
143 float dz = dS * t0.DzDs();
145 if ( DL ) *DL = -dS * CAMath::Sqrt( 1 + t0.DzDs() * t0.DzDs() );
149 float ex1i = 1. / ex1;
158 //float H0[5] = { 1,0, h2, 0, h4 };
159 //float H1[5] = { 0, 1, 0, dS, 0 };
160 //float H2[5] = { 0, 0, 1, 0, dxBz };
161 //float H3[5] = { 0, 0, 0, 1, 0 };
162 //float H4[5] = { 0, 0, 0, 0, 1 };
164 float h2 = dx * ( 1 + ey * ey1 + ex * ex1 ) * exi * ex1i * cci;
165 float h4 = dx2 * ( cc + ss * ey1 * ex1i ) * cci * cci * (-Bz);
166 float dxBz = dx * (-Bz);
172 fP[0] = Y() + dy + h2 * d[2] + h4 * d[4];
173 fP[1] = Z() + dz + dS * d[3];
174 fP[2] = t0.SinPhi() + d[2] + dxBz * d[4];
192 fC[0] = ( c00 + h2 * h2 * c22 + h4 * h4 * c44
193 + 2 * ( h2 * c20 + h4 * c40 + h2 * h4 * c42 ) );
195 fC[1] = c10 + h2 * c21 + h4 * c41 + dS * ( c30 + h2 * c32 + h4 * c43 );
196 fC[2] = c11 + 2 * dS * c31 + dS * dS * c33;
198 fC[3] = c20 + h2 * c22 + h4 * c42 + dxBz * ( c40 + h2 * c42 + h4 * c44 );
199 fC[4] = c21 + dS * c32 + dxBz * ( c41 + dS * c43 );
200 fC[5] = c22 + 2 * dxBz * c42 + dxBz * dxBz * c44;
202 fC[6] = c30 + h2 * c32 + h4 * c43;
203 fC[7] = c31 + dS * c33;
204 fC[8] = c32 + dxBz * c43;
207 fC[10] = c40 + h2 * c42 + h4 * c44;
208 fC[11] = c41 + dS * c43;
209 fC[12] = c42 + dxBz * c44;
217 GPUd() bool AliHLTTPCCATrackParam::TransportToX( float x, float sinPhi0, float cosPhi0, float Bz, float maxSinPhi )
219 //* Transport the track parameters to X=x, using linearization at phi0 with 0 curvature,
220 //* and the field value Bz
221 //* maxSinPhi is the max. allowed value for |t0.SinPhi()|
222 //* linearisation of trajectory t0 is also transported to X=x,
230 if ( CAMath::Abs( ex ) < 1.e-4 ) return 0;
233 float dxBz = dx * (-Bz);
235 float h2 = dS * exi * exi;
236 float h4 = .5 * h2 * dxBz;
238 //float H0[5] = { 1,0, h2, 0, h4 };
239 //float H1[5] = { 0, 1, 0, dS, 0 };
240 //float H2[5] = { 0, 0, 1, 0, dxBz };
241 //float H3[5] = { 0, 0, 0, 1, 0 };
242 //float H4[5] = { 0, 0, 0, 0, 1 };
244 float sinPhi = SinPhi() + dxBz * QPt();
245 if ( maxSinPhi > 0 && CAMath::Abs( sinPhi ) > maxSinPhi ) return 0;
248 fP[0] += dS * ey + h2 * ( SinPhi() - ey ) + h4 * QPt();
249 fP[1] += dS * DzDs();
270 fC[0] = ( c00 + h2 * h2 * c22 + h4 * h4 * c44
271 + 2 * ( h2 * c20 + h4 * c40 + h2 * h4 * c42 ) );
273 fC[1] = c10 + h2 * c21 + h4 * c41 + dS * ( c30 + h2 * c32 + h4 * c43 );
274 fC[2] = c11 + 2 * dS * c31 + dS * dS * c33;
276 fC[3] = c20 + h2 * c22 + h4 * c42 + dxBz * ( c40 + h2 * c42 + h4 * c44 );
277 fC[4] = c21 + dS * c32 + dxBz * ( c41 + dS * c43 );
278 fC[5] = c22 + 2 * dxBz * c42 + dxBz * dxBz * c44;
280 fC[6] = c30 + h2 * c32 + h4 * c43;
281 fC[7] = c31 + dS * c33;
282 fC[8] = c32 + dxBz * c43;
285 fC[10] = c40 + h2 * c42 + h4 * c44;
286 fC[11] = c41 + dS * c43;
287 fC[12] = c42 + dxBz * c44;
299 GPUd() bool AliHLTTPCCATrackParam::TransportToX( float x, float Bz, float maxSinPhi )
301 //* Transport the track parameters to X=x
303 AliHLTTPCCATrackLinearisation t0( *this );
305 return TransportToX( x, t0, Bz, maxSinPhi );
310 GPUd() bool AliHLTTPCCATrackParam::TransportToXWithMaterial( float x, AliHLTTPCCATrackLinearisation &t0, AliHLTTPCCATrackFitParam &par, float Bz, float maxSinPhi )
312 //* Transport the track parameters to X=x taking into account material budget
314 const float kRho = 1.025e-3;//0.9e-3;
315 const float kRadLen = 29.532;//28.94;
316 const float kRhoOverRadLen = kRho / kRadLen;
319 if ( !TransportToX( x, t0, Bz, maxSinPhi, &dl ) ) return 0;
321 CorrectForMeanMaterial( dl*kRhoOverRadLen, dl*kRho, par );
326 GPUd() bool AliHLTTPCCATrackParam::TransportToXWithMaterial( float x, AliHLTTPCCATrackFitParam &par, float Bz, float maxSinPhi )
328 //* Transport the track parameters to X=x taking into account material budget
330 AliHLTTPCCATrackLinearisation t0( *this );
331 return TransportToXWithMaterial( x, t0, par, Bz, maxSinPhi );
334 GPUd() bool AliHLTTPCCATrackParam::TransportToXWithMaterial( float x, float Bz, float maxSinPhi )
336 //* Transport the track parameters to X=x taking into account material budget
338 AliHLTTPCCATrackFitParam par;
339 CalculateFitParameters( par );
340 return TransportToXWithMaterial( x, par, Bz, maxSinPhi );
345 //* Multiple scattering and energy losses
349 float AliHLTTPCCATrackParam::BetheBlochGeant( float bg2,
357 // This is the parameterization of the Bethe-Bloch formula inspired by Geant.
359 // bg2 - (beta*gamma)^2
360 // kp0 - density [g/cm^3]
361 // kp1 - density effect first junction point
362 // kp2 - density effect second junction point
363 // kp3 - mean excitation energy [GeV]
366 // The default values for the kp* parameters are for silicon.
367 // The returned value is in [GeV/(g/cm^2)].
370 const float mK = 0.307075e-3; // [GeV*cm^2/g]
371 const float me = 0.511e-3; // [GeV/c^2]
372 const float rho = kp0;
373 const float x0 = kp1 * 2.303;
374 const float x1 = kp2 * 2.303;
375 const float mI = kp3;
376 const float mZA = kp4;
377 const float maxT = 2 * me * bg2; // neglecting the electron mass
381 const float x = 0.5 * AliHLTTPCCAMath::Log( bg2 );
382 const float lhwI = AliHLTTPCCAMath::Log( 28.816 * 1e-9 * AliHLTTPCCAMath::Sqrt( rho * mZA ) / mI );
385 } else if ( x > x0 ) {
386 const float r = ( x1 - x ) / ( x1 - x0 );
387 d2 = lhwI + x - 0.5 + ( 0.5 - lhwI - x0 ) * r * r * r;
390 return mK*mZA*( 1 + bg2 ) / bg2*( 0.5*AliHLTTPCCAMath::Log( 2*me*bg2*maxT / ( mI*mI ) ) - bg2 / ( 1 + bg2 ) - d2 );
393 float AliHLTTPCCATrackParam::BetheBlochSolid( float bg )
395 //------------------------------------------------------------------
396 // This is an approximation of the Bethe-Bloch formula,
397 // reasonable for solid materials.
398 // All the parameters are, in fact, for Si.
399 // The returned value is in [GeV]
400 //------------------------------------------------------------------
402 return BetheBlochGeant( bg );
405 float AliHLTTPCCATrackParam::BetheBlochGas( float bg )
407 //------------------------------------------------------------------
408 // This is an approximation of the Bethe-Bloch formula,
409 // reasonable for gas materials.
410 // All the parameters are, in fact, for Ne.
411 // The returned value is in [GeV]
412 //------------------------------------------------------------------
414 const float rho = 0.9e-3;
417 const float mI = 140.e-9;
418 const float mZA = 0.49555;
420 return BetheBlochGeant( bg, rho, x0, x1, mI, mZA );
426 GPUd() float AliHLTTPCCATrackParam::ApproximateBetheBloch( float beta2 )
428 //------------------------------------------------------------------
429 // This is an approximation of the Bethe-Bloch formula with
430 // the density effect taken into account at beta*gamma > 3.5
431 // (the approximation is reasonable only for solid materials)
432 //------------------------------------------------------------------
433 if ( beta2 >= 1 ) return 0;
435 if ( beta2 / ( 1 - beta2 ) > 3.5*3.5 )
436 return 0.153e-3 / beta2*( log( 3.5*5940 ) + 0.5*log( beta2 / ( 1 - beta2 ) ) - beta2 );
437 return 0.153e-3 / beta2*( log( 5940*beta2 / ( 1 - beta2 ) ) - beta2 );
441 GPUd() void AliHLTTPCCATrackParam::CalculateFitParameters( AliHLTTPCCATrackFitParam &par, float mass )
445 float p2 = ( 1. + fP[3] * fP[3] );
446 float k2 = fP[4] * fP[4];
447 float mass2 = mass * mass;
448 float beta2 = p2 / ( p2 + mass2 * k2 );
450 float pp2 = ( k2 > 1.e-8 ) ? p2 / k2 : 10000; // impuls 2
452 //par.fBethe = BetheBlochGas( pp2/mass2);
453 par.fBethe = ApproximateBetheBloch( pp2 / mass2 );
454 par.fE = CAMath::Sqrt( pp2 + mass2 );
455 par.fTheta2 = 14.1 * 14.1 / ( beta2 * pp2 * 1e6 );
456 par.fEP2 = par.fE / pp2;
458 // Approximate energy loss fluctuation (M.Ivanov)
460 const float knst = 0.07; // To be tuned.
461 par.fSigmadE2 = knst * par.fEP2 * fP[4];
462 par.fSigmadE2 = par.fSigmadE2 * par.fSigmadE2;
464 par.fK22 = ( 1. + fP[3] * fP[3] );
465 par.fK33 = par.fK22 * par.fK22;
466 par.fK43 = fP[3] * fP[4] * par.fK22;
467 par.fK44 = fP[3] * fP[3] * fP[4] * fP[4];
472 GPUd() bool AliHLTTPCCATrackParam::CorrectForMeanMaterial( float xOverX0, float xTimesRho, const AliHLTTPCCATrackFitParam &par )
474 //------------------------------------------------------------------
475 // This function corrects the track parameters for the crossed material.
476 // "xOverX0" - X/X0, the thickness in units of the radiation length.
477 // "xTimesRho" - is the product length*density (g/cm^2).
478 //------------------------------------------------------------------
482 float &fC40 = fC[10];
483 float &fC41 = fC[11];
484 float &fC42 = fC[12];
485 float &fC43 = fC[13];
486 float &fC44 = fC[14];
488 //Energy losses************************
490 float dE = par.fBethe * xTimesRho;
491 if ( CAMath::Abs( dE ) > 0.3*par.fE ) return 0; //30% energy loss is too much!
492 float corr = ( 1. - par.fEP2 * dE );
493 if ( corr < 0.3 || corr > 1.3 ) return 0;
501 fC44 += par.fSigmadE2 * CAMath::Abs( dE );
503 //Multiple scattering******************
505 float theta2 = par.fTheta2 * CAMath::Abs( xOverX0 );
506 fC22 += theta2 * par.fK22 * ( 1. - fP[2] * fP[2] );
507 fC33 += theta2 * par.fK33;
508 fC43 += theta2 * par.fK43;
509 fC44 += theta2 * par.fK44;
520 GPUd() bool AliHLTTPCCATrackParam::Rotate( float alpha, float maxSinPhi )
522 //* Rotate the coordinate system in XY on the angle alpha
524 float cA = CAMath::Cos( alpha );
525 float sA = CAMath::Sin( alpha );
526 float x = X(), y = Y(), sP = SinPhi(), cP = GetCosPhi();
527 float cosPhi = cP * cA + sP * sA;
528 float sinPhi = -cP * sA + sP * cA;
530 if ( CAMath::Abs( sinPhi ) > maxSinPhi || CAMath::Abs( cosPhi ) < 1.e-2 || CAMath::Abs( cP ) < 1.e-2 ) return 0;
532 float j0 = cP / cosPhi;
533 float j2 = cosPhi / cP;
536 SetY( -x*sA + y*cA );
537 SetSignCosPhi( cosPhi );
541 //float J[5][5] = { { j0, 0, 0, 0, 0 }, // Y
542 // { 0, 1, 0, 0, 0 }, // Z
543 // { 0, 0, j2, 0, 0 }, // SinPhi
544 // { 0, 0, 0, 1, 0 }, // DzDs
545 // { 0, 0, 0, 0, 1 } }; // Kappa
546 //cout<<"alpha="<<alpha<<" "<<x<<" "<<y<<" "<<sP<<" "<<cP<<" "<<j0<<" "<<j2<<endl;
547 //cout<<" "<<fC[0]<<" "<<fC[1]<<" "<<fC[6]<<" "<<fC[10]<<" "<<fC[4]<<" "<<fC[5]<<" "<<fC[8]<<" "<<fC[12]<<endl;
559 //cout<<" "<<fC[0]<<" "<<fC[1]<<" "<<fC[6]<<" "<<fC[10]<<" "<<fC[4]<<" "<<fC[5]<<" "<<fC[8]<<" "<<fC[12]<<endl;
563 GPUd() bool AliHLTTPCCATrackParam::Rotate( float alpha, AliHLTTPCCATrackLinearisation &t0, float maxSinPhi )
565 //* Rotate the coordinate system in XY on the angle alpha
567 float cA = CAMath::Cos( alpha );
568 float sA = CAMath::Sin( alpha );
569 float x0 = X(), y0 = Y(), sP = t0.SinPhi(), cP = t0.CosPhi();
570 float cosPhi = cP * cA + sP * sA;
571 float sinPhi = -cP * sA + sP * cA;
573 if ( CAMath::Abs( sinPhi ) > maxSinPhi || CAMath::Abs( cosPhi ) < 1.e-2 || CAMath::Abs( cP ) < 1.e-2 ) return 0;
575 //float J[5][5] = { { j0, 0, 0, 0, 0 }, // Y
576 // { 0, 1, 0, 0, 0 }, // Z
577 // { 0, 0, j2, 0, 0 }, // SinPhi
578 // { 0, 0, 0, 1, 0 }, // DzDs
579 // { 0, 0, 0, 0, 1 } }; // Kappa
581 float j0 = cP / cosPhi;
582 float j2 = cosPhi / cP;
583 float d[2] = {Y() - y0, SinPhi() - sP};
585 SetX( x0*cA + y0*sA );
586 SetY( -x0*sA + y0*cA + j0*d[0] );
587 t0.SetCosPhi( cosPhi );
588 t0.SetSinPhi( sinPhi );
590 SetSinPhi( sinPhi + j2*d[1] );
607 GPUd() bool AliHLTTPCCATrackParam::Filter( float y, float z, float err2Y, float err2Z, float maxSinPhi )
609 //* Add the y,z measurement with the Kalman filter
625 if ( err2Y < 1.e-8 || err2Z < 1.e-8 ) return 0;
627 float mS0 = 1. / err2Y;
628 float mS2 = 1. / err2Z;
632 float k00, k11, k20, k31, k40;
641 float sinPhi = fP[2] + k20 * z0 ;
643 if ( maxSinPhi > 0 && CAMath::Abs( sinPhi ) >= maxSinPhi ) return 0;
646 fChi2 += mS0 * z0 * z0 + mS2 * z1 * z1 ;
654 fC[ 0] -= k00 * c00 ;
655 fC[ 3] -= k20 * c00 ;
656 fC[ 5] -= k20 * c20 ;
657 fC[10] -= k40 * c00 ;
658 fC[12] -= k40 * c20 ;
659 fC[14] -= k40 * c40 ;
661 fC[ 2] -= k11 * c11 ;
662 fC[ 7] -= k31 * c11 ;
663 fC[ 9] -= k31 * c31 ;
668 GPUd() bool AliHLTTPCCATrackParam::CheckNumericalQuality() const
670 //* Check that the track parameters and covariance matrix are reasonable
672 bool ok = AliHLTTPCCAMath::Finite( fX ) && AliHLTTPCCAMath::Finite( fSignCosPhi ) && AliHLTTPCCAMath::Finite( fChi2 ) && AliHLTTPCCAMath::Finite( fNDF );
674 const float *c = Cov();
675 for ( int i = 0; i < 15; i++ ) ok = ok && AliHLTTPCCAMath::Finite( c[i] );
676 for ( int i = 0; i < 5; i++ ) ok = ok && AliHLTTPCCAMath::Finite( Par()[i] );
678 if ( c[0] <= 0 || c[2] <= 0 || c[5] <= 0 || c[9] <= 0 || c[14] <= 0 ) ok = 0;
679 if ( c[0] > 5. || c[2] > 5. || c[5] > 2. || c[9] > 2 || ( CAMath::Abs( QPt() ) > 1.e-4 && c[14] > 2. ) ) ok = 0;
681 if ( CAMath::Abs( SinPhi() ) > .99 ) ok = 0;
682 if ( CAMath::Abs( QPt() ) > 1. / 0.05 ) ok = 0;
688 #if !defined(HLTCA_GPUCODE)
692 GPUd() void AliHLTTPCCATrackParam::Print() const
696 #if !defined(HLTCA_GPUCODE)
697 std::cout << "track: x=" << GetX() << " c=" << GetSignCosPhi() << ", P= " << GetY() << " " << GetZ() << " " << GetSinPhi() << " " << GetDzDs() << " " << GetQPt() << std::endl;
698 std::cout << "errs2: " << GetErr2Y() << " " << GetErr2Z() << " " << GetErr2SinPhi() << " " << GetErr2DzDs() << " " << GetErr2QPt() << std::endl;