StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AliHLTTPCCATrackParam.cxx
1 // $Id: AliHLTTPCCATrackParam.cxx,v 1.1 2016/02/05 23:27:29 fisyak Exp $
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
5 // *
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. *
9 // *
10 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
11 // Maksym Zyzak <M.Zyzak@gsi.de> *
12 // *
13 // Permission to use, copy, modify and distribute this software and its *
14 // documentation strictly for non-commercial purposes is hereby granted *
15 // without fee, provided that the above copyright notice appears in all *
16 // copies and that both the copyright notice and this permission notice *
17 // appear in the supporting documentation. The authors make no claims *
18 // about the suitability of this software for any purpose. It is *
19 // provided "as is" without express or implied warranty. *
20 // *
21 //***************************************************************************
22 
23 
24 #include "AliHLTTPCCATrackParam.h"
25 #include "AliHLTTPCCAMath.h"
26 #include "AliHLTTPCCATrackLinearisation.h"
27 #include <iostream>
28 
29 //
30 // Circle in XY:
31 //
32 // kCLight = 0.000299792458;
33 // Kappa = Bz*kCLight*QPt;
34 // R = 1/CAMath::Abs(Kappa);
35 // Xc = X - sin(Phi)/Kappa;
36 // Yc = Y + cos(Phi)/Kappa;
37 //
38 
39 float AliHLTTPCCATrackParam::GetDist2( const AliHLTTPCCATrackParam &t ) const
40 {
41  // get squared distance between tracks
42 
43  float dx = GetX() - t.GetX();
44  float dy = GetY() - t.GetY();
45  float dz = GetZ() - t.GetZ();
46  return dx*dx + dy*dy + dz*dz;
47 }
48 
49 float AliHLTTPCCATrackParam::GetDistXZ2( const AliHLTTPCCATrackParam &t ) const
50 {
51  // get squared distance between tracks in X&Z
52 
53  float dx = GetX() - t.GetX();
54  float dz = GetZ() - t.GetZ();
55  return dx*dx + dz*dz;
56 }
57 
58 
59 float AliHLTTPCCATrackParam::GetS( float x, float y, float Bz ) const
60 {
61  //* Get XY path length to the given point
62 
63  float k = GetKappa( Bz );
64  float ex = GetCosPhi();
65  float ey = GetSinPhi();
66  x -= GetX();
67  y -= GetY();
68  float dS = x * ex + y * ey;
69  if ( CAMath::Abs( k ) > 1.e-4 ) dS = CAMath::ATan2( k * dS, 1 + k * ( x * ey - y * ex ) ) / k;
70  return dS;
71 }
72 
73 void AliHLTTPCCATrackParam::GetDCAPoint( float x, float y, float z,
74  float &xp, float &yp, float &zp,
75  float Bz ) const
76 {
77  //* Get the track point closest to the (x,y,z)
78 
79  float x0 = GetX();
80  float y0 = GetY();
81  float k = GetKappa( Bz );
82  float ex = GetCosPhi();
83  float ey = GetSinPhi();
84  float dx = x - x0;
85  float dy = y - y0;
86  float ax = dx * k + ey;
87  float ay = dy * k - ex;
88  float a = sqrt( ax * ax + ay * ay );
89  xp = x0 + ( dx - ey * ( ( dx * dx + dy * dy ) * k - 2 * ( -dx * ey + dy * ex ) ) / ( a + 1 ) ) / a;
90  yp = y0 + ( dy + ex * ( ( dx * dx + dy * dy ) * k - 2 * ( -dx * ey + dy * ex ) ) / ( a + 1 ) ) / a;
91  float s = GetS( x, y, Bz );
92  zp = GetZ() + GetDzDs() * s;
93  if ( CAMath::Abs( k ) > 1.e-2 ) {
94  float dZ = CAMath::Abs( GetDzDs() * CAMath::TwoPi() / k );
95  if ( dZ > .1 ) {
96  zp += CAMath::Nint( ( z - zp ) / dZ ) * dZ;
97  }
98  }
99 }
100 
101 
102 //*
103 //* Transport routines
104 //*
105 
106 bool AliHLTTPCCATrackParam::TransportToX( float x, float sinPhi0, float cosPhi0, float Bz, float maxSinPhi )
107 {
108  //* Transport the track parameters to X=x, using linearization at phi0 with 0 curvature,
109  //* and the field value Bz
110  //* maxSinPhi is the max. allowed value for |t0.SinPhi()|
111  //* linearisation of trajectory t0 is also transported to X=x,
112  //* returns 1 if OK
113  //*
114 
115  const float ex = cosPhi0;
116  const float ey = sinPhi0;
117  const float dx = x - X();
118 
119  if ( CAMath::Abs( ex ) < 1.e-4 ) return 0;
120  const float exi = 1. / ex;
121 
122  const float dxBz = dx * Bz;
123  const float dS = dx * exi;
124  const float h2 = dS * exi * exi;
125  const float h4 = .5 * h2 * dxBz;
126 
127  //const float H0[5] = { 1,0, h2, 0, h4 };
128  //const float H1[5] = { 0, 1, 0, dS, 0 };
129  //const float H2[5] = { 0, 0, 1, 0, dxBz };
130  //const float H3[5] = { 0, 0, 0, 1, 0 };
131  //const float H4[5] = { 0, 0, 0, 0, 1 };
132 
133  const float sinPhi = SinPhi() + dxBz * QPt();
134  if ( maxSinPhi > 0 && CAMath::Abs( sinPhi ) > maxSinPhi ) return 0;
135 
136  fX = X() + dx;
137  fP[0] += dS * ey + h2 * ( SinPhi() - ey ) + h4 * QPt();
138  fP[1] += dS * DzDs();
139  fP[2] = sinPhi;
140 
141  const float c00 = fC[0];
142  const float c10 = fC[1];
143  const float c11 = fC[2];
144  const float c20 = fC[3];
145  const float c21 = fC[4];
146  const float c22 = fC[5];
147  const float c30 = fC[6];
148  const float c31 = fC[7];
149  const float c32 = fC[8];
150  const float c33 = fC[9];
151  const float c40 = fC[10];
152  const float c41 = fC[11];
153  const float c42 = fC[12];
154  const float c43 = fC[13];
155  const float c44 = fC[14];
156 
157 
158  fC[0] = ( c00 + h2 * h2 * c22 + h4 * h4 * c44
159  + 2 * ( h2 * c20 + h4 * c40 + h2 * h4 * c42 ) );
160 
161  fC[1] = c10 + h2 * c21 + h4 * c41 + dS * ( c30 + h2 * c32 + h4 * c43 );
162  fC[2] = c11 + 2 * dS * c31 + dS * dS * c33;
163 
164  fC[3] = c20 + h2 * c22 + h4 * c42 + dxBz * ( c40 + h2 * c42 + h4 * c44 );
165  fC[4] = c21 + dS * c32 + dxBz * ( c41 + dS * c43 );
166  fC[5] = c22 + 2 * dxBz * c42 + dxBz * dxBz * c44;
167 
168  fC[6] = c30 + h2 * c32 + h4 * c43;
169  fC[7] = c31 + dS * c33;
170  fC[8] = c32 + dxBz * c43;
171  fC[9] = c33;
172 
173  fC[10] = c40 + h2 * c42 + h4 * c44;
174  fC[11] = c41 + dS * c43;
175  fC[12] = c42 + dxBz * c44;
176  fC[13] = c43;
177  fC[14] = c44;
178 
179  return 1;
180 }
181 
182 bool AliHLTTPCCATrackParam::TransportToX( float x, float Bz, float maxSinPhi )
183 {
184  //* Transport the track parameters to X=x
185 
186  AliHLTTPCCATrackLinearisation t0( *this );
187 
188  return TransportToX( x, t0, Bz, maxSinPhi );
189 }
190 
191 bool AliHLTTPCCATrackParam::TransportToXWithMaterial( float x, float Bz, float maxSinPhi )
192 {
193  //* Transport the track parameters to X=x taking into account material budget
194 
195  AliHLTTPCCATrackFitParam par;
196  CalculateFitParameters( par );
197  return TransportToXWithMaterial( x, par, Bz, maxSinPhi );
198 }
199 
200 
201 //*
202 //* Multiple scattering and energy losses
203 //*
204 
205 
206 float AliHLTTPCCATrackParam::BetheBlochGeant( float bg2,
207  float kp0,
208  float kp1,
209  float kp2,
210  float kp3,
211  float kp4 )
212 {
213  //
214  // This is the parameterization of the Bethe-Bloch formula inspired by Geant.
215  //
216  // bg2 - (beta*gamma)^2
217  // kp0 - density [g/cm^3]
218  // kp1 - density effect first junction point
219  // kp2 - density effect second junction point
220  // kp3 - mean excitation energy [GeV]
221  // kp4 - mean Z/A
222  //
223  // The default values for the kp* parameters are for silicon.
224  // The returned value is in [GeV/(g/cm^2)].
225  //
226 
227  const float mK = 0.307075e-3; // [GeV*cm^2/g]
228  const float me = 0.511e-3; // [GeV/c^2]
229  const float rho = kp0;
230  const float x0 = kp1 * 2.303;
231  const float x1 = kp2 * 2.303;
232  const float mI = kp3;
233  const float mZA = kp4;
234  const float maxT = 2 * me * bg2; // neglecting the electron mass
235 
236  //*** Density effect
237  float d2 = 0.;
238  const float x = 0.5 * CAMath::Log( bg2 );
239  const float lhwI = CAMath::Log( 28.816 * 1e-9 * CAMath::Sqrt( rho * mZA ) / mI );
240  if ( x > x1 ) {
241  d2 = lhwI + x - 0.5;
242  } else if ( x > x0 ) {
243  const float r = ( x1 - x ) / ( x1 - x0 );
244  d2 = lhwI + x - 0.5 + ( 0.5 - lhwI - x0 ) * r * r * r;
245  }
246 
247  return mK*mZA*( 1 + bg2 ) / bg2*( 0.5*CAMath::Log( 2*me*bg2*maxT / ( mI*mI ) ) - bg2 / ( 1 + bg2 ) - d2 );
248 }
249 
250 float AliHLTTPCCATrackParam::BetheBlochSolid( float bg )
251 {
252  //------------------------------------------------------------------
253  // This is an approximation of the Bethe-Bloch formula,
254  // reasonable for solid materials.
255  // All the parameters are, in fact, for Si.
256  // The returned value is in [GeV]
257  //------------------------------------------------------------------
258 
259  return BetheBlochGeant( bg );
260 }
261 
262 float AliHLTTPCCATrackParam::BetheBlochGas( float bg )
263 {
264  //------------------------------------------------------------------
265  // This is an approximation of the Bethe-Bloch formula,
266  // reasonable for gas materials.
267  // All the parameters are, in fact, for Ne.
268  // The returned value is in [GeV]
269  //------------------------------------------------------------------
270 
271  const float rho = 0.9e-3;
272  const float x0 = 2.;
273  const float x1 = 4.;
274  const float mI = 140.e-9;
275  const float mZA = 0.49555;
276 
277  return BetheBlochGeant( bg, rho, x0, x1, mI, mZA );
278 }
279 
280 
281 
282 
283 
284 
285 //*
286 //* Rotation
287 //*
288 
289 
290 bool AliHLTTPCCATrackParam::Rotate( float alpha, float maxSinPhi )
291 {
292  //* Rotate the coordinate system in XY on the angle alpha
293 
294  const float cA = CAMath::Cos( alpha );
295  const float sA = CAMath::Sin( alpha );
296  const float x = X(), y = Y(), sP = SinPhi(), cP = GetCosPhi();
297  const float cosPhi = cP * cA + sP * sA;
298  const float sinPhi = -cP * sA + sP * cA;
299 
300  if ( CAMath::Abs( sinPhi ) > maxSinPhi || CAMath::Abs( cosPhi ) < 1.e-2 || CAMath::Abs( cP ) < 1.e-2 ) return 0;
301 
302  const float j0 = cP / cosPhi;
303  const float j2 = cosPhi / cP;
304 
305  SetX( x*cA + y*sA );
306  SetY( -x*sA + y*cA );
307  SetSignCosPhi( CAMath::Abs(cosPhi)/cosPhi );
308  SetSinPhi( sinPhi );
309 
310 
311  //float J[5][5] = { { j0, 0, 0, 0, 0 }, // Y
312  // { 0, 1, 0, 0, 0 }, // Z
313  // { 0, 0, j2, 0, 0 }, // SinPhi
314  // { 0, 0, 0, 1, 0 }, // DzDs
315  // { 0, 0, 0, 0, 1 } }; // Kappa
316  //cout<<"alpha="<<alpha<<" "<<x<<" "<<y<<" "<<sP<<" "<<cP<<" "<<j0<<" "<<j2<<endl;
317  //cout<<" "<<fC[0]<<" "<<fC[1]<<" "<<fC[6]<<" "<<fC[10]<<" "<<fC[4]<<" "<<fC[5]<<" "<<fC[8]<<" "<<fC[12]<<endl;
318  fC[0] *= j0 * j0;
319  fC[1] *= j0;
320  fC[3] *= j0;
321  fC[6] *= j0;
322  fC[10] *= j0;
323 
324  fC[3] *= j2;
325  fC[4] *= j2;
326  fC[5] *= j2 * j2;
327  fC[8] *= j2;
328  fC[12] *= j2;
329  //cout<<" "<<fC[0]<<" "<<fC[1]<<" "<<fC[6]<<" "<<fC[10]<<" "<<fC[4]<<" "<<fC[5]<<" "<<fC[8]<<" "<<fC[12]<<endl;
330  return 1;
331 }
332 
333 bool AliHLTTPCCATrackParam::Rotate( float alpha, AliHLTTPCCATrackLinearisation &t0, float maxSinPhi )
334 {
335  //* Rotate the coordinate system in XY on the angle alpha
336 
337  const float cA = CAMath::Cos( alpha );
338  const float sA = CAMath::Sin( alpha );
339  const float x0 = X(), y0 = Y(), sP = t0.SinPhi(), cP = t0.CosPhi();
340  const float cosPhi = cP * cA + sP * sA;
341  const float sinPhi = -cP * sA + sP * cA;
342 
343  if ( CAMath::Abs( sinPhi ) > maxSinPhi || CAMath::Abs( cosPhi ) < 1.e-2 || CAMath::Abs( cP ) < 1.e-2 ) return 0;
344 
345  //float J[5][5] = { { j0, 0, 0, 0, 0 }, // Y
346  // { 0, 1, 0, 0, 0 }, // Z
347  // { 0, 0, j2, 0, 0 }, // SinPhi
348  // { 0, 0, 0, 1, 0 }, // DzDs
349  // { 0, 0, 0, 0, 1 } }; // Kappa
350 
351  const float j0 = cP / cosPhi;
352  const float j2 = cosPhi / cP;
353  const float d[2] = {Y() - y0, SinPhi() - sP};
354 
355  SetX( x0*cA + y0*sA );
356  SetY( -x0*sA + y0*cA + j0*d[0] );
357  t0.SetCosPhi( cosPhi );
358  t0.SetSinPhi( sinPhi );
359 
360  SetSinPhi( sinPhi + j2*d[1] );
361 
362  fC[0] *= j0 * j0;
363  fC[1] *= j0;
364  fC[3] *= j0;
365  fC[6] *= j0;
366  fC[10] *= j0;
367 
368  fC[3] *= j2;
369  fC[4] *= j2;
370  fC[5] *= j2 * j2;
371  fC[8] *= j2;
372  fC[12] *= j2;
373 
374  return 1;
375 }
376 
377 
378 
379 /*bool AliHLTTPCCATrackParam::Filter( float y, float z, float err2Y, float err2Z, float maxSinPhi )
380 {
381  assert( maxSinPhi > 0.f );
383 
384  float
385  c00 = fC[ 0],
386  c11 = fC[ 2],
387  c20 = fC[ 3],
388  c31 = fC[ 7],
389  c40 = fC[10];
390 
391  err2Y += c00;
392  err2Z += c11;
393 
394  float
395  z0 = y - fP[0],
396  z1 = z - fP[1];
397 
398  if ( ISUNLIKELY( err2Y < 1.e-8f ) || ISUNLIKELY( err2Z < 1.e-8f ) ) return 0;
399 
400  float mS0 = 1.f / err2Y;
401  float mS2 = 1.f / err2Z;
402 
403  // K = CHtS
404 
405  float k00, k11, k20, k31, k40;
406 
407  k00 = c00 * mS0;
408  k20 = c20 * mS0;
409  k40 = c40 * mS0;
410 
411  k11 = c11 * mS2;
412  k31 = c31 * mS2;
413 
414  float sinPhi = fP[2] + k20 * z0 ;
415 
416  if ( ISUNLIKELY( CAMath::Abs( sinPhi ) >= maxSinPhi ) ) return 0;
417 
418  fNDF += 2;
419  fChi2 += mS0 * z0 * z0 + mS2 * z1 * z1 ;
420 
421  fP[ 0] += k00 * z0 ;
422  fP[ 1] += k11 * z1 ;
423  fP[ 2] = sinPhi ;
424  fP[ 3] += k31 * z1 ;
425  fP[ 4] += k40 * z0 ;
426 
427  fC[ 0] -= k00 * c00 ;
428  fC[ 3] -= k20 * c00 ;
429  fC[ 5] -= k20 * c20 ;
430  fC[10] -= k40 * c00 ;
431  fC[12] -= k40 * c20 ;
432  fC[14] -= k40 * c40 ;
433 
434  fC[ 2] -= k11 * c11 ;
435  fC[ 7] -= k31 * c11 ;
436  fC[ 9] -= k31 * c31 ;
437 
438  return 1;
439 }*/
440 
441 
442 
443 
444 #if !defined(HLTCA_GPUCODE)
445 #include <iostream>
446 #endif
447 
448 void AliHLTTPCCATrackParam::Print() const
449 {
450  //* print parameters
451 
452 #if !defined(HLTCA_GPUCODE)
453  std::cout << "track: x=" << GetX() << " c=" << GetSignCosPhi() << ", P= " << GetY() << " " << GetZ() << " " << GetSinPhi() << " " << GetDzDs() << " " << GetQPt() << std::endl;
454  std::cout << "errs2: " << GetErr2Y() << " " << GetErr2Z() << " " << GetErr2SinPhi() << " " << GetErr2DzDs() << " " << GetErr2QPt() << std::endl;
455 #endif
456 }
457 
458 std::istream &operator>>( std::istream &in, AliHLTTPCCATrackParam &t )
459 {
460  in >> t.fX;
461  in >> t.fSignCosPhi;
462  in >> t.fChi2;
463  in >> t.fNDF;
464  for ( int i = 0; i < 5; i++ ) in >> t.fP[i];
465  for ( int i = 0; i < 15; i++ ) in >> t.fC[i];
466  return in;
467 }
468 
469 std::ostream &operator<<( std::ostream &out, const AliHLTTPCCATrackParam &t )
470 {
471  out << t.X() << " "
472  << t.SignCosPhi() << " "
473  << t.Chi2() << " "
474  << t.NDF()
475  << '\n';
476  for ( int i = 0; i < 5; i++ ) out << t.Par()[i] << " ";
477  out << '\n';
478  for ( int i = 0; i < 15; i++ ) out << t.Cov()[i] << " ";
479  out << '\n';
480  return out;
481 }
482 
483 AliHLTTPCCATrackParam AliHLTTPCCATrackParam::GetGlobalParam(float alpha) const
484 {
485  AliHLTTPCCATrackParam r = *this;
486  r.Rotate( -alpha );
487  return r;
488 }