1 #ifndef RecoPixelVertexing_PixelTrackFitting_interface_BrokenLine_h
2 #define RecoPixelVertexing_PixelTrackFitting_interface_BrokenLine_h
4 #include <Eigen/Eigenvalues>
58 constexpr
double inv_X0 = 0.06 / 16.;
64 constexpr
double geometry_factor = 0.7;
102 using scalar = std::remove_reference<decltype(circle.
par(0))>::
type;
112 scalar deltaPara = x0 * cosPhi + y0 * sinPhi;
113 scalar deltaOrth = x0 * sinPhi - y0 * cosPhi + dee;
114 scalar tempSmallU = 1 + rho * dee;
115 scalar tempC = -rho * y0 + tempSmallU * cosPhi;
116 scalar tempB = rho * x0 + tempSmallU * sinPhi;
122 scalar tempV = 1. + rho * deltaOrth;
124 scalar mu = 1. / (tempU * (1. + tempU)) + rho * lambda;
127 2. *
mu * tempSmallU * deltaPara, 2. *
mu * tempV,
mu * zeta - lambda * tempA, 0, 0, 1.;
131 circle.
par(0) = atan2(tempB, tempC);
133 circle.
par(1) = tempA / (1 + tempU);
138 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
149 template <
typename M3xN,
typename V4,
int n>
157 dVec =
hits.block(0, 1, 2, 1) -
hits.block(0, 0, 2, 1);
158 eVec =
hits.block(0,
n - 1, 2, 1) -
hits.block(0,
n - 2, 2, 1);
167 eVec = -fast_fit(2) * fast_fit.head(2) / fast_fit.head(2).norm();
168 for (u_int
i = 0;
i <
n;
i++) {
169 dVec =
results.radii.block(0,
i, 2, 1);
177 for (u_int
i = 0;
i <
n;
i++) {
179 pointsSZ(1,
i) = zVec(
i);
180 pointsSZ.block(0,
i, 2, 1) = rotMat * pointsSZ.block(0,
i, 2, 1);
182 results.sTotal = pointsSZ.block(0, 0, 1,
n).transpose();
183 results.zInSZplane = pointsSZ.block(1, 0, 1,
n).transpose();
187 for (u_int
i = 1;
i <
n - 1;
i++) {
210 for (u_int
i = 0;
i <
n;
i++) {
214 if (
i > 0 &&
i <
n - 1)
217 ((sTotal(
i + 1) - sTotal(
i)) * (sTotal(
i) - sTotal(
i - 1))));
221 if (
i > 0 &&
i <
n - 1)
223 1. / (varBeta(
i) * (sTotal(
i + 1) - sTotal(
i))) *
224 (-(sTotal(
i + 1) - sTotal(
i - 1)) / ((sTotal(
i + 1) - sTotal(
i)) * (sTotal(
i) - sTotal(
i - 1))));
227 1. / (varBeta(
i + 1) * (sTotal(
i + 1) - sTotal(
i))) *
228 (-(sTotal(
i + 2) - sTotal(
i)) / ((sTotal(
i + 2) - sTotal(
i + 1)) * (sTotal(
i + 1) - sTotal(
i))));
231 c_uMat(
i,
i + 2) = 1. / (varBeta(
i + 1) * (sTotal(
i + 2) - sTotal(
i + 1)) * (sTotal(
i + 1) - sTotal(
i)));
235 return c_uMat + c_uMat.transpose();
248 template <
typename M3xN,
typename V4>
250 constexpr uint32_t
n = M3xN::ColsAtCompileTime;
257 result(0) =
hits(0, 0) - (
a(1) *
c.squaredNorm() +
c(1) *
a.squaredNorm()) *
tmp;
258 result(1) =
hits(1, 0) + (
a(0) *
c.squaredNorm() +
c(0) *
a.squaredNorm()) *
tmp;
295 template <
typename M3xN,
typename M6xN,
typename V4,
int n>
303 auto& radii =
data.radii;
304 const auto& sTransverse =
data.sTransverse;
305 const auto& sTotal =
data.sTotal;
306 auto& zInSZplane =
data.zInSZplane;
307 auto& varBeta =
data.varBeta;
308 const double slope = -circle_results.
qCharge / fast_fit(3);
311 for (u_int
i = 0;
i <
n;
i++) {
312 zInSZplane(
i) = radii.block(0,
i, 2, 1).norm() - fast_fit(2);
318 for (u_int
i = 0;
i <
n;
i++) {
319 vMat(0, 0) = hits_ge.col(
i)[0];
320 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
321 vMat(1, 1) = hits_ge.col(
i)[2];
324 1. / ((rotMat * vMat * rotMat.transpose())(1, 1));
329 for (u_int
i = 0;
i <
n;
i++) {
330 r_uVec(
i) = weightsVec(
i) * zInSZplane(
i);
334 c_uMat.block(0, 0,
n,
n) =
matrixC_u(weightsVec, sTransverse, varBeta);
337 for (u_int
i = 0;
i <
n;
i++) {
339 if (
i > 0 &&
i <
n - 1) {
341 -(sTransverse(
i + 1) - sTransverse(
i - 1)) * (sTransverse(
i + 1) - sTransverse(
i - 1)) /
342 (2. * varBeta(
i) * (sTransverse(
i + 1) - sTransverse(
i)) * (sTransverse(
i) - sTransverse(
i - 1)));
346 (sTransverse(
i) - sTransverse(
i - 2)) / (2. * varBeta(
i - 1) * (sTransverse(
i) - sTransverse(
i - 1)));
350 (sTransverse(
i + 2) - sTransverse(
i)) / (2. * varBeta(
i + 1) * (sTransverse(
i + 1) - sTransverse(
i)));
352 c_uMat(
n,
i) = c_uMat(
i,
n);
353 if (
i > 0 &&
i <
n - 1)
358 std::cout <<
"CU5\n" << c_uMat << std::endl;
363 std::cout <<
"I5\n" << iMat << std::endl;
370 radii.block(0, 0, 2, 1) /= radii.block(0, 0, 2, 1).norm();
371 radii.block(0, 1, 2, 1) /= radii.block(0, 1, 2, 1).norm();
376 circle_results.
par << atan2((eVec - dVec)(1), (eVec - dVec)(0)),
379 circle_results.
qCharge * (1. / fast_fit(2) + uVec(
n));
384 double tmp1 = eMinusd.squaredNorm();
388 jacobian << (radii(1, 0) * eMinusd(0) - eMinusd(1) * radii(0, 0)) / tmp1,
389 (radii(1, 1) * eMinusd(0) - eMinusd(1) * radii(0, 1)) / tmp1, 0,
390 (circle_results.
qCharge / 2) * (eMinusd(0) * radii(0, 0) + eMinusd(1) * radii(1, 0)) / tmp2,
391 (circle_results.
qCharge / 2) * (eMinusd(0) * radii(0, 1) + eMinusd(1) * radii(1, 1)) / tmp2, 0, 0, 0,
394 circle_results.
cov << iMat(0, 0), iMat(0, 1), iMat(0,
n), iMat(1, 0), iMat(1, 1), iMat(1,
n), iMat(
n, 0),
395 iMat(
n, 1), iMat(
n,
n);
397 circle_results.
cov = jacobian * circle_results.
cov * jacobian.transpose();
401 auto eMinusDVec = eVec - dVec;
402 translateKarimaki(circle_results, 0.5 * eMinusDVec(0), 0.5 * eMinusDVec(1), jacobian);
403 circle_results.
cov(0, 0) +=
411 circle_results.
chi2 = 0;
412 for (u_int
i = 0;
i <
n;
i++) {
414 if (
i > 0 &&
i <
n - 1)
415 circle_results.
chi2 +=
417 uVec(
i) * (sTransverse(
i + 1) - sTransverse(
i - 1)) /
418 ((sTransverse(
i + 1) - sTransverse(
i)) * (sTransverse(
i) - sTransverse(
i - 1))) +
419 uVec(
i + 1) / (sTransverse(
i + 1) - sTransverse(
i)) +
420 (sTransverse(
i + 1) - sTransverse(
i - 1)) * uVec(
n) / 2) /
449 template <
typename V4,
typename M6xN,
int n>
455 const auto& radii =
data.radii;
456 const auto& sTotal =
data.sTotal;
457 const auto& zInSZplane =
data.zInSZplane;
458 const auto& varBeta =
data.varBeta;
460 const double slope = -
data.qCharge / fast_fit(3);
465 riemannFit::Matrix2x3d::Zero();
467 for (u_int
i = 0;
i <
n;
i++) {
468 vMat(0, 0) = hits_ge.col(
i)[0];
469 vMat(0, 1) = vMat(1, 0) = hits_ge.col(
i)[1];
470 vMat(0, 2) = vMat(2, 0) = hits_ge.col(
i)[3];
471 vMat(1, 1) = hits_ge.col(
i)[2];
472 vMat(2, 1) = vMat(1, 2) = hits_ge.col(
i)[4];
473 vMat(2, 2) = hits_ge.col(
i)[5];
474 auto tmp = 1. / radii.block(0,
i, 2, 1).norm();
475 jacobXYZtosZ(0, 0) = radii(1,
i) *
tmp;
476 jacobXYZtosZ(0, 1) = -radii(0,
i) *
tmp;
477 jacobXYZtosZ(1, 2) = 1.;
478 weights(
i) = 1. / ((rotMat * jacobXYZtosZ * vMat * jacobXYZtosZ.transpose() * rotMat.transpose())(
483 for (u_int
i = 0;
i <
n;
i++) {
492 std::cout <<
"I4\n" << iMat << std::endl;
498 line_results.
par << (uVec(1) - uVec(0)) / (sTotal(1) - sTotal(0)), uVec(0);
499 auto idiff = 1. / (sTotal(1) - sTotal(0));
500 line_results.
cov << (iMat(0, 0) - 2 * iMat(0, 1) + iMat(1, 1)) *
riemannFit::sqr(idiff) +
502 (iMat(0, 1) - iMat(0, 0)) * idiff, (iMat(0, 1) - iMat(0, 0)) * idiff, iMat(0, 0);
508 jacobian(1, 0) = -sTotal(0);
510 line_results.
par(1) += -line_results.
par(0) * sTotal(0);
511 line_results.
cov = jacobian * line_results.
cov * jacobian.transpose();
514 auto tmp = rotMat(0, 0) - line_results.
par(0) * rotMat(0, 1);
515 jacobian(1, 1) = 1. /
tmp;
516 jacobian(0, 0) = jacobian(1, 1) * jacobian(1, 1);
518 jacobian(1, 0) = line_results.
par(1) * rotMat(0, 1) * jacobian(0, 0);
519 line_results.
par(1) = line_results.
par(1) * jacobian(1, 1);
520 line_results.
par(0) = (rotMat(0, 1) + line_results.
par(0) * rotMat(0, 0)) * jacobian(1, 1);
521 line_results.
cov = jacobian * line_results.
cov * jacobian.transpose();
524 line_results.
chi2 = 0;
525 for (u_int
i = 0;
i <
n;
i++) {
527 if (
i > 0 &&
i <
n - 1)
529 uVec(
i) * (sTotal(
i + 1) - sTotal(
i - 1)) /
530 ((sTotal(
i + 1) - sTotal(
i)) * (sTotal(
i) - sTotal(
i - 1))) +
531 uVec(
i + 1) / (sTotal(
i + 1) - sTotal(
i))) /
572 const Eigen::Matrix<float, 6, 4>& hits_ge,
588 jacobian << 1., 0, 0, 0, 1., 0, 0, 0,
591 circle.
cov = jacobian * circle.
cov * jacobian.transpose();
594 helix.
cov = riemannFit::MatrixXd::Zero(5, 5);
595 helix.
cov.block(0, 0, 3, 3) = circle.
cov;
596 helix.
cov.block(3, 3, 2, 2) =
line.cov;
606 #endif // RecoPixelVertexing_PixelTrackFitting_interface_BrokenLine_h