CMS 3D CMS Logo

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