4 #include <gtest/gtest.h>
6 #include <framework/gearbox/Const.h>
8 #include <analysis/VertexFitting/TreeFitter/HelixUtils.h>
9 #include <framework/geometry/BFieldManager.h>
10 #include <framework/gearbox/Unit.h>
15 class TreeFitterHelixJacobianTest :
public ::testing::Test {
20 TEST_F(TreeFitterHelixJacobianTest, Helix)
22 const double eps = 1E-6;
24 const double px = 0.123214;
25 const double py = 1.543;
26 const double pz = -2.876;
27 const double x = 3.765346;
28 const double y = -2.56756;
29 const double z = 1.678;
34 const double aq =
charge / alpha;
38 const double pt = std::sqrt(px * px + py * py);
39 const double omega = aq / pt;
41 const double phi = atan(py / px);
42 const double cosPhi = std::cos(phi);
43 const double sinPhi = std::sin(phi);
45 const double para = -x * cosPhi - y * sinPhi;
46 const double ortho = -y * cosPhi + x * sinPhi;
47 const double R2 = para * para + ortho * ortho;
48 const double A = 2 * ortho + omega * R2;
49 const double U = std::sqrt(1 + omega * A);
50 const double d0 = A / (1 + U);
51 const double l = 1 / omega * atan((omega * para) / (1 + omega * ortho));
52 const double phi0 = phi + atan((omega * para) / (1 + omega * ortho));
53 const double tanLambda = pz / pt;
54 const double z0 = z + tanLambda * l;
56 std::vector<double> h = {d0, phi0, omega, z0, tanLambda};
57 std::vector<double> h_framework = {helix.getD0(), helix.getPhi0(), helix.getOmega(), helix.getZ0(), helix.getTanLambda()};
58 for (
int row = 0; row < 5; ++row) {
59 double res = h[row] - h_framework[row];
60 EXPECT_TRUE(res < eps) <<
"row " << row <<
" num - ana " << res <<
" framework " << h_framework[row] <<
" mine " << h[row];
65 TEST_F(TreeFitterHelixJacobianTest, Parameters)
67 const double delta = 1
e-6;
68 const double eps = 1
e-5;
70 Eigen::Matrix<double, 5, 6> jacobian_numerical = Eigen::Matrix<double, 5, 6>::Zero(5, 6);
71 Eigen::Matrix<double, 5, 6> jacobian_analytical = Eigen::Matrix<double, 5, 6>::Zero(5, 6);
77 const double px = 0.523214;
78 const double py = -1.543;
79 const double pz = -2.876;
80 const double x = -3.765346;
81 const double y = -2.56756;
82 const double z = 5.678;
84 const Eigen::Matrix<double, 1, 6> positionAndMom_ = (Eigen::Matrix<double, 1, 6>() << x, y, z, px, py, pz).finished();
90 for (
int jin = 0; jin < 6; ++jin) {
91 for (
int i = 0; i < 3; ++i) {
92 postmp[i] = positionAndMom_(i);
93 momtmp[i] = positionAndMom_(i + 3);
98 momtmp[jin - 3] += delta;
101 Belle2::Helix helixPlusDelta(postmp, momtmp, charge, bfield);
103 jacobian_numerical(0, jin) = (helixPlusDelta.getD0() - helix.getD0()) / delta;
104 jacobian_numerical(1, jin) = (helixPlusDelta.getPhi0() - helix.getPhi0()) / delta;
105 jacobian_numerical(2, jin) = (helixPlusDelta.getOmega() - helix.getOmega()) / delta;
106 jacobian_numerical(3, jin) = (helixPlusDelta.getZ0() - helix.getZ0()) / delta;
107 jacobian_numerical(4, jin) = (helixPlusDelta.getTanLambda() - helix.getTanLambda()) / delta;
112 for (
int row = 0; row < 5; ++row) {
113 for (
int col = 0; col < 6; ++col) {
114 const double num = jacobian_numerical(row, col);
115 const double ana = jacobian_analytical(row, col);
116 const double res = std::abs(num - ana);
117 EXPECT_TRUE(res < eps) <<
"row " << row <<
" col " << col <<
" num - ana " << res <<
" num " << num <<
" ana " << ana;