FairRoot/PandaRoot
PndFTSCATrackParam.cxx
Go to the documentation of this file.
1 // $Id: AliHLTTPCCATrackParam.cxx,v 1.6 2011/05/20 16:11:22 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 // Mykhailo Pugach <M.Pugach@gsi.de> *
12 // Maksym Zyzak <M.Zyzak@gsi.de> *
13 // *
14 // Permission to use, copy, modify and distribute this software and its *
15 // documentation strictly for non-commercial purposes is hereby granted *
16 // without fee, provided that the above copyright notice appears in all *
17 // copies and that both the copyright notice and this permission notice *
18 // appear in the supporting documentation. The authors make no claims *
19 // about the suitability of this software for any purpose. It is *
20 // provided "as is" without express or implied warranty. *
21 // *
22 //***************************************************************************
23 
24 
25 #include "PndFTSCATrackParam.h"
26 #include "PndFTSCAMath.h"
27 #include <iostream>
28 
29 #ifdef PANDA_FTS
30 
32 { // TODO
33  UNUSED_PARAM1(t);
34  // in >> t.z;
35  // for ( int i = 0; i < 5; i++ ) in >> t.Par(i);
36  // for ( int i = 0; i < 15; i++ ) in >> t.Cov(i);
37  return in;
38 }
39 
41 { // TODO
42  UNUSED_PARAM1(t);
43  // out << t.X() << " "
44  // << t.SignCosPhi() << " "
45  // << t.Chi2() << " "
46  // << t.NDF()
47  // << '\n';
48  // for ( int i = 0; i < 5; i++ ) out << t.Par()[i] << " ";
49  // out << '\n';
50  // for ( int i = 0; i < 15; i++ ) out << t.Cov()[i] << " ";
51  // out << '\n';
52  return out;
53 }
54 
55 #else // PANDA_FTS
56 /*
57 float PndFTSCATrackParam::GetDist2( const PndFTSCATrackParam &t ) const
58 {
59  // get squared distance between tracks
60 
61  float dx = X() - t.X();
62  float dy = Y() - t.Y();
63  float dz = Z() - t.Z();
64  return dx*dx + dy*dy + dz*dz;
65 }
66 
67 float PndFTSCATrackParam::GetDistXZ2( const PndFTSCATrackParam &t ) const
68 {
69  // get squared distance between tracks in X&Z
70 
71  float dx = X() - t.X();
72  float dz = Z() - t.Z();
73  return dx*dx + dz*dz;
74 }
75 */
76 #include "PndFTSCAParam.h"
77 
78 float PndFTSCATrackParam::S( float x, float y, float Bz ) const
79 {
80  //* Get XY path length to the given point
81 
82  float k = Kappa( Bz );
83  float ex = CosPhi();
84  float ey = SinPhi();
85  x -= X();
86  y -= Y();
87  float dS = x * ex + y * ey;
88  if ( CAMath::Abs( k ) > 1.e-4 ) dS = CAMath::ATan2( k * dS, 1 + k * ( x * ey - y * ex ) ) / k;
89  return dS;
90 }
91 
92 void PndFTSCATrackParam::GetDCAPoint( float x, float y, float z,
93  float &xp, float &yp, float &zp,
94  float Bz ) const
95 {
96  //* Get the track point closest to the (x,y,z)
97 
98  float x0 = X();
99  float y0 = Y();
100  float k = Kappa( Bz );
101  float ex = CosPhi();
102  float ey = SinPhi();
103  float dx = x - x0;
104  float dy = y - y0;
105  float ax = dx * k + ey;
106  float ay = dy * k - ex;
107  float a = sqrt( ax * ax + ay * ay );
108  xp = x0 + ( dx - ey * ( ( dx * dx + dy * dy ) * k - 2 * ( -dx * ey + dy * ex ) ) / ( a + 1 ) ) / a;
109  yp = y0 + ( dy + ex * ( ( dx * dx + dy * dy ) * k - 2 * ( -dx * ey + dy * ex ) ) / ( a + 1 ) ) / a;
110  float s = S( x, y, Bz );
111  zp = Z() + DzDs() * s;
112  if ( CAMath::Abs( k ) > 1.e-2 ) {
113  float dZ = CAMath::Abs( DzDs() * CAMath::TwoPi() / k );
114  if ( dZ > .1 ) {
115  zp += CAMath::Nint( ( z - zp ) / dZ ) * dZ;
116  }
117  }
118 }
119 
120 bool PndFTSCATrackParam::Rotate( float alpha, float maxSinPhi )
121 {
122  //* Rotate the coordinate system in XY on the angle alpha
123 
124  const float cA = CAMath::Cos( alpha );
125  const float sA = CAMath::Sin( alpha );
126  const float x = X(), y = Y(), sP = SinPhi(), cP = CosPhi();
127  const float cosPhi = cP * cA + sP * sA;
128  const float sinPhi = -cP * sA + sP * cA;
129 
130  if ( CAMath::Abs( sinPhi ) > maxSinPhi || CAMath::Abs( cosPhi ) < 1.e-2 || CAMath::Abs( cP ) < 1.e-2 ) return 0;
131 
132  if ( fabs(alpha) > 3.1415 * 0.25 ) return 0; // allow turn by 45 degree only
133 
134  const float j0 = cP / cosPhi;
135  const float j2 = cosPhi / cP;
136 
137  fX = x*cA + y*sA;
138  fP[0] = -x*sA + y*cA;
139  fSignCosPhi = CAMath::Abs(cosPhi) / cosPhi;
140  fP[2] = sinPhi;
141 
142  // float J[5][5] = { { j0, 0, 0, 0, 0 }, // Y
143  // { 0, 1, 0, 0, 0 }, // Z
144  // { 0, 0, j2, 0, 0 }, // SinPhi
145  // { 0, 0, 0, 1, 0 }, // DzDs
146  // { 0, 0, 0, 0, 1 } }; // Kappa
147  fC[0] *= j0 * j0;
148  fC[1] *= j0;
149  fC[3] *= j0;
150  fC[6] *= j0;
151  fC[10] *= j0;
152 
153  fC[3] *= j2;
154  fC[4] *= j2;
155  fC[5] *= j2 * j2;
156  fC[8] *= j2;
157  fC[12] *= j2;
158 
159  fAlpha += alpha;
160 
161  return 1;
162 }
163 
164 
166 {
167  const bool rotated = Rotate( -fAlpha + hit.Angle() );
168  const bool transported = TransportToX0( hit.X0(), param.cBz() );
169  return rotated & transported;
170 }
171 
172 
174 {
175  in >> t.fX;
176  in >> t.fSignCosPhi;
177  in >> t.fChi2;
178  in >> t.fNDF;
179  for ( int i = 0; i < 5; i++ ) in >> t.fP[i];
180  for ( int i = 0; i < 15; i++ ) in >> t.fC[i];
181  return in;
182 }
183 
185 {
186  out << t.X() << " "
187  << t.SignCosPhi() << " "
188  << t.Chi2() << " "
189  << t.NDF()
190  << '\n';
191  for ( int i = 0; i < 5; i++ ) out << t.Par()[i] << " ";
192  out << '\n';
193  for ( int i = 0; i < 15; i++ ) out << t.Cov()[i] << " ";
194  out << '\n';
195  return out;
196 }
197 
198 bool PndFTSCATrackParam::GetXYZPxPyPzQ( float& x, float& y, float& z, float& px, float& py, float& pz, int &q, float cov[21] ) const
199 {
200  { // -- convert parameters
201 
202  x = X();
203  y = Y();
204  z = Z();
205 
206  const float pt = CAMath::Abs( 1.f / QPt() );
207  q = -( QPt() >=0 ? 1 : -1 );
208 
209  const float cosL = DzDs();
210  px = pt * CosPhi();
211  py = pt * SinPhi();
212  pz = pt * cosL;
213 
214  // -- convert cov matrix
215  // get jacobian
216  float J[6][6];
217  for (int i = 0; i < 6; i++)
218  for (int j = 0; j < 6; j++)
219  J[i][j] = 0;
220  J[0][0] = 1; // x -> x
221  J[1][1] = 1; // y -> y
222  J[2][2] = 1; // z -> z
223  J[3][3] = pt * CosPhi() / SinPhi();
224  J[3][5] = - q * pt * pt * CosPhi(); // q/pt -> px
225  J[4][3] = pt; // sinPhi -> py
226  J[4][5] = - q* pt * pt * SinPhi(); // q/pt -> py
227  J[5][4] = pt; // dz/ds -> pz
228  J[5][5] = - q* pt * pt * cosL; // q/pt -> pz
229 
230  float CovIn[6][6]; // triangular -> symmetric matrix
231  {
232  CovIn[0][0] = .000001f*.00001f; // dx. From nowhere. TODO
233  for (int i = 1; i < 6; i++) {
234  CovIn[i][0] = 0;
235  CovIn[0][i] = 0;
236  }
237  int k = 0;
238  for (int i = 1; i < 6; i++) {
239  for (int j = 1; j <= i; j++, k++) {
240  CovIn[i][j] = Cov()[k];
241  CovIn[j][i] = Cov()[k];
242  }
243  }
244  }
245 
246  float CovInJ[6][6]; // CovInJ = CovIn * J^t
247  for (int i = 0; i < 6; i++)
248  for (int j = 0; j < 6; j++) {
249  CovInJ[i][j] = 0;
250  for (int k = 0; k < 6; k++) {
251  CovInJ[i][j] += CovIn[i][k] * J[j][k];
252  }
253  }
254 
255  float CovOut[6][6]; // CovOut = J * CovInJ
256  for (int i = 0; i < 6; i++)
257  for (int j = 0; j < 6; j++) {
258  CovOut[i][j] = 0;
259  for (int k = 0; k < 6; k++) {
260  CovOut[i][j] += J[i][k] * CovInJ[k][j];
261  }
262  }
263 
264  // symmetric matrix -> triangular
265  {
266  int k = 0;
267  for (int i = 0; i < 6; i++) {
268  for (int j = 0; j <= i; j++, k++) {
269  cov[k] = CovOut[i][j];
270  ASSERT( !finite(CovOut[i][j]) || CovOut[i][j] == 0 || fabs( 1. - CovOut[j][i]/CovOut[i][j] ) <= 0.05,
271  "CovOut[" << i << "][" << j << "] == CovOut[" << j << "][" << i << "] : " << CovOut[i][j] << " == " << CovOut[j][i]);
272  }
273  }
274  }
275 
276  { // check cov matrix
277  bool ok = true;
278  int k = 0;
279  for (int i = 0; i < 6; i++) {
280  for (int j = 0; j <= i; j++, k++) {
281  ok &= finite( cov[k] );
282  }
283  ok &= ( cov[k-1] > 0 );
284  }
285  if (!ok) return false;
286  }
287  }
288 
289  // Rotate in XY plane to convert to global
290  {
291  const float alpha = Angle();
292 
293 #if defined(PANDA_STT) || defined(PANDA_FTS)
294  assert(0); // different coordinate transform for panda
295 #endif
296  const float cA = cos( alpha );
297  const float sA = sin( alpha );
298 
299  //float J[6][6] = { { cA, sA, 0, 0, 0, 0 }, // X
300  // { -sA, cA, 0, 0, 0, 0 }, // Y
301  // { 0, 0, 1, 0, 0, 0 }, // Z
302  // { 0, 0, 0, cA, sA, 0 }, // Px
303  // { 0, 0, 0, -sA, cA, 0 }, // Py
304  // { 0, 0, 0, 0, 0, 1 } }; // Pz
305 
306  float J[2][2] = { { cA, sA },
307  { -sA, cA } };
308 
309  { // convert x, y TODO optimize
310  const float xt = x, yt = y;
311  x = xt*cA + yt*sA;
312  y = -xt*sA + yt*cA;
313 
314  float Cov1[2][2]; // triangular -> symmetric matrix
315  Cov1[0][0] = cov[0];
316  Cov1[0][1] = cov[1];
317  Cov1[1][0] = cov[1];
318  Cov1[1][1] = cov[2];
319 
320  float Cov2[2][2]; // Cov2 = Cov1 * J^t
321  for (int i = 0; i < 2; i++)
322  for (int j = 0; j < 2; j++) {
323  Cov2[i][j] = 0;
324  for (int k = 0; k < 2; k++) {
325  Cov2[i][j] += Cov1[i][k] * J[j][k];
326  }
327  }
328 
329  // Cov1 = J * Cov2
330  for (int i = 0; i < 2; i++)
331  for (int j = 0; j < 2; j++) {
332  Cov1[i][j] = 0;
333  for (int k = 0; k < 2; k++) {
334  Cov1[i][j] += J[i][k] * Cov2[k][j];
335  }
336  }
337 
338  // symmetric matrix -> triangular
339  cov[0] = Cov1[0][0];
340  cov[1] = Cov1[0][1];
341  cov[2] = Cov1[1][1];
342  }
343 
344  { // convert Px, Py TODO optimize
345  const float xt = px, yt = py;
346  px = xt*cA + yt*sA;
347  py = -xt*sA + yt*cA;
348 
349  float Cov1[2][2]; // triangular -> symmetric matrix
350  Cov1[0][0] = cov[9];
351  Cov1[0][1] = cov[13];
352  Cov1[1][0] = cov[13];
353  Cov1[1][1] = cov[14];
354 
355 
356  float Cov2[2][2]; // Cov2 = Cov1 * J^t
357  for (int i = 0; i < 2; i++)
358  for (int j = 0; j < 2; j++) {
359  Cov2[i][j] = 0;
360  for (int k = 0; k < 2; k++) {
361  Cov2[i][j] += Cov1[i][k] * J[j][k];
362  }
363  }
364 
365  // Cov1 = J * Cov2
366  for (int i = 0; i < 2; i++)
367  for (int j = 0; j < 2; j++) {
368  Cov1[i][j] = 0;
369  for (int k = 0; k < 2; k++) {
370  Cov1[i][j] += J[i][k] * Cov2[k][j];
371  }
372  }
373 
374  // symmetric matrix -> triangular
375 
376  cov[9] = Cov1[0][0];
377  cov[13] = Cov1[0][1];
378  cov[14] = Cov1[1][1];
379  }
380  }
381 
382  return true;
383 }
384 
385 #endif // PANDA_FTS
Double_t x0
Definition: checkhelixhit.C:70
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
double dy
bool Transport(const FTSCAHit &hit, const PndFTSCAParam &param)
Int_t i
Definition: run_full.C:25
void GetDCAPoint(float x, float y, float z, float &px, float &py, float &pz, float Bz) const
bool Rotate(float alpha, float maxSinPhi=.999)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
float SignCosPhi() const
float Angle() const
Definition: FTSCAHits.h:71
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
TLorentzVector s
Definition: Pnd2DStar.C:50
static T Sin(const T &x)
Definition: PndCAMath.h:42
const float * Par() const
static T Cos(const T &x)
Definition: PndCAMath.h:43
float X0() const
Definition: FTSCAHits.h:41
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
static T Abs(const T &x)
Definition: PndCAMath.h:39
const float * Cov() const
Int_t a
Definition: anaLmdDigi.C:126
float cBz() const
Definition: PndFTSCAParam.h:49
std::istream & operator>>(std::istream &in, PndFTSCATrackParam &t)
float_m ok
Double_t y0
Definition: checkhelixhit.C:71
static T ATan2(const T &y, const T &x)
bool GetXYZPxPyPzQ(float &x, float &y, float &z, float &px, float &py, float &pz, int &q, float cov[21]) const
TFile * f
Definition: bump_analys.C:12
Double_t z
bool TransportToX0(float x, float Bz, float maxSinPhi=.999)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TFile * out
Definition: reco_muo.C:20
double dx
std::ostream & operator<<(std::ostream &out, const PndFTSCATrackParam &t)
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
Double_t x
static float TwoPi()
Definition: PndCAMath.h:61
#define ASSERT(v, msg)
Definition: PndCADef.h:56
float S(float x, float y, float Bz) const
TTree * t
Definition: bump_analys.C:13
Double_t y
double alpha
Definition: f_Init.h:9
int Nint(float x)
Definition: PndCAMath.h:117
double pz[39]
Definition: pipisigmas.h:14
float Kappa(float Bz) const