CMS 3D CMS Logo

BrokenLine.h
Go to the documentation of this file.
1 #ifndef RecoTracker_PixelTrackFitting_interface_alpaka_BrokenLine_h
2 #define RecoTracker_PixelTrackFitting_interface_alpaka_BrokenLine_h
3 
4 #include <alpaka/alpaka.hpp>
5 
6 #include <Eigen/Core>
7 
10 
12 
13  using namespace cms::alpakatools;
14  using namespace ::riemannFit;
15 
17 
25 
29  template <int n>
31  int qCharge;
34  // starting from the pre-fitted closest approach
38  };
39 
59  template <typename TAcc>
60  ALPAKA_FN_ACC ALPAKA_FN_INLINE double multScatt(
61  const TAcc& acc, const double& length, const double bField, const double radius, int layer, double slope) {
62  // limit R to 20GeV...
63  auto pt2 = alpaka::math::min(acc, 20., bField * radius);
64  pt2 *= pt2;
65  constexpr double inv_X0 = 0.06 / 16.;
66  //if(Layer==1) XXI_0=0.06/16.;
67  // else XXI_0=0.06/16.;
68  //XX_0*=1;
69 
71  constexpr double geometry_factor = 0.7;
72  constexpr double fact = geometry_factor * riemannFit::sqr(13.6 / 1000.);
73  return fact / (pt2 * (1. + riemannFit::sqr(slope))) * (alpaka::math::abs(acc, length) * inv_X0) *
74  riemannFit::sqr(1. + 0.038 * log(alpaka::math::abs(acc, length) * inv_X0));
75  }
76 
84  template <typename TAcc>
85  ALPAKA_FN_ACC ALPAKA_FN_INLINE riemannFit::Matrix2d rotationMatrix(const TAcc& acc, double slope) {
87  rot(0, 0) = 1. / alpaka::math::sqrt(acc, 1. + riemannFit::sqr(slope));
88  rot(0, 1) = slope * rot(0, 0);
89  rot(1, 0) = -rot(0, 1);
90  rot(1, 1) = rot(0, 0);
91  return rot;
92  }
93 
105  template <typename TAcc>
106  ALPAKA_FN_ACC ALPAKA_FN_INLINE void translateKarimaki(
107  const TAcc& acc, karimaki_circle_fit& circle, double x0, double y0, riemannFit::Matrix3d& jacobian) {
108  // Avoid multiple access to the circle.par vector.
109  using scalar = typename std::remove_reference<decltype(circle.par(0))>::type;
110  scalar phi = circle.par(0);
111  scalar dee = circle.par(1);
112  scalar rho = circle.par(2);
113 
114  // Avoid repeated trig. computations
115  scalar sinPhi = alpaka::math::sin(acc, phi);
116  scalar cosPhi = alpaka::math::cos(acc, phi);
117 
118  // Intermediate computations for the circle parameters
119  scalar deltaPara = x0 * cosPhi + y0 * sinPhi;
120  scalar deltaOrth = x0 * sinPhi - y0 * cosPhi + dee;
121  scalar tempSmallU = 1 + rho * dee;
122  scalar tempC = -rho * y0 + tempSmallU * cosPhi;
123  scalar tempB = rho * x0 + tempSmallU * sinPhi;
124  scalar tempA = 2. * deltaOrth + rho * (riemannFit::sqr(deltaOrth) + riemannFit::sqr(deltaPara));
125  scalar tempU = alpaka::math::sqrt(acc, 1. + rho * tempA);
126 
127  // Intermediate computations for the error matrix transform
128  scalar xi = 1. / (riemannFit::sqr(tempB) + riemannFit::sqr(tempC));
129  scalar tempV = 1. + rho * deltaOrth;
130  scalar lambda = (0.5 * tempA) / (riemannFit::sqr(1. + tempU) * tempU);
131  scalar mu = 1. / (tempU * (1. + tempU)) + rho * lambda;
132  scalar zeta = riemannFit::sqr(deltaOrth) + riemannFit::sqr(deltaPara);
133  jacobian << xi * tempSmallU * tempV, -xi * riemannFit::sqr(rho) * deltaOrth, xi * deltaPara,
134  2. * mu * tempSmallU * deltaPara, 2. * mu * tempV, mu * zeta - lambda * tempA, 0, 0, 1.;
135 
136  // translated circle parameters
137  // phi
138  circle.par(0) = alpaka::math::atan2(acc, tempB, tempC);
139  // d
140  circle.par(1) = tempA / (1 + tempU);
141  // rho after translation. It is invariant, so noop
142  // circle.par(2)= rho;
143 
144  // translated error matrix
145  circle.cov = jacobian * circle.cov * jacobian.transpose();
146  }
147 
156  template <typename TAcc, typename M3xN, typename V4, int n>
157  ALPAKA_FN_ACC ALPAKA_FN_INLINE void __attribute__((always_inline)) prepareBrokenLineData(
158  const TAcc& acc, const M3xN& hits, const V4& fast_fit, const double bField, PreparedBrokenLineData<n>& results) {
161 
162  int mId = 1;
163 
164  if constexpr (n > 3) {
165  riemannFit::Vector2d middle = 0.5 * (hits.block(0, n - 1, 2, 1) + hits.block(0, 0, 2, 1));
166  auto d1 = (hits.block(0, n / 2, 2, 1) - middle).squaredNorm();
167  auto d2 = (hits.block(0, n / 2 - 1, 2, 1) - middle).squaredNorm();
168  mId = d1 < d2 ? n / 2 : n / 2 - 1;
169  }
170 
171  dVec = hits.block(0, mId, 2, 1) - hits.block(0, 0, 2, 1);
172  eVec = hits.block(0, n - 1, 2, 1) - hits.block(0, mId, 2, 1);
173  results.qCharge = riemannFit::cross2D(acc, dVec, eVec) > 0 ? -1 : 1;
174 
175  const double slope = -results.qCharge / fast_fit(3);
176 
178 
179  // calculate radii and s
180  results.radii = hits.block(0, 0, 2, n) - fast_fit.head(2) * riemannFit::MatrixXd::Constant(1, n, 1);
181  eVec = -fast_fit(2) * fast_fit.head(2) / fast_fit.head(2).norm();
182  for (u_int i = 0; i < n; i++) {
183  dVec = results.radii.block(0, i, 2, 1);
184  results.sTransverse(i) =
185  results.qCharge * fast_fit(2) *
186  alpaka::math::atan2(acc, riemannFit::cross2D(acc, dVec, eVec), dVec.dot(eVec)); // calculates the arc length
187  }
188  riemannFit::VectorNd<n> zVec = hits.block(2, 0, 1, n).transpose();
189 
190  //calculate sTotal and zVec
192  for (u_int i = 0; i < n; i++) {
193  pointsSZ(0, i) = results.sTransverse(i);
194  pointsSZ(1, i) = zVec(i);
195  pointsSZ.block(0, i, 2, 1) = rotMat * pointsSZ.block(0, i, 2, 1);
196  }
197  results.sTotal = pointsSZ.block(0, 0, 1, n).transpose();
198  results.zInSZplane = pointsSZ.block(1, 0, 1, n).transpose();
199 
200  //calculate varBeta
201  results.varBeta(0) = results.varBeta(n - 1) = 0;
202  for (u_int i = 1; i < n - 1; i++) {
203  results.varBeta(i) =
204  multScatt(acc, results.sTotal(i + 1) - results.sTotal(i), bField, fast_fit(2), i + 2, slope) +
205  multScatt(acc, results.sTotal(i) - results.sTotal(i - 1), bField, fast_fit(2), i + 1, slope);
206  }
207  }
208 
221  template <typename TAcc, int n>
222  ALPAKA_FN_ACC ALPAKA_FN_INLINE riemannFit::MatrixNd<n> matrixC_u(const TAcc& acc,
227  for (u_int i = 0; i < n; i++) {
228  c_uMat(i, i) = weights(i);
229  if (i > 1)
230  c_uMat(i, i) += 1. / (varBeta(i - 1) * riemannFit::sqr(sTotal(i) - sTotal(i - 1)));
231  if (i > 0 && i < n - 1)
232  c_uMat(i, i) +=
233  (1. / varBeta(i)) * riemannFit::sqr((sTotal(i + 1) - sTotal(i - 1)) /
234  ((sTotal(i + 1) - sTotal(i)) * (sTotal(i) - sTotal(i - 1))));
235  if (i < n - 2)
236  c_uMat(i, i) += 1. / (varBeta(i + 1) * riemannFit::sqr(sTotal(i + 1) - sTotal(i)));
237 
238  if (i > 0 && i < n - 1)
239  c_uMat(i, i + 1) =
240  1. / (varBeta(i) * (sTotal(i + 1) - sTotal(i))) *
241  (-(sTotal(i + 1) - sTotal(i - 1)) / ((sTotal(i + 1) - sTotal(i)) * (sTotal(i) - sTotal(i - 1))));
242  if (i < n - 2)
243  c_uMat(i, i + 1) +=
244  1. / (varBeta(i + 1) * (sTotal(i + 1) - sTotal(i))) *
245  (-(sTotal(i + 2) - sTotal(i)) / ((sTotal(i + 2) - sTotal(i + 1)) * (sTotal(i + 1) - sTotal(i))));
246 
247  if (i < n - 2)
248  c_uMat(i, i + 2) = 1. / (varBeta(i + 1) * (sTotal(i + 2) - sTotal(i + 1)) * (sTotal(i + 1) - sTotal(i)));
249 
250  c_uMat(i, i) *= 0.5;
251  }
252  return c_uMat + c_uMat.transpose();
253  }
254 
265  template <typename TAcc, typename M3xN, typename V4>
266  ALPAKA_FN_ACC ALPAKA_FN_INLINE void fastFit(const TAcc& acc, const M3xN& hits, V4& result) {
267  constexpr uint32_t n = M3xN::ColsAtCompileTime;
268 
269  int mId = 1;
270 
271  if constexpr (n > 3) {
272  riemannFit::Vector2d middle = 0.5 * (hits.block(0, n - 1, 2, 1) + hits.block(0, 0, 2, 1));
273  auto d1 = (hits.block(0, n / 2, 2, 1) - middle).squaredNorm();
274  auto d2 = (hits.block(0, n / 2 - 1, 2, 1) - middle).squaredNorm();
275  mId = d1 < d2 ? n / 2 : n / 2 - 1;
276  }
277 
278  const riemannFit::Vector2d a = hits.block(0, mId, 2, 1) - hits.block(0, 0, 2, 1);
279  const riemannFit::Vector2d b = hits.block(0, n - 1, 2, 1) - hits.block(0, mId, 2, 1);
280  const riemannFit::Vector2d c = hits.block(0, 0, 2, 1) - hits.block(0, n - 1, 2, 1);
281 
282  auto tmp = 0.5 / riemannFit::cross2D(acc, c, a);
283  result(0) = hits(0, 0) - (a(1) * c.squaredNorm() + c(1) * a.squaredNorm()) * tmp;
284  result(1) = hits(1, 0) + (a(0) * c.squaredNorm() + c(0) * a.squaredNorm()) * tmp;
285  // check Wikipedia for these formulas
286 
287  result(2) = alpaka::math::sqrt(acc, a.squaredNorm() * b.squaredNorm() * c.squaredNorm()) /
288  (2. * alpaka::math::abs(acc, riemannFit::cross2D(acc, b, a)));
289  // Using Math Olympiad's formula R=abc/(4A)
290 
291  const riemannFit::Vector2d d = hits.block(0, 0, 2, 1) - result.head(2);
292  const riemannFit::Vector2d e = hits.block(0, n - 1, 2, 1) - result.head(2);
293 
294  result(3) = result(2) * atan2(riemannFit::cross2D(acc, d, e), d.dot(e)) / (hits(2, n - 1) - hits(2, 0));
295  // ds/dz slope between last and first point
296  }
297 
322  template <typename TAcc, typename M3xN, typename M6xN, typename V4, int n>
323  ALPAKA_FN_ACC ALPAKA_FN_INLINE void circleFit(const TAcc& acc,
324  const M3xN& hits,
325  const M6xN& hits_ge,
326  const V4& fast_fit,
327  const double bField,
329  karimaki_circle_fit& circle_results) {
330  circle_results.qCharge = data.qCharge;
331  auto& radii = data.radii;
332  const auto& sTransverse = data.sTransverse;
333  const auto& sTotal = data.sTotal;
334  auto& zInSZplane = data.zInSZplane;
335  auto& varBeta = data.varBeta;
336  const double slope = -circle_results.qCharge / fast_fit(3);
337  varBeta *= 1. + riemannFit::sqr(slope); // the kink angles are projected!
338 
339  for (u_int i = 0; i < n; i++) {
340  zInSZplane(i) = radii.block(0, i, 2, 1).norm() - fast_fit(2);
341  }
342 
343  riemannFit::Matrix2d vMat; // covariance matrix
344  riemannFit::VectorNd<n> weightsVec; // weights
345  riemannFit::Matrix2d rotMat; // rotation matrix point by point
346  for (u_int i = 0; i < n; i++) {
347  vMat(0, 0) = hits_ge.col(i)[0]; // x errors
348  vMat(0, 1) = vMat(1, 0) = hits_ge.col(i)[1]; // cov_xy
349  vMat(1, 1) = hits_ge.col(i)[2]; // y errors
350  rotMat = rotationMatrix(acc, -radii(0, i) / radii(1, i));
351  weightsVec(i) =
352  1. / ((rotMat * vMat * rotMat.transpose())(1, 1)); // compute the orthogonal weight point by point
353  }
354 
356  r_uVec(n) = 0;
357  for (u_int i = 0; i < n; i++) {
358  r_uVec(i) = weightsVec(i) * zInSZplane(i);
359  }
360 
362  c_uMat.block(0, 0, n, n) = matrixC_u(acc, weightsVec, sTransverse, varBeta);
363  c_uMat(n, n) = 0;
364  //add the border to the c_uMat matrix
365  for (u_int i = 0; i < n; i++) {
366  c_uMat(i, n) = 0;
367  if (i > 0 && i < n - 1) {
368  c_uMat(i, n) +=
369  -(sTransverse(i + 1) - sTransverse(i - 1)) * (sTransverse(i + 1) - sTransverse(i - 1)) /
370  (2. * varBeta(i) * (sTransverse(i + 1) - sTransverse(i)) * (sTransverse(i) - sTransverse(i - 1)));
371  }
372  if (i > 1) {
373  c_uMat(i, n) +=
374  (sTransverse(i) - sTransverse(i - 2)) / (2. * varBeta(i - 1) * (sTransverse(i) - sTransverse(i - 1)));
375  }
376  if (i < n - 2) {
377  c_uMat(i, n) +=
378  (sTransverse(i + 2) - sTransverse(i)) / (2. * varBeta(i + 1) * (sTransverse(i + 1) - sTransverse(i)));
379  }
380  c_uMat(n, i) = c_uMat(i, n);
381  if (i > 0 && i < n - 1)
382  c_uMat(n, n) += riemannFit::sqr(sTransverse(i + 1) - sTransverse(i - 1)) / (4. * varBeta(i));
383  }
384 
385 #ifdef CPP_DUMP
386  std::cout << "CU5\n" << c_uMat << std::endl;
387 #endif
389  math::cholesky::invert(c_uMat, iMat);
390 #ifdef CPP_DUMP
391  std::cout << "I5\n" << iMat << std::endl;
392 #endif
393  riemannFit::VectorNplusONEd<n> uVec = iMat * r_uVec; // obtain the fitted parameters by solving the linear system
394 
395  // compute (phi, d_ca, k) in the system in which the midpoint of the first two corrected hits is the origin...
396 
397  radii.block(0, 0, 2, 1) /= radii.block(0, 0, 2, 1).norm();
398  radii.block(0, 1, 2, 1) /= radii.block(0, 1, 2, 1).norm();
399 
400  riemannFit::Vector2d dVec = hits.block(0, 0, 2, 1) + (-zInSZplane(0) + uVec(0)) * radii.block(0, 0, 2, 1);
401  riemannFit::Vector2d eVec = hits.block(0, 1, 2, 1) + (-zInSZplane(1) + uVec(1)) * radii.block(0, 1, 2, 1);
402  auto eMinusd = eVec - dVec;
403  auto eMinusd2 = eMinusd.squaredNorm();
404  auto tmp1 = 1. / eMinusd2;
405  auto tmp2 = alpaka::math::sqrt(acc, riemannFit::sqr(fast_fit(2)) - 0.25 * eMinusd2);
406 
407  circle_results.par << atan2(eMinusd(1), eMinusd(0)), circle_results.qCharge * (tmp2 - fast_fit(2)),
408  circle_results.qCharge * (1. / fast_fit(2) + uVec(n));
409 
410  tmp2 = 1. / tmp2;
411 
412  riemannFit::Matrix3d jacobian;
413  jacobian << (radii(1, 0) * eMinusd(0) - eMinusd(1) * radii(0, 0)) * tmp1,
414  (radii(1, 1) * eMinusd(0) - eMinusd(1) * radii(0, 1)) * tmp1, 0,
415  circle_results.qCharge * (eMinusd(0) * radii(0, 0) + eMinusd(1) * radii(1, 0)) * tmp2,
416  circle_results.qCharge * (eMinusd(0) * radii(0, 1) + eMinusd(1) * radii(1, 1)) * tmp2, 0, 0, 0,
417  circle_results.qCharge;
418 
419  circle_results.cov << iMat(0, 0), iMat(0, 1), iMat(0, n), iMat(1, 0), iMat(1, 1), iMat(1, n), iMat(n, 0),
420  iMat(n, 1), iMat(n, n);
421 
422  circle_results.cov = jacobian * circle_results.cov * jacobian.transpose();
423 
424  //...Translate in the system in which the first corrected hit is the origin, adding the m.s. correction...
425 
426  translateKarimaki(acc, circle_results, 0.5 * eMinusd(0), 0.5 * eMinusd(1), jacobian);
427  circle_results.cov(0, 0) +=
428  (1 + riemannFit::sqr(slope)) * multScatt(acc, sTotal(1) - sTotal(0), bField, fast_fit(2), 2, slope);
429 
430  //...And translate back to the original system
431 
432  translateKarimaki(acc, circle_results, dVec(0), dVec(1), jacobian);
433 
434  // compute chi2
435  circle_results.chi2 = 0;
436  for (u_int i = 0; i < n; i++) {
437  circle_results.chi2 += weightsVec(i) * riemannFit::sqr(zInSZplane(i) - uVec(i));
438  if (i > 0 && i < n - 1)
439  circle_results.chi2 +=
440  riemannFit::sqr(uVec(i - 1) / (sTransverse(i) - sTransverse(i - 1)) -
441  uVec(i) * (sTransverse(i + 1) - sTransverse(i - 1)) /
442  ((sTransverse(i + 1) - sTransverse(i)) * (sTransverse(i) - sTransverse(i - 1))) +
443  uVec(i + 1) / (sTransverse(i + 1) - sTransverse(i)) +
444  (sTransverse(i + 1) - sTransverse(i - 1)) * uVec(n) / 2) /
445  varBeta(i);
446  }
447  }
448 
471  template <typename TAcc, typename V4, typename M6xN, int n>
472  ALPAKA_FN_ACC ALPAKA_FN_INLINE void lineFit(const TAcc& acc,
473  const M6xN& hits_ge,
474  const V4& fast_fit,
475  const double bField,
477  riemannFit::LineFit& line_results) {
478  const auto& radii = data.radii;
479  const auto& sTotal = data.sTotal;
480  const auto& zInSZplane = data.zInSZplane;
481  const auto& varBeta = data.varBeta;
482 
483  const double slope = -data.qCharge / fast_fit(3);
485 
486  riemannFit::Matrix3d vMat = riemannFit::Matrix3d::Zero(); // covariance matrix XYZ
487  riemannFit::Matrix2x3d jacobXYZtosZ =
488  riemannFit::Matrix2x3d::Zero(); // jacobian for computation of the error on s (xyz -> sz)
490  for (u_int i = 0; i < n; i++) {
491  vMat(0, 0) = hits_ge.col(i)[0]; // x errors
492  vMat(0, 1) = vMat(1, 0) = hits_ge.col(i)[1]; // cov_xy
493  vMat(0, 2) = vMat(2, 0) = hits_ge.col(i)[3]; // cov_xz
494  vMat(1, 1) = hits_ge.col(i)[2]; // y errors
495  vMat(2, 1) = vMat(1, 2) = hits_ge.col(i)[4]; // cov_yz
496  vMat(2, 2) = hits_ge.col(i)[5]; // z errors
497  auto tmp = 1. / radii.block(0, i, 2, 1).norm();
498  jacobXYZtosZ(0, 0) = radii(1, i) * tmp;
499  jacobXYZtosZ(0, 1) = -radii(0, i) * tmp;
500  jacobXYZtosZ(1, 2) = 1.;
501  weights(i) = 1. / ((rotMat * jacobXYZtosZ * vMat * jacobXYZtosZ.transpose() * rotMat.transpose())(
502  1, 1)); // compute the orthogonal weight point by point
503  }
504 
506  for (u_int i = 0; i < n; i++) {
507  r_u(i) = weights(i) * zInSZplane(i);
508  }
509 #ifdef CPP_DUMP
510  std::cout << "CU4\n" << matrixC_u(w, sTotal, varBeta) << std::endl;
511 #endif
514 #ifdef CPP_DUMP
515  std::cout << "I4\n" << iMat << std::endl;
516 #endif
517 
518  riemannFit::VectorNd<n> uVec = iMat * r_u; // obtain the fitted parameters by solving the linear system
519 
520  // line parameters in the system in which the first hit is the origin and with axis along SZ
521  line_results.par << (uVec(1) - uVec(0)) / (sTotal(1) - sTotal(0)), uVec(0);
522  auto idiff = 1. / (sTotal(1) - sTotal(0));
523  line_results.cov << (iMat(0, 0) - 2 * iMat(0, 1) + iMat(1, 1)) * riemannFit::sqr(idiff) +
524  multScatt(acc, sTotal(1) - sTotal(0), bField, fast_fit(2), 2, slope),
525  (iMat(0, 1) - iMat(0, 0)) * idiff, (iMat(0, 1) - iMat(0, 0)) * idiff, iMat(0, 0);
526 
527  // translate to the original SZ system
528  riemannFit::Matrix2d jacobian;
529  jacobian(0, 0) = 1.;
530  jacobian(0, 1) = 0;
531  jacobian(1, 0) = -sTotal(0);
532  jacobian(1, 1) = 1.;
533  line_results.par(1) += -line_results.par(0) * sTotal(0);
534  line_results.cov = jacobian * line_results.cov * jacobian.transpose();
535 
536  // rotate to the original sz system
537  auto tmp = rotMat(0, 0) - line_results.par(0) * rotMat(0, 1);
538  jacobian(1, 1) = 1. / tmp;
539  jacobian(0, 0) = jacobian(1, 1) * jacobian(1, 1);
540  jacobian(0, 1) = 0;
541  jacobian(1, 0) = line_results.par(1) * rotMat(0, 1) * jacobian(0, 0);
542  line_results.par(1) = line_results.par(1) * jacobian(1, 1);
543  line_results.par(0) = (rotMat(0, 1) + line_results.par(0) * rotMat(0, 0)) * jacobian(1, 1);
544  line_results.cov = jacobian * line_results.cov * jacobian.transpose();
545 
546  // compute chi2
547  line_results.chi2 = 0;
548  for (u_int i = 0; i < n; i++) {
549  line_results.chi2 += weights(i) * riemannFit::sqr(zInSZplane(i) - uVec(i));
550  if (i > 0 && i < n - 1)
551  line_results.chi2 += riemannFit::sqr(uVec(i - 1) / (sTotal(i) - sTotal(i - 1)) -
552  uVec(i) * (sTotal(i + 1) - sTotal(i - 1)) /
553  ((sTotal(i + 1) - sTotal(i)) * (sTotal(i) - sTotal(i - 1))) +
554  uVec(i + 1) / (sTotal(i + 1) - sTotal(i))) /
555  varBeta(i);
556  }
557  }
558 
594  template <int n>
595  class helixFit {
596  public:
597  template <typename TAcc>
598  ALPAKA_FN_ACC ALPAKA_FN_INLINE void operator()(const TAcc& acc,
600  const Eigen::Matrix<float, 6, 4>* hits_ge,
601  const double bField,
602  riemannFit::HelixFit* helix) const {
604  fastFit(acc, *hits, fast_fit);
605 
607  karimaki_circle_fit circle;
609  riemannFit::Matrix3d jacobian;
610 
612  lineFit(acc, *hits_ge, fast_fit, bField, data, line);
613  circleFit(acc, *hits, *hits_ge, fast_fit, bField, data, circle);
614 
615  // the circle fit gives k, but here we want p_t, so let's change the parameter and the covariance matrix
616  jacobian << 1., 0, 0, 0, 1., 0, 0, 0,
617  -alpaka::math::abs(acc, circle.par(2)) * bField / (riemannFit::sqr(circle.par(2)) * circle.par(2));
618  circle.par(2) = bField / alpaka::math::abs(acc, circle.par(2));
619  circle.cov = jacobian * circle.cov * jacobian.transpose();
620 
621  helix->par << circle.par, line.par;
622  helix->cov = riemannFit::MatrixXd::Zero(5, 5);
623  helix->cov.block(0, 0, 3, 3) = circle.cov;
624  helix->cov.block(3, 3, 2, 2) = line.cov;
625  helix->qCharge = circle.qCharge;
626  helix->chi2_circle = circle.chi2;
627  helix->chi2_line = line.chi2;
628  }
629  };
630 
631 } // namespace ALPAKA_ACCELERATOR_NAMESPACE::brokenline
632 
633 #endif // RecoTracker_PixelTrackFitting_interface_alpaka_BrokenLine_h
riemannFit::VectorNd< n > zVec
Definition: BrokenLine.h:188
Eigen::Vector4d Vector4d
Definition: FitResult.h:12
Eigen::Matrix< double, 2, N > Matrix2xNd
Definition: FitUtils.h:29
ALPAKA_FN_ACC ALPAKA_FN_INLINE void fastFit(const TAcc &acc, const M3xN &hits, V4 &result)
A very fast helix fit.
Definition: BrokenLine.h:266
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN & hits
Definition: BrokenLine.h:158
Eigen::Matrix3d Matrix3d
Definition: FitResult.h:15
riemannFit::VectorNd< n > sTotal
total distance traveled (three-dimensional)
Definition: BrokenLine.h:35
ALPAKA_FN_ACC ALPAKA_FN_INLINE riemannFit::MatrixNd< n > matrixC_u(const TAcc &acc, const riemannFit::VectorNd< n > &weights, const riemannFit::VectorNd< n > &sTotal, const riemannFit::VectorNd< n > &varBeta)
Computes the n-by-n band matrix obtained minimizing the Broken Line&#39;s cost function w...
Definition: BrokenLine.h:222
int32_t qCharge
particle charge
Definition: FitResult.h:31
ALPAKA_FN_ACC ALPAKA_FN_INLINE void translateKarimaki(const TAcc &acc, karimaki_circle_fit &circle, double x0, double y0, riemannFit::Matrix3d &jacobian)
Changes the Karimäki parameters (and consequently their covariance matrix) under a translation of the...
Definition: BrokenLine.h:106
T w() const
Eigen::Matrix< double, 2, 3 > Matrix2x3d
Definition: FitUtils.h:49
Vector5d par
(phi,Tip,pt,cotan(theta)),Zip)
Definition: FitResult.h:46
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ALPAKA_FN_ACC ALPAKA_FN_INLINE double cross2D(const TAcc &acc, const Vector2d &a, const Vector2d &b)
Compute cross product of two 2D vector (assuming z component 0), returning z component of the result...
Definition: FitUtils.h:117
Eigen::Matrix< double, N+1, 1 > VectorNplusONEd
Definition: FitUtils.h:39
Vector3d par
parameter: (X0,Y0,R)
Definition: FitResult.h:24
constexpr T sqr(const T a)
raise to square.
Definition: FitUtils.h:104
ALPAKA_FN_ACC ALPAKA_FN_INLINE double multScatt(const TAcc &acc, const double &length, const double bField, const double radius, int layer, double slope)
Computes the Coulomb multiple scattering variance of the planar angle.
Definition: BrokenLine.h:60
riemannFit::Matrix2xNd< n > radii
xy data in the system in which the pre-fitted center is the origin
Definition: BrokenLine.h:32
ALPAKA_FN_ACC ALPAKA_FN_INLINE void __attribute__((always_inline)) prepareBrokenLineData(const TAcc &acc
Computes the data needed for the Broken Line fit procedure that are mainly common for the circle and ...
ALPAKA_FN_ACC ALPAKA_FN_INLINE void lineFit(const TAcc &acc, const M6xN &hits_ge, const V4 &fast_fit, const double bField, const PreparedBrokenLineData< n > &data, riemannFit::LineFit &line_results)
Performs the Broken Line fit in the straight track case (that is, the fit parameters are only the int...
Definition: BrokenLine.h:472
riemannFit::VectorNd< n > varBeta
kink angles in the SZ plane
Definition: BrokenLine.h:37
__host__ __device__ void prepareBrokenLineData(const M3xN &hits, const V4 &fast_fit, const double bField, PreparedBrokenLineData< n > &results)
Computes the data needed for the Broken Line fit procedure that are mainly common for the circle and ...
Definition: BrokenLine.h:151
Eigen::Matrix< double, N, 1 > VectorNd
Definition: FitUtils.h:37
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 const double bField
Definition: BrokenLine.h:158
int32_t qCharge
particle charge
Definition: FitResult.h:58
T sqrt(T t)
Definition: SSEVec.h:23
Eigen::Matrix2d Matrix2d
Definition: FitResult.h:14
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Eigen::Matrix< double, N, N > MatrixNd
Definition: FitUtils.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Eigen::Matrix< double, 3, N > Matrix3xNd
Definition: HelixFit.h:30
ALPAKA_FN_ACC ALPAKA_FN_INLINE riemannFit::Matrix2d rotationMatrix(const TAcc &acc, double slope)
Computes the 2D rotation matrix that transforms the line y=slope*x into the line y=0.
Definition: BrokenLine.h:85
d
Definition: ztail.py:151
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 const double PreparedBrokenLineData< n > & results
Definition: BrokenLine.h:158
Polynomial< 0 > Constant
Definition: Constant.h:6
Helix fit by three step: -fast pre-fit (see Fast_fit() for further info); -circle fit of the hits pr...
Definition: BrokenLine.h:595
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 & fast_fit
Definition: BrokenLine.h:158
const double fact
riemannFit::VectorNd< n > sTransverse
total distance traveled in the transverse plane
Definition: BrokenLine.h:33
riemannFit::Matrix2xNd< n > pointsSZ
Definition: BrokenLine.h:191
Eigen::Vector2d Vector2d
Definition: FitResult.h:10
double b
Definition: hdecay.h:120
Eigen::Matrix< double, N+1, N+1 > MatrixNplusONEd
Definition: FitUtils.h:21
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
data needed for the Broken Line fit procedure.
Definition: BrokenLine.h:30
double a
Definition: hdecay.h:121
Vector2d par
(cotan(theta),Zip)
Definition: FitResult.h:36
static constexpr float d1
tmp
align.sh
Definition: createJobs.py:716
riemannFit::VectorNd< n > zInSZplane
orthogonal coordinate to the pre-fitted line in the sz plane
Definition: BrokenLine.h:36
ALPAKA_FN_ACC ALPAKA_FN_INLINE void circleFit(const TAcc &acc, const M3xN &hits, const M6xN &hits_ge, const V4 &fast_fit, const double bField, PreparedBrokenLineData< n > &data, karimaki_circle_fit &circle_results)
Performs the Broken Line fit in the curved track case (that is, the fit parameters are the intercepti...
Definition: BrokenLine.h:323
ALPAKA_FN_ACC ALPAKA_FN_INLINE void operator()(const TAcc &acc, const riemannFit::Matrix3xNd< n > *hits, const Eigen::Matrix< float, 6, 4 > *hits_ge, const double bField, riemannFit::HelixFit *helix) const
Definition: BrokenLine.h:598