PandaRoot
PndFTSCATrackParam.h
Go to the documentation of this file.
1 
2 //-*- Mode: C++ -*-
3 // $Id: PndFTSCATrackParam.h,v 1.5 2011/05/20 16:28:05 fisyak Exp $
4 // ************************************************************************
5 // This file is property of and copyright by the ALICE HLT Project *
6 // ALICE Experiment at CERN, All rights reserved. *
7 // See cxx source for full Copyright notice *
8 // *
9 //*************************************************************************
10 
11 #ifndef PNDFTSCATRACKPARAM_H
12 #define PNDFTSCATRACKPARAM_H
13 #include <string.h>
14 #include "PndFTSCAMath.h"
16 #include "PndFTSCADef.h"
17 #include "FTSCAHits.h"
18 
19 #ifdef PANDA_FTS
20 
28 class PndFTSCATrackParam {
29  friend std::istream &operator>>(std::istream &, PndFTSCATrackParam &);
30  friend std::ostream &operator<<(std::ostream &, const PndFTSCATrackParam &);
31 
32  public:
33  PndFTSCATrackParam() { Reset(); }
35  : x(v.X()[i]), y(v.Y()[i]), tx(v.Tx()[i]), ty(v.Ty()[i]), qp(v.QP()[i]), z(v.Z()[i]), C00(v.Cov(0)[i]), C10(v.Cov(1)[i]), C11(v.Cov(2)[i]), C20(v.Cov(3)[i]), C21(v.Cov(4)[i]),
36  C22(v.Cov(5)[i]), C30(v.Cov(6)[i]), C31(v.Cov(7)[i]), C32(v.Cov(8)[i]), C33(v.Cov(9)[i]), C40(v.Cov(10)[i]), C41(v.Cov(11)[i]), C42(v.Cov(12)[i]), C43(v.Cov(13)[i]),
37  C44(v.Cov(14)[i]), chi2(v.Chi2()[i]), ndf(v.NDF()[i]), fAlpha(v.Angle()[i])
38  {
39  }
40 
41  float X0() const { return z; }
42  float X1() const { return x; }
43  float X2() const { return y; }
44  float Tx1() const { return tx; }
45  float Tx2() const { return ty; }
46 
47  float X() const { return x; }
48  float Y() const { return y; }
49  float Z() const { return z; }
50  float Tx() const { return tx; }
51  float Ty() const { return ty; }
52  float QP() const { return qp; }
53 
54  float Chi2() const { return chi2; }
55  int NDF() const { return ndf; }
56 
57  float QMomentum() const { return QP(); } // used for triplets comparison
58  float Angle() const { return fAlpha; }
59 
60  float Err2X1() const { return Err2X(); }
61  float Err2X2() const { return Err2Y(); }
62  float Err2Tx1() const { return Err2Tx(); }
63  float Err2Tx2() const { return Err2Ty(); }
64 
65  float Err2X() const { return C00; }
66  float Err2Y() const { return C11; }
67  float Err2Tx() const { return C22; }
68  float Err2Ty() const { return C33; }
69  float Err2QP() const { return C44; }
70  float Err2QMomentum() const { return Err2QP(); }
71 
72  float *Par() { return &x; }
73  float *Cov() { return &C00; }
74 
75  float Par(int i) const
76  {
77  switch (i) {
78  case 0: return x;
79  case 1: return y;
80  case 2: return tx;
81  case 3: return ty;
82  case 4: return qp;
83  }
84  assert(0);
85  return -1;
86  }
87 
88  float Cov(int i) const
89  {
90  switch (i) {
91  case 0: return C00;
92  case 1: return C10;
93  case 2: return C11;
94  case 3: return C20;
95  case 4: return C21;
96  case 5: return C22;
97  case 6: return C30;
98  case 7: return C31;
99  case 8: return C32;
100  case 9: return C33;
101  case 10: return C40;
102  case 11: return C41;
103  case 12: return C42;
104  case 13: return C43;
105  case 14: return C44;
106  }
107  assert(0);
108  return -1;
109  }
110 
111  void SetCov(int i, float v)
112  {
113  switch (i) {
114  case 0: C00 = v; break;
115  case 1: C10 = v; break;
116  case 2: C11 = v; break;
117  case 3: C20 = v; break;
118  case 4: C21 = v; break;
119  case 5: C22 = v; break;
120  case 6: C30 = v; break;
121  case 7: C31 = v; break;
122  case 8: C32 = v; break;
123  case 9: C33 = v; break;
124  case 10: C40 = v; break;
125  case 11: C41 = v; break;
126  case 12: C42 = v; break;
127  case 13: C43 = v; break;
128  case 14: C44 = v; break;
129  }
130  }
131 
132  void SetX(float v) { x = v; }
133  void SetY(float v) { y = v; }
134  void SetZ(float v) { z = v; }
135 
136  void SetTX(float v) { tx = v; }
137  void SetTY(float v) { ty = v; }
138  void SetQP(float v) { qp = v; }
139 
140  void SetChi2(float v) { chi2 = v; }
141  void SetNDF(int v) { ndf = v; }
142 
143  void Print() const;
144 
145  bool TransportToX0(const float &x_, const float &Bz)
146  {
147  UNUSED_PARAM1(Bz);
148  return TransportToX0Line(x_);
149  };
150 
151  bool Transport(const FTSCAHit &hit, const PndFTSCAParam &param)
152  {
154  v.ConvertTrackParamToVector(this, 1);
155  const float_m &mask = v.Transport(hit, param);
156  *this = PndFTSCATrackParam(v, 0);
157  return mask[0];
158  };
159 
160  bool Filter(const FTSCAHit &hit, const PndFTSCAParam &param)
161  {
163  v.ConvertTrackParamToVector(this, 1);
164  const float_m &mask = v.Filter(hit, param);
165  *this = PndFTSCATrackParam(v, 0);
166  return mask[0];
167  };
168 
169  void Reset()
170  {
171  x = y = tx = ty = qp = z = C00 = C10 = C11 = C20 = C21 = C22 = C30 = C31 = C32 = C33 = C40 = C41 = C42 = C43 = C44 = 0.f;
172  ndf = 0;
173  chi2 = -1;
174  }
175 
176  bool TransportToX0Line(float x0);
177 
178  bool IsValid() const { return chi2 != -1; }
179  void SetAsInvalid() { chi2 = -1; }
180 
181  bool Rotate(float) { return 1; }; // don't need rotation in CBM
182 
183  private:
184  float x, y, tx, ty, qp, z, C00, C10, C11, C20, C21, C22, C30, C31, C32, C33, C40, C41, C42, C43, C44;
185 
186  float chi2; // the chi^2 value
187  short ndf; // the Number of Degrees of Freedom
188 
189  float fAlpha; // coor system
190 };
191 
192 inline bool PndFTSCATrackParam::TransportToX0Line(float x0_out)
193 {
194  float dz = (x0_out - z);
195 
196  x += tx * dz;
197  y += ty * dz;
198  z += dz;
199 
200  const float dzC32_in = dz * C32;
201 
202  C21 += dzC32_in;
203  C10 += dz * (C21 + C30);
204 
205  const float C20_in = C20;
206 
207  C20 += dz * C22;
208  C00 += dz * (C20 + C20_in);
209 
210  const float C31_in = C31;
211 
212  C31 += dz * C33;
213  C11 += dz * (C31 + C31_in);
214  C30 += dzC32_in;
215 
216  C40 += dz * C42;
217  C41 += dz * C43;
218 
219  return 1;
220 }
221 
222 #else // PANDA_FTS
223 
225  friend std::istream &operator>>(std::istream &, PndFTSCATrackParam &);
226  friend std::ostream &operator<<(std::ostream &, const PndFTSCATrackParam &);
227 
228  public:
229  PndFTSCATrackParam() { Reset(); }
230  PndFTSCATrackParam(const TrackParamVector &v, int i) : fX(v.X()[i]), fSignCosPhi(v.SignCosPhi()[i]), fChi2(v.Chi2()[i]), fNDF(v.NDF()[i]), fAlpha(v.Angle()[i])
231  {
232  for (int j = 0; j < 5; ++j)
233  fP[j] = v.Par()[j][i];
234  for (int j = 0; j < 15; ++j)
235  fC[j] = v.Cov()[j][i];
236  }
237 
238  float X0() const { return fX; }
239  float X1() const { return Y(); }
240  float X2() const { return Z(); }
241 
242  float X() const { return fX; }
243  float Y() const { return fP[0]; }
244  float Z() const { return fP[1]; }
245  float SinPhi() const { return fP[2]; }
246  float DzDs() const { return fP[3]; }
247  float QPt() const { return fP[4]; }
248  float QP() const { return QPt() / sqrt(DzDs() * DzDs() + 1); }
249  float QMomentum() const { return QPt(); }
250 
251  float SignCosPhi() const { return fSignCosPhi; }
252  float Chi2() const { return fChi2; }
253  int NDF() const { return fNDF; }
254 
255  float Err2X1() const { return Err2Y(); }
256  float Err2X2() const { return Err2Z(); }
257 
258  float Err2Y() const { return fC[0]; }
259  float Err2Z() const { return fC[2]; }
260  float Err2SinPhi() const { return fC[5]; }
261  float Err2DzDs() const { return fC[9]; }
262  float Err2QPt() const { return fC[14]; }
263 
264  float Angle() const { return fAlpha; }
265 
266  float Kappa(float Bz) const { return fP[4] * Bz; }
267  float CosPhi() const { return fSignCosPhi * CAMath::Sqrt(1 - SinPhi() * SinPhi()); }
268 
269  float Err2QMomentum() const { return fC[14]; }
270 
271  const float *Par() const { return fP; }
272  const float *Cov() const { return fC; }
273 
274  bool GetXYZPxPyPzQ(float &x, float &y, float &z, float &px, float &py, float &pz, int &q, float cov[21]) const;
275 
276  void SetSinPhi(float v) { fP[2] = v; }
277 
278  void GetDCAPoint(float x, float y, float z, float &px, float &py, float &pz, float Bz) const;
279 
280  bool TransportToX0(float x, float Bz, float maxSinPhi = .999);
281 
282  bool Rotate(float alpha, float maxSinPhi = .999);
283 
284  bool Transport(const FTSCAHit &hit, const PndFTSCAParam &param);
285 
286  bool IsValid() const { return fChi2 != -1; }
287  void SetAsInvalid() { fChi2 = -1; }
288 
289  private:
290  void Reset()
291  {
292  fX = 0;
293  fSignCosPhi = 0;
294  for (int i = 0; i < 5; i++)
295  fP[i] = 0;
296  for (int i = 0; i < 15; i++)
297  fC[i] = 0;
298  fChi2 = 0;
299  fNDF = 0;
300  }
301  float S(float x, float y, float Bz) const;
302 
303  float fX; // x position
304  float fSignCosPhi; // sign of cosPhi // phi = arctg (Dy/Dx)
305  float fP[5]; // 'active' track parameters: Y, Z, SinPhi = dy/sqrt(dx*dx + dy*dy), DzDs = dz/sqrt(dx*dx + dy*dy), q/Pt
306  float fC[15]; // the covariance matrix for Y,Z,SinPhi,..
307  float fChi2; // the chi^2 value
308  int fNDF; // the Number of Degrees of Freedom
309 
310  float fAlpha; // coor system
311 };
312 
313 inline bool PndFTSCATrackParam::TransportToX0(float x, float Bz, float maxSinPhi)
314 {
315  //* Transport the track parameters to X=x, using linearization at t0, and the field value Bz
316  //* maxSinPhi is the max. allowed value for |t0.SinPhi()|
317  //* linearisation of trajectory t0 is also transported to X=x,
318  //* returns 1 if OK
319  //*
320 
321  const float ex = CosPhi();
322  const float ey = SinPhi();
323  const float k = QPt() * Bz;
324  const float dx = x - X();
325 
326  const float ey1 = k * dx + ey;
327 
328  // check for intersection with X=x
329 
330  if (CAMath::Abs(ey1) > maxSinPhi)
331  return 0;
332 
333  float ex1 = CAMath::Sqrt(1.f - ey1 * ey1);
334  if (ex < 0)
335  ex1 = -ex1;
336 
337  const float dx2 = dx * dx;
338  const float ss = ey + ey1;
339  const float cc = ex + ex1;
340 
341  if ((CAMath::Abs(cc) < 1.e-4 || CAMath::Abs(ex) < 1.e-4 || CAMath::Abs(ex1) < 1.e-4))
342  return 0;
343 
344  const float cci = 1.f / cc;
345  const float exi = 1.f / ex;
346  const float ex1i = 1.f / ex1;
347 
348  const float tg = ss * cci; // tan((phi1+phi)/2)
349 
350  const float dy = dx * tg;
351  float dl = dx * CAMath::Sqrt(1.f + tg * tg);
352 
353  if (cc < 0)
354  dl = -dl;
355  float dSin = dl * k * 0.5;
356  if (dSin > 1.f)
357  dSin = 1.f;
358  if (dSin < -1.f)
359  dSin = -1.f;
360  const float dS = (CAMath::Abs(k) > 1.e-4) ? (2 * CAMath::ASin(dSin) / k) : dl;
361  const float dz = dS * DzDs();
362 
363  // float H0[5] = { 1,0, h2, 0, h4 };
364  // float H1[5] = { 0, 1, 0, dS, 0 };
365  // float H2[5] = { 0, 0, 1, 0, dxBz };
366  // float H3[5] = { 0, 0, 0, 1, 0 };
367  // float H4[5] = { 0, 0, 0, 0, 1 };
368 
369  const float h2 = dx * (1.f + ey * ey1 + ex * ex1) * exi * ex1i * cci;
370  const float h4 = dx2 * (cc + ss * ey1 * ex1i) * cci * cci * Bz;
371  const float dxBz = dx * Bz;
372 
373  fX = X() + dx;
374  fP[0] = Y() + dy;
375  fP[1] = Z() + dz;
376  fP[2] = ey1;
377 
378 #if 1
379  const float c00 = fC[0];
380  const float c10 = fC[1];
381  const float c11 = fC[2];
382  const float c20 = fC[3];
383  const float c21 = fC[4];
384  const float c22 = fC[5];
385  const float c30 = fC[6];
386  const float c31 = fC[7];
387  const float c32 = fC[8];
388  const float c33 = fC[9];
389  const float c40 = fC[10];
390  const float c41 = fC[11];
391  const float c42 = fC[12];
392  const float c43 = fC[13];
393  const float c44 = fC[14];
394 
395  fC[0] = (c00 + h2 * h2 * c22 + h4 * h4 * c44 + 2.f * (h2 * c20 + h4 * c40 + h2 * h4 * c42));
396 
397  fC[1] = c10 + h2 * c21 + h4 * c41 + dS * (c30 + h2 * c32 + h4 * c43);
398  fC[2] = c11 + 2.f * dS * c31 + dS * dS * c33;
399 
400  fC[3] = c20 + h2 * c22 + h4 * c42 + dxBz * (c40 + h2 * c42 + h4 * c44);
401  fC[4] = c21 + dS * c32 + dxBz * (c41 + dS * c43);
402  fC[5] = c22 + 2.f * dxBz * c42 + dxBz * dxBz * c44;
403 
404  fC[6] = c30 + h2 * c32 + h4 * c43;
405  fC[7] = c31 + dS * c33;
406  fC[8] = c32 + dxBz * c43;
407  fC[9] = c33;
408 
409  fC[10] = c40 + h2 * c42 + h4 * c44;
410  fC[11] = c41 + dS * c43;
411  fC[12] = c42 + dxBz * c44;
412  fC[13] = c43;
413  fC[14] = c44;
414 #else
415  fC[0] = (fC[0] + h2 * h2 * fC[5] + h4 * h4 * fC[14] + 2 * (h2 * fC[3] + h4 * fC[10] + h2 * h4 * fC[12]));
416 
417  fC[1] = fC[1] + h2 * fC[4] + h4 * fC[11] + dS * (fC[6] + h2 * fC[8] + h4 * fC[13]);
418  fC[2] = fC[2] + 2 * dS * fC[7] + dS * dS * fC[9];
419 
420  fC[3] = fC[3] + h2 * fC[5] + h4 * fC[12] + dxBz * (fC[10] + h2 * fC[12] + h4 * fC[14]);
421  fC[4] = fC[4] + dS * fC[8] + dxBz * (fC[11] + dS * fC[13]);
422  fC[5] = fC[5] + 2 * dxBz * fC[12] + dxBz * dxBz * fC[14];
423 
424  fC[6] = fC[6] + h2 * fC[8] + h4 * fC[13];
425  fC[7] = fC[7] + dS * fC[9];
426  fC[8] = fC[8] + dxBz * fC[13];
427  fC[9] = fC[9];
428 
429  fC[10] = fC[10] + h2 * fC[12] + h4 * fC[14];
430  fC[11] = fC[11] + dS * fC[13];
431  fC[12] = fC[12] + dxBz * fC[14];
432  fC[13] = fC[13];
433  fC[14] = fC[14];
434 #endif
435 
436  return 1;
437 }
438 
439 #endif // PANDA_FTS
440 
442 
443 std::istream &operator>>(std::istream &in, PndFTSCATrackParam &ot);
444 std::ostream &operator<<(std::ostream &out, const PndFTSCATrackParam &ot);
445 
446 #endif
static T ASin(const T &x)
basic_istream< char, char_traits< char > > istream
bool GetXYZPxPyPzQ(float &x, float &y, float &z, float &px, float &py, float &pz, int &q, float cov[21]) const
float Kappa(float Bz) const
bool Transport(const FTSCAHit &hit, const PndFTSCAParam &param)
bool Rotate(float alpha, float maxSinPhi=.999)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:28
float Err2QMomentum() const
static T Sqrt(const T &x)
Definition: PndCAMath.h:45
friend std::istream & operator>>(std::istream &, PndFTSCATrackParam &)
friend std::ostream & operator<<(std::ostream &, const PndFTSCATrackParam &)
PndFTSCATrackParam(const TrackParamVector &v, int i)
__m128 v
Definition: P4_F32vec4.h:3
unsigned int i
Definition: P4_F32vec4.h:21
void GetDCAPoint(float x, float y, float z, float &px, float &py, float &pz, float Bz) const
static T Abs(const T &x)
Definition: PndCAMath.h:56
float_m Transport(const int_v &ista, const PndFTSCAParam &param, const float_m &mask=float_m(true))
float Err2SinPhi() const
const float * Par() const
const float * Cov() const
PndFTSCATrackParam TrackParam
bool TransportToX0(float x, float Bz, float maxSinPhi=.999)
float f
Definition: P4_F32vec4.h:20
basic_ostream< char, char_traits< char > > ostream
double alpha
Definition: f_Init.h:7
const float_v & Cov(int i) const
void ConvertTrackParamToVector(PndFTSCATrackParam t0[float_v::Size], int nTracksV)
double pz[39]
Definition: pipisigmas.h:13
float SignCosPhi() const
const float_v & Par(int i) const
float_m Filter(const FTSCAHitV &hit, const PndFTSCAParam &param, const float_m &mask=float_m(true), const float_v &chi2Cut=10e10f)