1 #ifndef RecoPixelVertexing_PixelTrackFitting_interface_BrokenLine_h 2 #define RecoPixelVertexing_PixelTrackFitting_interface_BrokenLine_h 3 #include <alpaka/alpaka.hpp> 4 #include <Eigen/Eigenvalues> 56 template <
typename TAcc>
58 const TAcc& acc,
const double& length,
const double bField,
const double radius,
int layer,
double slope) {
81 template <
typename TAcc>
102 template <
typename TAcc>
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);
118 scalar tempSmallU = 1 + rho * dee;
119 scalar tempC = -rho * y0 + tempSmallU *
cosPhi;
120 scalar tempB = rho * x0 + tempSmallU *
sinPhi;
126 scalar tempV = 1. + rho * deltaOrth;
128 scalar
mu = 1. / (tempU * (1. + tempU)) + rho * lambda;
131 2. *
mu * tempSmallU * deltaPara, 2. *
mu * tempV,
mu * zeta - lambda * tempA, 0, 0, 1.;
135 circle.
par(0) = alpaka::math::atan2(acc, tempB, tempC);
137 circle.
par(1) = tempA / (1 + tempU);
142 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
153 template <
typename TAcc,
typename M3xN,
typename V4,
int n>
154 ALPAKA_FN_ACC ALPAKA_FN_INLINE
void __attribute__((always_inline))
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;
183 for (u_int
i = 0;
i <
n;
i++) {
194 for (u_int
i = 0;
i <
n;
i++) {
204 for (u_int
i = 1;
i <
n - 1;
i++) {
223 template <
typename TAcc,
int n>
229 for (u_int
i = 0;
i <
n;
i++) {
233 if (
i > 0 &&
i <
n - 1)
240 if (
i > 0 &&
i <
n - 1)
254 return c_uMat + c_uMat.transpose();
267 template <
typename TAcc,
typename M3xN,
typename V4>
269 constexpr uint32_t
n = M3xN::ColsAtCompileTime;
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;
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;
324 template <
typename TAcc,
typename M3xN,
typename M6xN,
typename V4,
int n>
325 ALPAKA_FN_ACC ALPAKA_FN_INLINE
void circleFit(
const TAcc& acc,
334 const auto& sTransverse =
data.sTransverse;
341 for (u_int
i = 0;
i <
n;
i++) {
348 for (u_int
i = 0;
i <
n;
i++) {
349 vMat(0, 0) = hits_ge.col(
i)[0];
350 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
351 vMat(1, 1) = hits_ge.col(
i)[2];
359 for (u_int
i = 0;
i <
n;
i++) {
367 for (u_int
i = 0;
i <
n;
i++) {
369 if (
i > 0 &&
i <
n - 1) {
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)));
376 (sTransverse(
i) - sTransverse(
i - 2)) / (2. *
varBeta(
i - 1) * (sTransverse(
i) - sTransverse(
i - 1)));
380 (sTransverse(
i + 2) - sTransverse(
i)) / (2. *
varBeta(
i + 1) * (sTransverse(
i + 1) - sTransverse(
i)));
382 c_uMat(
n,
i) = c_uMat(
i,
n);
383 if (
i > 0 &&
i <
n - 1)
388 std::cout <<
"CU5\n" << c_uMat << std::endl;
393 std::cout <<
"I5\n" << iMat << std::endl;
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();
405 auto eMinusd2 = eMinusd.squaredNorm();
406 auto tmp1 = 1. / eMinusd2;
409 circle_results.
par << atan2(eMinusd(1), eMinusd(0)), circle_results.
qCharge * (tmp2 -
fast_fit(2)),
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,
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);
424 circle_results.
cov = jacobian * circle_results.
cov * jacobian.transpose();
428 translateKarimaki(acc, circle_results, 0.5 * eMinusd(0), 0.5 * eMinusd(1), jacobian);
429 circle_results.
cov(0, 0) +=
437 circle_results.
chi2 = 0;
438 for (u_int
i = 0;
i <
n;
i++) {
440 if (
i > 0 &&
i <
n - 1)
441 circle_results.
chi2 +=
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) /
473 template <
typename TAcc,
typename V4,
typename M6xN,
int n>
474 ALPAKA_FN_ACC ALPAKA_FN_INLINE
void lineFit(
const TAcc& acc,
490 riemannFit::Matrix2x3d::Zero();
492 for (u_int
i = 0;
i <
n;
i++) {
493 vMat(0, 0) = hits_ge.col(
i)[0];
494 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
495 vMat(0, 2) = vMat(2, 0) = hits_ge.col(
i)[3];
496 vMat(1, 1) = hits_ge.col(
i)[2];
497 vMat(2, 1) = vMat(1, 2) = hits_ge.col(
i)[4];
498 vMat(2, 2) = hits_ge.col(
i)[5];
499 auto tmp = 1. /
radii.block(0,
i, 2, 1).norm();
502 jacobXYZtosZ(1, 2) = 1.;
503 weights(
i) = 1. / ((
rotMat * jacobXYZtosZ * vMat * jacobXYZtosZ.transpose() *
rotMat.transpose())(
508 for (u_int
i = 0;
i <
n;
i++) {
517 std::cout <<
"I4\n" << iMat << std::endl;
523 line_results.
par << (uVec(1) - uVec(0)) / (
sTotal(1) -
sTotal(0)), uVec(0);
525 line_results.
cov << (iMat(0, 0) - 2 * iMat(0, 1) + iMat(1, 1)) *
riemannFit::sqr(idiff) +
527 (iMat(0, 1) - iMat(0, 0)) * idiff, (iMat(0, 1) - iMat(0, 0)) * idiff, iMat(0, 0);
533 jacobian(1, 0) = -
sTotal(0);
535 line_results.
par(1) += -line_results.
par(0) *
sTotal(0);
536 line_results.
cov = jacobian * line_results.
cov * jacobian.transpose();
540 jacobian(1, 1) = 1. /
tmp;
541 jacobian(0, 0) = jacobian(1, 1) * jacobian(1, 1);
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();
549 line_results.
chi2 = 0;
550 for (u_int
i = 0;
i <
n;
i++) {
552 if (
i > 0 &&
i <
n - 1)
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,
618 jacobian << 1., 0, 0, 0, 1., 0, 0, 0,
621 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
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;
634 #endif // RecoPixelVertexing_PixelTrackFitting_interface_BrokenLine_h
riemannFit::VectorNd< n > zVec
Eigen::Matrix< double, 2, N > Matrix2xNd
ALPAKA_FN_ACC ALPAKA_FN_INLINE void fastFit(const TAcc &acc, const M3xN &hits, V4 &result)
A very fast helix fit.
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN & hits
riemannFit::VectorNd< n > sTotal
total distance traveled (three-dimensional)
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's cost function w...
int32_t qCharge
particle charge
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...
Eigen::Matrix< double, 2, 3 > Matrix2x3d
Vector5d par
(phi,Tip,pt,cotan(theta)),Zip)
Sin< T >::type sin(const T &t)
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...
Eigen::Matrix< double, N+1, 1 > VectorNplusONEd
Vector3d par
parameter: (X0,Y0,R)
constexpr T sqr(const T a)
raise to square.
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.
riemannFit::Matrix2xNd< n > radii
xy data in the system in which the pre-fitted center is the origin
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...
riemannFit::VectorNd< n > varBeta
kink angles in the SZ plane
riemannFit::Matrix2d rotMat
__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 ...
Eigen::Matrix< double, N, 1 > VectorNd
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 const double bField
int32_t qCharge
particle charge
Cos< T >::type cos(const T &t)
Eigen::Matrix< double, N, N > MatrixNd
Abs< T >::type abs(const T &t)
Eigen::Matrix< double, 3, N > Matrix3xNd
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.
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 const double PreparedBrokenLineData< n > & results
Helix fit by three step: -fast pre-fit (see Fast_fit() for further info); -circle fit of the hits pr...
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 & fast_fit
riemannFit::VectorNd< n > sTransverse
total distance traveled in the transverse plane
riemannFit::Matrix2xNd< n > pointsSZ
int qCharge
particle charge
riemannFit::Vector2d eVec
Eigen::Matrix< double, N+1, N+1 > MatrixNplusONEd
char data[epos_bytes_allocation]
data needed for the Broken Line fit procedure.
Vector2d par
(cotan(theta),Zip)
static constexpr float d1
riemannFit::VectorNd< n > zInSZplane
orthogonal coordinate to the pre-fitted line in the sz plane
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...
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