1 #ifndef RecoTracker_PixelTrackFitting_interface_alpaka_FitUtils_h 2 #define RecoTracker_PixelTrackFitting_interface_alpaka_FitUtils_h 4 #include <alpaka/alpaka.hpp> 23 using ArrayNd = Eigen::Array<double, N, N>;
25 using Matrix2Nd = Eigen::Matrix<double, 2 * N, 2 * N>;
27 using Matrix3Nd = Eigen::Matrix<double, 3 * N, 3 * N>;
59 template <
typename VI5,
typename MI5,
typename VO5,
typename MO5>
61 auto sinTheta2 = 1. / (1. + ip(3) * ip(3));
63 auto cosTheta = ip(3) * sinTheta;
65 op(0) = sinTheta * ip(2);
73 jMat(0, 2) = sinTheta;
74 jMat(0, 3) = -sinTheta2 * cosTheta * ip(2);
80 ocov = jMat * icov * jMat.transpose();
89 template <
typename TAcc,
class C>
92 for (
uint r = 0; r <
m->rows(); ++r) {
93 for (
uint c = 0;
c <
m->cols(); ++
c) {
94 printf(
"%s Matrix(%d,%d) = %g\n",
prefix, r,
c, (*
m)(r,
c));
103 template <
typename T>
116 template <
typename TAcc>
118 return a.x() *
b.y() -
a.y() *
b.x();
125 template <
typename TAcc,
typename M6xNf,
typename M2Nd>
139 constexpr uint32_t hits_in_fit = M6xNf::ColsAtCompileTime;
140 for (uint32_t
i = 0;
i < hits_in_fit; ++
i) {
143 hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) = ge.col(
i)[ge_idx];
147 hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) = ge.col(
i)[ge_idx];
151 hits_cov(
i +
l * hits_in_fit,
i +
j * hits_in_fit) = hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) =
157 template <
typename TAcc,
typename M6xNf,
typename M3xNd>
158 ALPAKA_FN_ACC
void loadCovariance(
const TAcc& acc, M6xNf
const& ge, M3xNd& hits_cov) {
171 constexpr uint32_t hits_in_fit = M6xNf::ColsAtCompileTime;
172 for (uint32_t
i = 0;
i < hits_in_fit; ++
i) {
175 hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) = ge.col(
i)[ge_idx];
179 hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) = ge.col(
i)[ge_idx];
183 hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) = ge.col(
i)[ge_idx];
187 hits_cov(
i +
l * hits_in_fit,
i +
j * hits_in_fit) = hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) =
192 hits_cov(
i +
l * hits_in_fit,
i +
j * hits_in_fit) = hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) =
197 hits_cov(
i +
l * hits_in_fit,
i +
j * hits_in_fit) = hits_cov(
i +
j * hits_in_fit,
i +
l * hits_in_fit) =
211 template <
typename TAcc>
217 const double temp0 = circle.par.head(2).squaredNorm();
219 par_pak <<
alpaka::math::atan2(acc, circle.qCharge * circle.par(0), -circle.qCharge * circle.par(1)),
220 circle.qCharge * (temp1 - circle.par(2)), circle.par(2) *
B;
222 const double temp2 =
sqr(circle.par(0)) * 1. / temp0;
223 const double temp3 = 1. / temp1 * circle.qCharge;
225 j4Mat << -circle.par(1) * temp2 * 1. /
sqr(circle.par(0)), temp2 * 1. / circle.par(0), 0.,
226 circle.par(0) * temp3, circle.par(1) * temp3, -circle.qCharge, 0., 0.,
B;
227 circle.cov = j4Mat * circle.cov * j4Mat.transpose();
229 circle.par = par_pak;
238 template <
typename TAcc>
241 const double temp0 = circle.par.head(2).squaredNorm();
243 par_pak <<
alpaka::math::atan2(acc, circle.qCharge * circle.par(0), -circle.qCharge * circle.par(1)),
244 circle.qCharge * (temp1 - circle.par(2)), circle.qCharge / circle.par(2);
246 const double temp2 =
sqr(circle.par(0)) * 1. / temp0;
247 const double temp3 = 1. / temp1 * circle.qCharge;
249 j4Mat << -circle.par(1) * temp2 * 1. /
sqr(circle.par(0)), temp2 * 1. / circle.par(0), 0., circle.par(0) * temp3,
250 circle.par(1) * temp3, -circle.qCharge, 0., 0., -circle.qCharge / (circle.par(2) * circle.par(2));
251 circle.cov = j4Mat * circle.cov * j4Mat.transpose();
253 circle.par = par_pak;
260 #endif // RecoTracker_PixelTrackFitting_interface_alpaka_FitUtils_h Eigen::Matrix< double, 2, N > Matrix2xNd
Eigen::Matrix< double, 6, 1 > Vector6f
Eigen::Matrix< double, 3 *N, 1 > Vector3Nd
Eigen::Matrix< double, 5, 5 > Matrix5d
Eigen::Matrix< double, 1, 2 *N > RowVector2Nd
ALPAKA_FN_ACC void loadCovariance2D(const TAcc &acc, M6xNf const &ge, M2Nd &hits_cov)
Eigen::Matrix< double, 2 *N, 1 > Vector2Nd
Eigen::Matrix< double, 2, 3 > Matrix2x3d
Eigen::Matrix< double, 3 *N, 3 *N > Matrix3Nd
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...
ALPAKA_FN_ACC ALPAKA_FN_INLINE void par_uvrtopak(const TAcc &acc, CircleFit &circle, const double B, const bool error)
Transform circle parameter from (X0,Y0,R) to (phi,Tip,p_t) and consequently covariance matrix...
Eigen::Array< double, N, N > ArrayNd
Eigen::Matrix< double, N+1, 1 > VectorNplusONEd
constexpr T sqr(const T a)
raise to square.
void transformToPerigeePlane(VI5 const &ip, MI5 const &icov, VO5 &op, MO5 &ocov)
Eigen::Matrix< double, N, 1 > VectorNd
Eigen::Matrix< double, N, N > MatrixNd
constexpr double epsilon
used in numerical derivative (J2 in Circle_fit())
ALPAKA_FN_ACC ALPAKA_FN_INLINE void fromCircleToPerigee(const TAcc &acc, CircleFit &circle)
Transform circle parameter from (X0,Y0,R) to (phi,Tip,q/R) and consequently covariance matrix...
Eigen::Matrix< double, N, 5 > MatrixNx5d
Eigen::Matrix< double, 2 *N, 2 *N > Matrix2Nd
ALPAKA_FN_ACC void loadCovariance(const TAcc &acc, M6xNf const &ge, M3xNd &hits_cov)
Eigen::Array< double, 2, N > Array2xNd
ALPAKA_FN_ACC void printIt(const TAcc &acc, C *m, const char *prefix="")
Eigen::Matrix< double, N, 3 > MatrixNx3d
Eigen::Matrix< double, N+1, N+1 > MatrixNplusONEd
Eigen::Matrix< double, 1, 1, N > RowVectorNd
MPlex< T, D1, D2, N > atan2(const MPlex< T, D1, D2, N > &y, const MPlex< T, D1, D2, N > &x)