11 #ifndef ALIHLTTPCCATRACKPARAMVECTOR_H
12 #define ALIHLTTPCCATRACKPARAMVECTOR_H
14 #include "AliHLTTPCCADef.h"
15 #include "AliHLTTPCCAMath.h"
22 template<
typename T>
struct char_traits;
23 template<
typename _CharT,
typename _Traits>
class basic_istream;
24 typedef basic_istream<char, char_traits<char> > istream;
25 template<
typename _CharT,
typename _Traits>
class basic_ostream;
26 typedef basic_ostream<char, char_traits<char> > ostream;
43 fSignCosPhi( Vc::Zero ),
47 for (
int i = 0; i < 5; ++i ) fP[i].setZero();
48 for (
int i = 0; i < 15; ++i ) fC[i].setZero();
63 sfloat_v X()
const {
return fX; }
64 sfloat_v Y()
const {
return fP[0]; }
65 sfloat_v Z()
const {
return fP[1]; }
66 sfloat_v SinPhi()
const {
return fP[2]; }
67 sfloat_v DzDs()
const {
return fP[3]; }
68 sfloat_v QPt()
const {
return fP[4]; }
75 sfloat_v Chi2()
const {
return fChi2; }
76 short_v NDF()
const {
return fNDF; }
78 sfloat_v Err2Y()
const {
return fC[0]; }
79 sfloat_v Err2Z()
const {
return fC[2]; }
80 sfloat_v Err2SinPhi()
const {
return fC[5]; }
81 sfloat_v Err2DzDs()
const {
return fC[9]; }
82 sfloat_v Err2QPt()
const {
return fC[14]; }
84 sfloat_v GetX()
const {
return fX; }
85 sfloat_v GetY()
const {
return fP[0]; }
86 sfloat_v GetZ()
const {
return fP[1]; }
87 sfloat_v GetSinPhi()
const {
return fP[2]; }
88 sfloat_v GetDzDs()
const {
return fP[3]; }
89 sfloat_v GetQPt()
const {
return fP[4]; }
90 sfloat_v GetSignCosPhi()
const {
return fSignCosPhi; }
91 sfloat_v GetChi2()
const {
return fChi2; }
92 short_v GetNDF()
const {
return fNDF; }
94 sfloat_v GetKappa(
const sfloat_v &Bz )
const {
return fP[4]*Bz; }
95 sfloat_v GetCosPhiPositive()
const {
return CAMath::Sqrt( sfloat_v( Vc::One ) - SinPhi()*SinPhi() ); }
96 sfloat_v GetCosPhi()
const {
return fSignCosPhi*CAMath::Sqrt( sfloat_v( Vc::One ) - SinPhi()*SinPhi() ); }
98 sfloat_v GetErr2Y()
const {
return fC[0]; }
99 sfloat_v GetErr2Z()
const {
return fC[2]; }
100 sfloat_v GetErr2SinPhi()
const {
return fC[5]; }
101 sfloat_v GetErr2DzDs()
const {
return fC[9]; }
102 sfloat_v GetErr2QPt()
const {
return fC[14]; }
104 const sfloat_v *Par()
const {
return fP; }
105 const sfloat_v *Cov()
const {
return fC; }
107 const sfloat_v *GetPar()
const {
return fP; }
108 const sfloat_v *GetCov()
const {
return fC; }
112 for(
int i=0; i<5; i++) fP[i](m) = param.Par()[i];
113 for(
int i=0; i<15; i++) fC[i](m) = param.Cov()[i];
116 fChi2(m) = param.GetChi2();
117 fNDF(static_cast<short_m>(m)) = param.GetNDF();
120 void SetPar(
int i,
const sfloat_v &v ) { fP[i] = v; }
121 void SetPar(
int i,
const sfloat_v &v,
const sfloat_m &m ) { fP[i]( m ) = v; }
122 void SetCov(
int i,
const sfloat_v &v ) { fC[i] = v; }
123 void SetCov(
int i,
const sfloat_v &v,
const sfloat_m &m ) { fC[i]( m ) = v; }
125 void SetX(
const sfloat_v &v ) { fX = v; }
126 void SetY(
const sfloat_v &v ) { fP[0] = v; }
127 void SetZ(
const sfloat_v &v ) { fP[1] = v; }
128 void SetX(
const sfloat_v &v,
const sfloat_m &m ) { fX( m ) = v; }
129 void SetY(
const sfloat_v &v,
const sfloat_m &m ) { fP[0]( m ) = v; }
130 void SetZ(
const sfloat_v &v,
const sfloat_m &m ) { fP[1]( m ) = v; }
131 void SetSinPhi(
const sfloat_v &v ) { fP[2] = v; }
132 void SetSinPhi(
const sfloat_v &v,
const sfloat_m &m ) { fP[2]( m ) = v; }
133 void SetDzDs(
const sfloat_v &v ) { fP[3] = v; }
134 void SetDzDs(
const sfloat_v &v,
const sfloat_m &m ) { fP[3]( m ) = v; }
135 void SetQPt(
const sfloat_v &v ) { fP[4] = v; }
136 void SetQPt(
const sfloat_v &v,
const sfloat_m &m ) { fP[4]( m ) = v; }
137 void SetSignCosPhi(
const sfloat_v &v ) { fSignCosPhi = v; }
138 void SetSignCosPhi(
const sfloat_v &v,
const sfloat_m &m ) { fSignCosPhi(m) = v; }
139 void SetChi2(
const sfloat_v &v ) { fChi2 = v; }
140 void SetChi2(
const sfloat_v &v,
const sfloat_m &m ) { fChi2(m) = v; }
141 void SetNDF(
int v ) { fNDF = v; }
142 void SetNDF(
const short_v &v ) { fNDF = v; }
143 void SetNDF(
const short_v &v,
const short_m &m ) { fNDF(m) = v; }
149 sfloat_v GetS(
const sfloat_v &x,
const sfloat_v &y,
const sfloat_v &Bz )
const;
151 void GetDCAPoint(
const sfloat_v &x,
const sfloat_v &y,
const sfloat_v &z,
152 sfloat_v *px, sfloat_v *py, sfloat_v *pz,
const sfloat_v &Bz )
const;
155 sfloat_m TransportToXWithMaterial(
const sfloat_v &x,
const sfloat_v &Bz,
const float maxSinPhi = .999f );
157 sfloat_m TransportToX(
const sfloat_v &x,
const sfloat_v &Bz,
const float maxSinPhi = .999f,
const sfloat_m &mask = sfloat_m(
true ) );
160 const sfloat_v &Bz,
const float maxSinPhi = .999f, sfloat_v *DL = 0,
const sfloat_m &mask = sfloat_m(
true ) );
162 sfloat_m TransportToX(
const sfloat_v &x,
const sfloat_v &sinPhi0,
163 const sfloat_v &Bz,
const sfloat_v maxSinPhi = .999f,
const sfloat_m &mask = sfloat_m(
true ) );
166 AliHLTTPCCATrackFitParam &par,
const sfloat_v &Bz,
const float maxSinPhi = .999f,
const sfloat_m &mask = sfloat_m(
true ) );
168 sfloat_m TransportToXWithMaterial(
const sfloat_v &x,
169 AliHLTTPCCATrackFitParam &par,
const sfloat_v &Bz,
const float maxSinPhi = .999f );
172 const float maxSinPhi = .999f,
const sfloat_m &mask = sfloat_m(
true ) );
173 sfloat_m Rotate(
const sfloat_v &alpha,
const float maxSinPhi = .999f,
const sfloat_m &mask = sfloat_m(
true ) );
174 void RotateXY( sfloat_v alpha, sfloat_v &x, sfloat_v &y, sfloat_v &sin,
const sfloat_m &mask = sfloat_m(
true ) )
const ;
176 sfloat_m FilterWithMaterial(
const sfloat_v &y,
const sfloat_v &z, sfloat_v err2Y, sfloat_v err2Z,
177 float maxSinPhi=0.999f,
const sfloat_m &mask = sfloat_m(
true ) );
179 static sfloat_v ApproximateBetheBloch(
const sfloat_v &beta2 );
180 static sfloat_v BetheBlochGeant(
const sfloat_v &bg,
181 const sfloat_v &kp0 = 2.33f,
182 const sfloat_v &kp1 = 0.20f,
183 const sfloat_v &kp2 = 3.00f,
184 const sfloat_v &kp3 = 173e-9f,
185 const sfloat_v &kp4 = 0.49848f
187 static sfloat_v BetheBlochSolid(
const sfloat_v &bg );
188 static sfloat_v BetheBlochGas(
const sfloat_v &bg );
191 void CalculateFitParameters( AliHLTTPCCATrackFitParam &par,
const sfloat_v &mass = 0.13957f );
192 sfloat_m CorrectForMeanMaterial(
const sfloat_v &xOverX0,
const sfloat_v &xTimesRho,
193 const AliHLTTPCCATrackFitParam &par,
const sfloat_m &_mask );
195 sfloat_m FilterDelta(
const sfloat_m &mask,
const sfloat_v &dy,
const sfloat_v &dz,
196 sfloat_v err2Y, sfloat_v err2Z,
const float maxSinPhi = .999f );
197 sfloat_m
Filter(
const sfloat_m &mask,
const sfloat_v &y,
const sfloat_v &z,
198 sfloat_v err2Y, sfloat_v err2Z,
const float maxSinPhi = .999f );
204 sfloat_v fSignCosPhi;
213 inline sfloat_m AliHLTTPCCATrackParamVector::TransportToX(
const sfloat_v &x,
const sfloat_v &sinPhi0,
214 const sfloat_v &Bz,
const sfloat_v maxSinPhi,
const sfloat_m &_mask )
223 debugKF() <<
"Start TransportToX(" << x <<
", " << _mask <<
")\n" << *
this << std::endl;
225 const sfloat_v &ey = sinPhi0;
226 const sfloat_v &dx = x - X();
227 const sfloat_v &exi = sfloat_v( Vc::One ) * CAMath::RSqrt( sfloat_v( Vc::One ) - ey * ey );
229 const sfloat_v &dxBz = dx * Bz;
230 const sfloat_v &dS = dx * exi;
231 const sfloat_v &h2 = dS * exi * exi;
232 const sfloat_v &h4 = .5f * h2 * dxBz;
235 std::cout <<
" TrTo-sinPhi0 = " << sinPhi0 << std::endl;
239 const sfloat_v &sinPhi = SinPhi() + dxBz * QPt();
242 std::cout <<
" TrTo-sinPhi = " << sinPhi << std::endl;
244 sfloat_m mask = _mask && CAMath::Abs( exi ) <= 1.e4f;
245 mask &= ( (CAMath::Abs( sinPhi ) <= maxSinPhi) || (maxSinPhi <= 0.f) );
249 fP[0]( mask ) += dS * ey + h2 * ( SinPhi() - ey ) + h4 * QPt();
250 fP[1]( mask ) += dS * DzDs();
251 fP[2]( mask ) = sinPhi;
256 const sfloat_v c20 = fC[3];
258 const sfloat_v c22 = fC[5];
260 const sfloat_v c31 = fC[7];
262 const sfloat_v c33 = fC[9];
263 const sfloat_v c40 = fC[10];
265 const sfloat_v c42 = fC[12];
267 const sfloat_v c44 = fC[14];
269 const sfloat_v two( 2.f );
271 fC[0] ( mask ) += h2 * h2 * c22 + h4 * h4 * c44
272 + two * ( h2 * c20 + h4 * ( c40 + h2 * c42 ) );
275 fC[2] ( mask ) += dS * ( two * c31 + dS * c33 );
277 fC[3] ( mask ) += h2 * c22 + h4 * c42 + dxBz * ( c40 + h2 * c42 + h4 * c44 );
279 const sfloat_v &dxBz_c44 = dxBz * c44;
280 fC[12]( mask ) += dxBz_c44;
281 fC[5] ( mask ) += dxBz * ( two * c42 + dxBz_c44 );
284 fC[7] ( mask ) += dS * c33;
288 fC[10]( mask ) += h2 * c42 + h4 * c44;
293 debugKF() << mask <<
"\n" << *
this << std::endl;
299 inline sfloat_m AliHLTTPCCATrackParamVector::FilterDelta(
const sfloat_m &mask,
const sfloat_v &dy,
const sfloat_v &dz,
300 sfloat_v err2Y, sfloat_v err2Z,
const float maxSinPhi )
302 debugKF() <<
"Kalman filter( " << mask
307 <<
"\n):" << std::endl;
309 assert( err2Y > 0.f || !mask );
310 assert( err2Z > 0.f || !mask );
314 const sfloat_v c00 = fC[ 0];
315 const sfloat_v c11 = fC[ 2];
316 const sfloat_v c20 = fC[ 3];
317 const sfloat_v c31 = fC[ 7];
318 const sfloat_v c40 = fC[10];
323 if ( !( err2Y > 0.f || !mask ).isFull() ) {
324 std::cerr << err2Y << mask << ( err2Y > 0.f || !mask ) << c00 << std::endl;
327 assert( err2Y > 0.f || !mask );
328 assert( err2Z > 0.f || !mask );
330 const sfloat_v &z0 = dy;
331 const sfloat_v &z1 = dz;
333 const sfloat_v &mS0 = sfloat_v( Vc::One ) / err2Y;
334 const sfloat_v &mS2 = sfloat_v( Vc::One ) / err2Z;
337 debugKF() <<
"delta(mS0): " << CAMath::Abs( sfloat_v( Vc::One ) / err2Y - mS0 ) << std::endl;
338 debugKF() <<
"delta(mS2): " << CAMath::Abs( sfloat_v( Vc::One ) / err2Z - mS2 ) << std::endl;
339 assert( mS0 > 0.f || !mask );
340 assert( mS2 > 0.f || !mask );
344 const sfloat_v &k00 = c00 * mS0;
345 const sfloat_v &k20 = c20 * mS0;
346 const sfloat_v &k40 = c40 * mS0;
348 const sfloat_v &k11 = c11 * mS2;
349 const sfloat_v &k31 = c31 * mS2;
351 debugKF() <<
"delta(k00): " << ( c00 / err2Y - k00 ) << std::endl;
352 debugKF() <<
"delta(k20): " << ( c20 / err2Y - k20 ) << std::endl;
353 debugKF() <<
"delta(k40): " << ( c40 / err2Y - k40 ) << std::endl;
355 debugKF() <<
"delta(k11): " << ( c11 / err2Z - k11 ) << std::endl;
356 debugKF() <<
"delta(k31): " << ( c31 / err2Z - k31 ) << std::endl;
358 const sfloat_v &sinPhi = fP[2] + k20 * z0 ;
359 debugKF() <<
"delta(sinPhi): " << ( z0 * c20 / err2Y + fP[2] - sinPhi ) << std::endl;
361 assert( maxSinPhi > 0.f );
362 const sfloat_m &success = mask && err2Y >= 1.e-8f && err2Z >= 1.e-8f && CAMath::Abs( sinPhi ) < maxSinPhi;
364 fNDF ( static_cast<short_m>( success ) ) += 2;
365 fChi2 ( success ) += mS0 * z0 * z0 + mS2 * z1 * z1 ;
367 fP[ 0]( success ) += k00 * z0 ;
368 fP[ 1]( success ) += k11 * z1 ;
369 fP[ 2]( success ) = sinPhi ;
370 fP[ 3]( success ) += k31 * z1 ;
371 fP[ 4]( success ) += k40 * z0 ;
373 fC[ 0]( success ) -= k00 * c00 ;
374 fC[ 3]( success ) -= k20 * c00 ;
375 fC[ 5]( success ) -= k20 * c20 ;
376 fC[10]( success ) -= k40 * c00 ;
377 fC[12]( success ) -= k40 * c20 ;
378 fC[14]( success ) -= k40 * c40 ;
380 fC[ 2]( success ) -= k11 * c11 ;
381 fC[ 7]( success ) -= k31 * c11 ;
382 fC[ 9]( success ) -= k31 * c31 ;
384 const sfloat_m check = ( fC[ 0] >= 0.f ) && ( fC[ 2] >= 0.f ) && ( fC[ 5] >= 0.f ) && ( fC[ 9] >= 0.f ) && ( fC[14] >= 0.f );
386 assert( fC[ 0] >= 0.f );
387 assert( fC[ 2] >= 0.f );
388 assert( fC[ 5] >= 0.f );
389 assert( fC[ 9] >= 0.f );
390 assert( fC[14] >= 0.f );
392 return success && check;
395 inline sfloat_m AliHLTTPCCATrackParamVector::Filter(
const sfloat_m &mask,
const sfloat_v &y,
const sfloat_v &z,
396 sfloat_v err2Y, sfloat_v err2Z,
const float maxSinPhi )
398 debugKF() <<
"Kalman filter( " << mask
403 <<
"\n):" << std::endl;
405 assert( err2Y > 0.f || !mask );
406 assert( err2Z > 0.f || !mask );
410 const sfloat_v c00 = fC[ 0];
411 const sfloat_v c11 = fC[ 2];
412 const sfloat_v c20 = fC[ 3];
413 const sfloat_v c31 = fC[ 7];
414 const sfloat_v c40 = fC[10];
419 if ( !( err2Y > 0.f || !mask ).isFull() ) {
420 std::cerr << err2Y << mask << ( err2Y > 0.f || !mask ) << c00 << std::endl;
423 assert( err2Y > 0.f || !mask );
424 assert( err2Z > 0.f || !mask );
426 const sfloat_v &z0 = y - fP[0];
427 const sfloat_v &z1 = z - fP[1];
429 const sfloat_v &mS0 = sfloat_v( Vc::One ) / err2Y;
430 const sfloat_v &mS2 = sfloat_v( Vc::One ) / err2Z;
433 debugKF() <<
"delta(mS0): " << CAMath::Abs( sfloat_v( Vc::One ) / err2Y - mS0 ) << std::endl;
434 debugKF() <<
"delta(mS2): " << CAMath::Abs( sfloat_v( Vc::One ) / err2Z - mS2 ) << std::endl;
435 assert( mS0 > 0.f || !mask );
436 assert( mS2 > 0.f || !mask );
440 const sfloat_v &k00 = c00 * mS0;
441 const sfloat_v &k20 = c20 * mS0;
442 const sfloat_v &k40 = c40 * mS0;
444 const sfloat_v &k11 = c11 * mS2;
445 const sfloat_v &k31 = c31 * mS2;
447 debugKF() <<
"delta(k00): " << ( c00 / err2Y - k00 ) << std::endl;
448 debugKF() <<
"delta(k20): " << ( c20 / err2Y - k20 ) << std::endl;
449 debugKF() <<
"delta(k40): " << ( c40 / err2Y - k40 ) << std::endl;
451 debugKF() <<
"delta(k11): " << ( c11 / err2Z - k11 ) << std::endl;
452 debugKF() <<
"delta(k31): " << ( c31 / err2Z - k31 ) << std::endl;
454 const sfloat_v &sinPhi = fP[2] + k20 * z0 ;
455 debugKF() <<
"delta(sinPhi): " << ( z0 * c20 / err2Y + fP[2] - sinPhi ) << std::endl;
457 assert( maxSinPhi > 0.f );
458 const sfloat_m &success = mask && err2Y >= 1.e-8f && err2Z >= 1.e-8f && CAMath::Abs( sinPhi ) < maxSinPhi;
460 fNDF ( static_cast<short_m>( success ) ) += 2;
461 fChi2 ( success ) += mS0 * z0 * z0 + mS2 * z1 * z1 ;
463 fP[ 0]( success ) += k00 * z0 ;
464 fP[ 1]( success ) += k11 * z1 ;
465 fP[ 2]( success ) = sinPhi ;
466 fP[ 3]( success ) += k31 * z1 ;
467 fP[ 4]( success ) += k40 * z0 ;
469 fC[ 0]( success ) -= k00 * c00 ;
470 fC[ 3]( success ) -= k20 * c00 ;
471 fC[ 5]( success ) -= k20 * c20 ;
472 fC[10]( success ) -= k40 * c00 ;
473 fC[12]( success ) -= k40 * c20 ;
474 fC[14]( success ) -= k40 * c40 ;
476 fC[ 2]( success ) -= k11 * c11 ;
477 fC[ 7]( success ) -= k31 * c11 ;
478 fC[ 9]( success ) -= k31 * c31 ;
480 const sfloat_m check = ( fC[ 0] >= 0.f ) && ( fC[ 2] >= 0.f ) && ( fC[ 5] >= 0.f ) && ( fC[ 9] >= 0.f ) && ( fC[14] >= 0.f );
482 assert( fC[ 0] >= 0.f );
483 assert( fC[ 2] >= 0.f );
484 assert( fC[ 5] >= 0.f );
485 assert( fC[ 9] >= 0.f );
486 assert( fC[14] >= 0.f );
488 return success && check;
491 inline sfloat_m AliHLTTPCCATrackParamVector::Rotate(
const sfloat_v &alpha,
const float maxSinPhi,
const sfloat_m &mask )
495 const sfloat_v cA = CAMath::Cos( alpha );
496 const sfloat_v sA = CAMath::Sin( alpha );
497 const sfloat_v x = X(), y = Y(), sP = SinPhi(), cP = GetCosPhi();
498 const sfloat_v cosPhi = cP * cA + sP * sA;
499 const sfloat_v sinPhi = -cP * sA + sP * cA;
501 sfloat_m mReturn = mask && (CAMath::Abs( sinPhi ) < maxSinPhi) && (CAMath::Abs( cosPhi ) > 1.e-2f) && (CAMath::Abs( cP ) > 1.e-2f);
503 const sfloat_v j0 = cP / cosPhi;
504 const sfloat_v j2 = cosPhi / cP;
506 SetX( x*cA + y*sA, mReturn);
507 SetY( -x*sA + y*cA, mReturn );
508 SetSignCosPhi( CAMath::Abs(cosPhi)/cosPhi, mReturn );
509 SetSinPhi( sinPhi, mReturn );
519 fC[0](mReturn) *= j0 * j0;
520 fC[1](mReturn) *= j0;
521 fC[3](mReturn) *= j0;
522 fC[6](mReturn) *= j0;
523 fC[10](mReturn) *= j0;
525 fC[3](mReturn) *= j2;
526 fC[4](mReturn) *= j2;
527 fC[5](mReturn) *= j2 * j2;
528 fC[8](mReturn) *= j2;
529 fC[12](mReturn) *= j2;
534 inline void AliHLTTPCCATrackParamVector::RotateXY( sfloat_v alpha, sfloat_v &x, sfloat_v &y, sfloat_v &sin,
const sfloat_m &mask )
const
537 const sfloat_v cA = CAMath::Cos( alpha );
538 const sfloat_v sA = CAMath::Sin( alpha );
540 x(mask) = ( X()*cA + Y()*sA );
541 y(mask) = ( -X()*sA + Y()*cA );
542 sin(mask) = -GetCosPhi() * sA + SinPhi() * cA;
sfloat_v SignCosPhi() const