1 #ifndef RecoTracker_PixelTrackFitting_interface_alpaka_BrokenLine_h 2 #define RecoTracker_PixelTrackFitting_interface_alpaka_BrokenLine_h 4 #include <alpaka/alpaka.hpp> 59 template <
typename TAcc>
61 const TAcc& acc,
const double& length,
const double bField,
const double radius,
int layer,
double slope) {
84 template <
typename TAcc>
105 template <
typename TAcc>
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);
121 scalar tempSmallU = 1 + rho * dee;
122 scalar tempC = -rho * y0 + tempSmallU *
cosPhi;
123 scalar tempB = rho * x0 + tempSmallU *
sinPhi;
129 scalar tempV = 1. + rho * deltaOrth;
131 scalar
mu = 1. / (tempU * (1. + tempU)) + rho * lambda;
134 2. *
mu * tempSmallU * deltaPara, 2. *
mu * tempV,
mu * zeta - lambda * tempA, 0, 0, 1.;
138 circle.
par(0) = alpaka::math::atan2(acc, tempB, tempC);
140 circle.
par(1) = tempA / (1 + tempU);
145 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
156 template <
typename TAcc,
typename M3xN,
typename V4,
int n>
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;
182 for (u_int
i = 0;
i <
n;
i++) {
192 for (u_int
i = 0;
i <
n;
i++) {
202 for (u_int
i = 1;
i <
n - 1;
i++) {
221 template <
typename TAcc,
int n>
227 for (u_int
i = 0;
i <
n;
i++) {
231 if (
i > 0 &&
i <
n - 1)
238 if (
i > 0 &&
i <
n - 1)
252 return c_uMat + c_uMat.transpose();
265 template <
typename TAcc,
typename M3xN,
typename V4>
267 constexpr uint32_t
n = M3xN::ColsAtCompileTime;
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;
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;
322 template <
typename TAcc,
typename M3xN,
typename M6xN,
typename V4,
int n>
323 ALPAKA_FN_ACC ALPAKA_FN_INLINE
void circleFit(
const TAcc& acc,
332 const auto& sTransverse =
data.sTransverse;
339 for (u_int
i = 0;
i <
n;
i++) {
346 for (u_int
i = 0;
i <
n;
i++) {
347 vMat(0, 0) = hits_ge.col(
i)[0];
348 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
349 vMat(1, 1) = hits_ge.col(
i)[2];
357 for (u_int
i = 0;
i <
n;
i++) {
365 for (u_int
i = 0;
i <
n;
i++) {
367 if (
i > 0 &&
i <
n - 1) {
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)));
374 (sTransverse(
i) - sTransverse(
i - 2)) / (2. *
varBeta(
i - 1) * (sTransverse(
i) - sTransverse(
i - 1)));
378 (sTransverse(
i + 2) - sTransverse(
i)) / (2. *
varBeta(
i + 1) * (sTransverse(
i + 1) - sTransverse(
i)));
380 c_uMat(
n,
i) = c_uMat(
i,
n);
381 if (
i > 0 &&
i <
n - 1)
386 std::cout <<
"CU5\n" << c_uMat << std::endl;
391 std::cout <<
"I5\n" << iMat << std::endl;
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();
403 auto eMinusd2 = eMinusd.squaredNorm();
404 auto tmp1 = 1. / eMinusd2;
407 circle_results.
par << atan2(eMinusd(1), eMinusd(0)), circle_results.
qCharge * (tmp2 -
fast_fit(2)),
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,
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);
422 circle_results.
cov = jacobian * circle_results.
cov * jacobian.transpose();
426 translateKarimaki(acc, circle_results, 0.5 * eMinusd(0), 0.5 * eMinusd(1), jacobian);
427 circle_results.
cov(0, 0) +=
435 circle_results.
chi2 = 0;
436 for (u_int
i = 0;
i <
n;
i++) {
438 if (
i > 0 &&
i <
n - 1)
439 circle_results.
chi2 +=
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) /
471 template <
typename TAcc,
typename V4,
typename M6xN,
int n>
472 ALPAKA_FN_ACC ALPAKA_FN_INLINE
void lineFit(
const TAcc& acc,
488 riemannFit::Matrix2x3d::Zero();
490 for (u_int
i = 0;
i <
n;
i++) {
491 vMat(0, 0) = hits_ge.col(
i)[0];
492 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
493 vMat(0, 2) = vMat(2, 0) = hits_ge.col(
i)[3];
494 vMat(1, 1) = hits_ge.col(
i)[2];
495 vMat(2, 1) = vMat(1, 2) = hits_ge.col(
i)[4];
496 vMat(2, 2) = hits_ge.col(
i)[5];
497 auto tmp = 1. /
radii.block(0,
i, 2, 1).norm();
500 jacobXYZtosZ(1, 2) = 1.;
501 weights(
i) = 1. / ((
rotMat * jacobXYZtosZ * vMat * jacobXYZtosZ.transpose() *
rotMat.transpose())(
506 for (u_int
i = 0;
i <
n;
i++) {
515 std::cout <<
"I4\n" << iMat << std::endl;
521 line_results.
par << (uVec(1) - uVec(0)) / (
sTotal(1) -
sTotal(0)), uVec(0);
523 line_results.
cov << (iMat(0, 0) - 2 * iMat(0, 1) + iMat(1, 1)) *
riemannFit::sqr(idiff) +
525 (iMat(0, 1) - iMat(0, 0)) * idiff, (iMat(0, 1) - iMat(0, 0)) * idiff, iMat(0, 0);
531 jacobian(1, 0) = -
sTotal(0);
533 line_results.
par(1) += -line_results.
par(0) *
sTotal(0);
534 line_results.
cov = jacobian * line_results.
cov * jacobian.transpose();
538 jacobian(1, 1) = 1. /
tmp;
539 jacobian(0, 0) = jacobian(1, 1) * jacobian(1, 1);
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();
547 line_results.
chi2 = 0;
548 for (u_int
i = 0;
i <
n;
i++) {
550 if (
i > 0 &&
i <
n - 1)
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,
616 jacobian << 1., 0, 0, 0, 1., 0, 0, 0,
619 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
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;
633 #endif // RecoTracker_PixelTrackFitting_interface_alpaka_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