1 #ifndef RecoTracker_PixelTrackFitting_BrokenLine_h 2 #define RecoTracker_PixelTrackFitting_BrokenLine_h 5 #include <Eigen/Eigenvalues> 55 const double& length,
const double bField,
const double radius,
int layer,
double slope) {
103 using scalar = std::remove_reference<decltype(circle.
par(0))>::
type;
104 scalar phi = circle.
par(0);
105 scalar dee = circle.
par(1);
106 scalar rho = circle.
par(2);
115 scalar tempSmallU = 1 + rho * dee;
116 scalar tempC = -rho * y0 + tempSmallU *
cosPhi;
117 scalar tempB = rho * x0 + tempSmallU *
sinPhi;
119 scalar tempU =
sqrt(1. + rho * tempA);
123 scalar tempV = 1. + rho * deltaOrth;
125 scalar
mu = 1. / (tempU * (1. + tempU)) + rho * lambda;
128 2. *
mu * tempSmallU * deltaPara, 2. *
mu * tempV,
mu * zeta - lambda * tempA, 0, 0, 1.;
132 circle.
par(0) = atan2(tempB, tempC);
134 circle.
par(1) = tempA / (1 + tempU);
139 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
150 template <
typename M3xN,
typename V4,
int n>
162 auto d1 = (
hits.block(0,
n / 2, 2, 1) - middle).squaredNorm();
163 auto d2 = (
hits.block(0,
n / 2 - 1, 2, 1) - middle).squaredNorm();
164 mId =
d1 < d2 ?
n / 2 :
n / 2 - 1;
178 for (u_int
i = 0;
i <
n;
i++) {
187 for (u_int
i = 0;
i <
n;
i++) {
197 for (u_int
i = 1;
i <
n - 1;
i++) {
220 for (u_int
i = 0;
i <
n;
i++) {
224 if (
i > 0 &&
i <
n - 1)
231 if (
i > 0 &&
i <
n - 1)
245 return c_uMat + c_uMat.transpose();
258 template <
typename M3xN,
typename V4>
260 constexpr uint32_t
n = M3xN::ColsAtCompileTime;
266 auto d1 = (
hits.block(0,
n / 2, 2, 1) - middle).squaredNorm();
267 auto d2 = (
hits.block(0,
n / 2 - 1, 2, 1) - middle).squaredNorm();
268 mId =
d1 < d2 ?
n / 2 :
n / 2 - 1;
276 result(0) =
hits(0, 0) - (
a(1) *
c.squaredNorm() +
c(1) *
a.squaredNorm()) *
tmp;
277 result(1) =
hits(1, 0) + (
a(0) *
c.squaredNorm() +
c(0) *
a.squaredNorm()) *
tmp;
314 template <
typename M3xN,
typename M6xN,
typename V4,
int n>
323 const auto& sTransverse =
data.sTransverse;
330 for (u_int
i = 0;
i <
n;
i++) {
337 for (u_int
i = 0;
i <
n;
i++) {
338 vMat(0, 0) = hits_ge.col(
i)[0];
339 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
340 vMat(1, 1) = hits_ge.col(
i)[2];
348 for (u_int
i = 0;
i <
n;
i++) {
356 for (u_int
i = 0;
i <
n;
i++) {
358 if (
i > 0 &&
i <
n - 1) {
360 -(sTransverse(
i + 1) - sTransverse(
i - 1)) * (sTransverse(
i + 1) - sTransverse(
i - 1)) /
361 (2. *
varBeta(
i) * (sTransverse(
i + 1) - sTransverse(
i)) * (sTransverse(
i) - sTransverse(
i - 1)));
365 (sTransverse(
i) - sTransverse(
i - 2)) / (2. *
varBeta(
i - 1) * (sTransverse(
i) - sTransverse(
i - 1)));
369 (sTransverse(
i + 2) - sTransverse(
i)) / (2. *
varBeta(
i + 1) * (sTransverse(
i + 1) - sTransverse(
i)));
371 c_uMat(
n,
i) = c_uMat(
i,
n);
372 if (
i > 0 &&
i <
n - 1)
377 std::cout <<
"CU5\n" << c_uMat << std::endl;
382 std::cout <<
"I5\n" << iMat << std::endl;
389 radii.block(0, 0, 2, 1) /=
radii.block(0, 0, 2, 1).norm();
390 radii.block(0, 1, 2, 1) /=
radii.block(0, 1, 2, 1).norm();
395 auto eMinusd2 = eMinusd.squaredNorm();
396 auto tmp1 = 1. / eMinusd2;
399 circle_results.
par << atan2(eMinusd(1), eMinusd(0)), circle_results.
qCharge * (tmp2 -
fast_fit(2)),
405 jacobian << (
radii(1, 0) * eMinusd(0) - eMinusd(1) *
radii(0, 0)) * tmp1,
406 (
radii(1, 1) * eMinusd(0) - eMinusd(1) *
radii(0, 1)) * tmp1, 0,
407 circle_results.
qCharge * (eMinusd(0) *
radii(0, 0) + eMinusd(1) *
radii(1, 0)) * tmp2,
408 circle_results.
qCharge * (eMinusd(0) *
radii(0, 1) + eMinusd(1) *
radii(1, 1)) * tmp2, 0, 0, 0,
411 circle_results.
cov << iMat(0, 0), iMat(0, 1), iMat(0,
n), iMat(1, 0), iMat(1, 1), iMat(1,
n), iMat(
n, 0),
412 iMat(
n, 1), iMat(
n,
n);
414 circle_results.
cov = jacobian * circle_results.
cov * jacobian.transpose();
419 circle_results.
cov(0, 0) +=
427 circle_results.
chi2 = 0;
428 for (u_int
i = 0;
i <
n;
i++) {
430 if (
i > 0 &&
i <
n - 1)
431 circle_results.
chi2 +=
433 uVec(
i) * (sTransverse(
i + 1) - sTransverse(
i - 1)) /
434 ((sTransverse(
i + 1) - sTransverse(
i)) * (sTransverse(
i) - sTransverse(
i - 1))) +
435 uVec(
i + 1) / (sTransverse(
i + 1) - sTransverse(
i)) +
436 (sTransverse(
i + 1) - sTransverse(
i - 1)) * uVec(
n) / 2) /
463 template <
typename V4,
typename M6xN,
int n>
479 riemannFit::Matrix2x3d::Zero();
481 for (u_int
i = 0;
i <
n;
i++) {
482 vMat(0, 0) = hits_ge.col(
i)[0];
483 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
484 vMat(0, 2) = vMat(2, 0) = hits_ge.col(
i)[3];
485 vMat(1, 1) = hits_ge.col(
i)[2];
486 vMat(2, 1) = vMat(1, 2) = hits_ge.col(
i)[4];
487 vMat(2, 2) = hits_ge.col(
i)[5];
488 auto tmp = 1. /
radii.block(0,
i, 2, 1).norm();
491 jacobXYZtosZ(1, 2) = 1.;
492 weights(
i) = 1. / ((
rotMat * jacobXYZtosZ * vMat * jacobXYZtosZ.transpose() *
rotMat.transpose())(
497 for (u_int
i = 0;
i <
n;
i++) {
506 std::cout <<
"I4\n" << iMat << std::endl;
512 line_results.
par << (uVec(1) - uVec(0)) / (
sTotal(1) -
sTotal(0)), uVec(0);
514 line_results.
cov << (iMat(0, 0) - 2 * iMat(0, 1) + iMat(1, 1)) *
riemannFit::sqr(idiff) +
516 (iMat(0, 1) - iMat(0, 0)) * idiff, (iMat(0, 1) - iMat(0, 0)) * idiff, iMat(0, 0);
522 jacobian(1, 0) = -
sTotal(0);
524 line_results.
par(1) += -line_results.
par(0) *
sTotal(0);
525 line_results.
cov = jacobian * line_results.
cov * jacobian.transpose();
529 jacobian(1, 1) = 1. /
tmp;
530 jacobian(0, 0) = jacobian(1, 1) * jacobian(1, 1);
532 jacobian(1, 0) = line_results.
par(1) *
rotMat(0, 1) * jacobian(0, 0);
533 line_results.
par(1) = line_results.
par(1) * jacobian(1, 1);
534 line_results.
par(0) = (
rotMat(0, 1) + line_results.
par(0) *
rotMat(0, 0)) * jacobian(1, 1);
535 line_results.
cov = jacobian * line_results.
cov * jacobian.transpose();
538 line_results.
chi2 = 0;
539 for (u_int
i = 0;
i <
n;
i++) {
541 if (
i > 0 &&
i <
n - 1)
586 const Eigen::Matrix<float, 6, 4>& hits_ge,
602 jacobian << 1., 0, 0, 0, 1., 0, 0, 0,
605 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
608 helix.
cov = riemannFit::MatrixXd::Zero(5, 5);
609 helix.
cov.block(0, 0, 3, 3) = circle.
cov;
610 helix.
cov.block(3, 3, 2, 2) =
line.cov;
620 #endif // RecoTracker_PixelTrackFitting_BrokenLine_h
riemannFit::VectorNd< n > zVec
__host__ __device__ void lineFit(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...
int qCharge
particle charge
Eigen::Matrix< double, 2, N > Matrix2xNd
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN & hits
int32_t qCharge
particle charge
Eigen::Matrix< double, 2, 3 > Matrix2x3d
static const double slope[3]
Vector5d par
(phi,Tip,pt,cotan(theta)),Zip)
Sin< T >::type sin(const T &t)
Eigen::Matrix< double, N+1, 1 > VectorNplusONEd
Vector3d par
parameter: (X0,Y0,R)
__host__ __device__ double cross2D(const Vector2d &a, const Vector2d &b)
Compute cross product of two 2D vector (assuming z component 0), returning z component of the result...
__host__ __device__ void translateKarimaki(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...
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 ...
__host__ __device__ double multScatt(const double &length, const double bField, const double radius, int layer, double slope)
Computes the Coulomb multiple scattering variance of the planar angle.
Eigen::Matrix< double, N, 1 > VectorNd
riemannFit::VectorNd< n > sTransverse
total distance traveled in the transverse plane
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
constexpr T sqr(const T a)
raise to square.
__host__ __device__ void fastFit(const M3xN &hits, V4 &result)
A very fast helix fit.
Abs< T >::type abs(const T &t)
riemannFit::HelixFit helixFit(const riemannFit::Matrix3xNd< n > &hits, const Eigen::Matrix< float, 6, 4 > &hits_ge, const double bField)
Helix fit by three step: -fast pre-fit (see Fast_fit() for further info); -circle fit of the hits pr...
Eigen::Matrix< double, 3, N > Matrix3xNd
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 const double PreparedBrokenLineData< n > & results
ALPAKA_FN_ACC ALPAKA_FN_INLINE void const M3xN const V4 & fast_fit
__host__ __device__ riemannFit::Matrix2d rotationMatrix(double slope)
Computes the 2D rotation matrix that transforms the line y=slope*x into the line y=0.
riemannFit::Matrix2xNd< n > pointsSZ
__host__ __device__ riemannFit::MatrixNd< n > matrixC_u(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...
riemannFit::Matrix2xNd< n > radii
xy data in the system in which the pre-fitted center is the origin
riemannFit::VectorNd< n > zInSZplane
orthogonal coordinate to the pre-fitted line in the sz plane
riemannFit::Vector2d eVec
Eigen::Matrix< double, N+1, N+1 > MatrixNplusONEd
char data[epos_bytes_allocation]
Vector2d par
(cotan(theta),Zip)
riemannFit::VectorNd< n > varBeta
kink angles in the SZ plane
static constexpr float d1
__host__ __device__ void circleFit(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...
riemannFit::VectorNd< n > sTotal
total distance traveled (three-dimensional)
data needed for the Broken Line fit procedure.