8#include <tracking/trackFindingCDC/numerics/SinEqLine.h>
10#include <tracking/trackFindingCDC/geometry/Line2D.h>
12#include <tracking/trackFindingCDC/numerics/CovarianceMatrixUtil.h>
14#include <tracking/trackFindingCDC/numerics/Median.h>
15#include <tracking/trackFindingCDC/numerics/WithWeight.h>
16#include <tracking/trackFindingCDC/numerics/ESign.h>
18#include <framework/gearbox/Unit.h>
20#include <gtest/gtest.h>
24using namespace TrackFindingCDC;
27TEST(TrackFindingCDCTest, numerics_sign)
29 EXPECT_EQ(ESign::c_Plus, sign(INFINITY));
30 EXPECT_EQ(ESign::c_Plus, sign(2));
31 EXPECT_EQ(ESign::c_Plus, sign(0.0));
32 EXPECT_EQ(ESign::c_Minus, sign(-0.0));
33 EXPECT_EQ(ESign::c_Minus, sign(-2));
34 EXPECT_EQ(ESign::c_Minus, sign(-INFINITY));
35 EXPECT_EQ(ESign::c_Invalid, sign(NAN));
51TEST(TrackFindingCDCTest, numerics_SinEqLine_isIncreasing)
62TEST(TrackFindingCDCTest, numerics_SinEqLine_getIPeriodFromIHalfPeriod)
66 EXPECT_EQ(-1, iPeriod);
70TEST(TrackFindingCDCTest, numerics_SinEqLine_computeRootInInterval_simple)
76 double rootX = sinEqLine.computeRootInInterval(M_PI / 2, 3 * M_PI / 2);
77 double rootY = sinEqLine.map(rootX);
79 EXPECT_NEAR(M_PI, rootX, 10e-7);
80 EXPECT_NEAR(0.0, rootY, 10e-7);
86TEST(TrackFindingCDCTest, numerics_SinEqLine_computeRootInInterval_const)
92 double rootX = sinEqLine.computeRootInInterval(M_PI / 2, 3 * M_PI / 2);
93 double rootY = sinEqLine.map(rootX);
95 EXPECT_NEAR(150.0 *
Unit::deg, rootX, 10e-7);
96 EXPECT_NEAR(0.0, rootY, 10e-7);
101TEST(TrackFindingCDCTest, numerics_SinEqLine_computeRootInInterval_complex)
107 line.moveAlongFirst(rootX);
111 double solvedRootX = sinEqLine.computeRootInInterval(M_PI / 2, 3 * M_PI / 2);
112 double solvedRootY = sinEqLine.map(rootX);
114 EXPECT_NEAR(rootX, solvedRootX, 10e-7);
115 EXPECT_NEAR(0.0, solvedRootY, 10e-7);
120TEST(TrackFindingCDCTest, numerics_SinEqLine_computeRootLargerThanExtemumInHalfPeriod_simple)
129 double solvedRootX = sinEqLine.computeRootLargerThanExtemumInHalfPeriod(-1);
130 double solvedRootY = sinEqLine.map(rootX);
132 EXPECT_NEAR(rootX, solvedRootX, 10e-7);
133 EXPECT_NEAR(0.0, solvedRootY, 10e-7);
138TEST(TrackFindingCDCTest, numerics_SinEqLine_computeRootLargerThanExtemumInHalfPeriod)
144 line.moveAlongFirst(rootX);
148 double solvedRootX = sinEqLine.computeRootLargerThanExtemumInHalfPeriod(0);
149 double solvedRootY = sinEqLine.map(rootX);
151 EXPECT_NEAR(rootX, solvedRootX, 10e-7);
152 EXPECT_NEAR(0.0, solvedRootY, 10e-7);
157TEST(TrackFindingCDCTest, numerics_SinEqLine_computeSmallestPositiveRoot)
163 line.moveAlongFirst(rootX);
167 double solvedRootX = sinEqLine.computeSmallestPositiveRoot();
168 double solvedRootY = sinEqLine.map(rootX);
170 EXPECT_NEAR(rootX, solvedRootX, 10e-7);
171 EXPECT_NEAR(0.0, solvedRootY, 10e-7);
177TEST(TrackFindingCDCTest, numerics_SinEqLine_computeSmallestPositiveRoot_largeSlope)
183 line.moveAlongFirst(rootX);
187 double solvedRootX = sinEqLine.computeSmallestPositiveRoot();
188 double solvedRootY = sinEqLine.map(rootX);
190 EXPECT_NEAR(rootX, solvedRootX, 10e-7);
191 EXPECT_NEAR(0.0, solvedRootY, 10e-7);
197TEST(TrackFindingCDCTest, numerics_SinEqLine_computeRootForLargeSlope)
202 line.moveAlongFirst(rootX);
206 double solvedRootX = sinEqLine.computeRootForLargeSlope();
207 double solvedRootY = sinEqLine.map(rootX);
209 EXPECT_NEAR(rootX, solvedRootX, 10e-7);
210 EXPECT_NEAR(0.0, solvedRootY, 10e-7);
213TEST(TrackFindingCDCTest, numerics_median)
215 std::vector<double> fourValues{0.0, 3.0, 5.0, 100};
216 EXPECT_EQ(4.0, median(std::move(fourValues)));
218 std::vector<double> threeValues{0.0, 3.0, 5.0, 100.0, 1000.0};
219 EXPECT_EQ(5.0, median(std::move(threeValues)));
221 std::vector<WithWeight<double>> weightedValues{{0.0, 0.2},
226 EXPECT_EQ(100.0, weightedMedian(std::move(weightedValues)));
229TEST(TrackFindingCDCTest, covariance_simple_average)
242 EXPECT_NEAR(0, par[0], 1
E-8);
243 EXPECT_NEAR(1, cov[0], 1
E-8);
244 EXPECT_NEAR(1, chi2, 1
E-8);
247TEST(TrackFindingCDCTest, covariance_half_projection_average)
261 EXPECT_NEAR(0, par[0], 1
E-8);
262 EXPECT_NEAR(1, cov[0], 1
E-8);
263 EXPECT_NEAR(1, chi2, 1
E-8);
266TEST(TrackFindingCDCTest, covariance_kalman_update_average)
278 EXPECT_NEAR(0, par[0], 1
E-8);
279 EXPECT_NEAR(1, cov[0], 1
E-8);
280 EXPECT_NEAR(1, chi2, 1
E-8);
A two dimensional normal line.
static Line2D fromSlopeIntercept(const double slope, const double intercept)
Constructs a line from its slope and intercept over the first coordinate (default forward orientation...
A matrix implementation to be used as an interface typ through out the track finder.
Helper class to calculate roots for the function f(x) = sin x - slope * x - intercept.
static EIncDec getEIncDec(const Vector2D &lower, const Vector2D &upper)
Determines if the function is increasing or decreasing in the interval.
static int getIPeriodFromIHalfPeriod(int iHalfPeriod)
Helper function to translate the index of the half period to index of the containing period.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
static const double deg
degree to radians
ESign
Enumeration for the distinct sign values of floating point variables.
ESign opposite(ESign s)
Return the opposite sign. Leaves ESign::c_Invalid the same.
bool isValid(ESign s)
Returns true if sign is ESign::c_Plus, ESign::c_Minus or ESign::c_Zero.
Abstract base class for different kinds of events.
static double kalmanUpdate(const ParameterVector< N1 > &par1, const CovarianceMatrix< N1 > &cov1, const JacobianMatrix< N1, M > &ambiguity1, ParameterVector< M > &par2, CovarianceMatrix< M > &cov2)
Updates a parameter and its covariance by integrating information from parameter vector in a projecte...
static double average(const ParameterVector< N > &par1, const CovarianceMatrix< N > &cov1, const ParameterVector< N > &par2, const CovarianceMatrix< N > &cov2, ParameterVector< N > &par, CovarianceMatrix< N > &cov)
Averages two parameter vectors taking into account their respective covariances.