Belle II Software development
FacetFitter.test.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/trackFindingCDC/fitting/FacetFitter.h>
9
10#include <tracking/trackFindingCDC/geometry/UncertainParameterLine2D.h>
11#include <tracking/trackFindingCDC/geometry/LineParameters.h>
12#include <tracking/trackFindingCDC/geometry/Vector2D.h>
13
14#include <tracking/trackFindingCDC/numerics/Matrix.h>
15
16#include <framework/logging/Logger.h>
17
18#include <gtest/gtest.h>
19
20using namespace Belle2;
21using namespace TrackFindingCDC;
22
23
24TEST(TrackFindingCDCTest, fitting_FacetFitter_fitLine)
25{
26 Matrix<double, 3, 1> weights = Matrix<double, 3, 1>::Constant(1.0 / 4.0);
27 Matrix<double, 3, 3> xyl = Matrix<double, 3, 3>::Zero();
28
29 xyl(0, 0) = -1;
30 xyl(0, 1) = 1.1;
31 xyl(0, 2) = -0.05;
32
33 xyl(1, 0) = 0;
34 xyl(1, 1) = 0.8;
35 xyl(1, 2) = 0.1;
36
37 xyl(2, 0) = 1;
38 xyl(2, 1) = 1.1;
39 xyl(2, 2) = -0.05;
40
41 for (int nSteps : {100, 1, 0}) {
42 UncertainParameterLine2D fittedLine = FacetFitter::fit(xyl, weights, nSteps);
43
44 EXPECT_NEAR(1, fittedLine->tangential().x(), 1e-6);
45 EXPECT_NEAR(0, fittedLine->tangential().y(), 1e-6);
46 EXPECT_NEAR(0, fittedLine->support().x(), 1e-6);
47 EXPECT_NEAR(1, fittedLine->support().y(), 1e-6);
48 EXPECT_NEAR(0.015 * 1.0 / 4.0, fittedLine.chi2(), 1e-6);
49 B2INFO(fittedLine.lineCovariance());
50 }
51}
52
53
54TEST(TrackFindingCDCTest, fitting_FacetFitter_fitLine_alongYAxes)
55{
56 Matrix<double, 3, 1> weights = Matrix<double, 3, 1>::Constant(1.0);
57 Matrix<double, 3, 3> xyl = Matrix<double, 3, 3>::Zero();
58
59 xyl(0, 0) = 1.1;
60 xyl(0, 1) = -1;
61 xyl(0, 2) = 0.05;
62
63 xyl(1, 0) = 0.8;
64 xyl(1, 1) = 0;
65 xyl(1, 2) = -0.1;
66
67 xyl(2, 0) = 1.1;
68 xyl(2, 1) = 1;
69 xyl(2, 2) = 0.05;
70
71 for (int nSteps : {100, 1, 0}) {
72 UncertainParameterLine2D fittedLine = FacetFitter::fit(xyl, weights, nSteps);
73
74 EXPECT_NEAR(0, fittedLine->tangential().x(), 1e-6);
75 EXPECT_NEAR(1, fittedLine->tangential().y(), 1e-6);
76 EXPECT_NEAR(1, fittedLine->support().x(), 1e-6);
77 EXPECT_NEAR(0, fittedLine->support().y(), 1e-6);
78 EXPECT_NEAR(0.015, fittedLine.chi2(), 1e-6);
79 B2INFO(fittedLine.lineCovariance());
80 }
81}
82
83
84
85TEST(TrackFindingCDCTest, fitting_FacetFitter_fitLine_sameSide)
86{
87 Matrix<double, 3, 1> weights = Matrix<double, 3, 1>::Constant(1);
88 Matrix<double, 3, 3> xyl = Matrix<double, 3, 3>::Zero();
89
90 xyl(0, 0) = 1;
91 xyl(0, 1) = 0.8;
92 xyl(0, 2) = -0.1;
93
94 xyl(1, 0) = 0;
95 xyl(1, 1) = 0.8;
96 xyl(1, 2) = -0.4;
97
98 xyl(2, 0) = -1;
99 xyl(2, 1) = 0.8;
100 xyl(2, 2) = -0.1;
101
102 for (int nSteps : {100, 1, 0}) {
103 UncertainParameterLine2D fittedLine = FacetFitter::fit(xyl, weights, nSteps);
104
105 EXPECT_NEAR(-1, fittedLine->tangential().x(), 1e-6);
106 EXPECT_NEAR(0, fittedLine->tangential().y(), 1e-6);
107 EXPECT_NEAR(0, fittedLine->support().x(), 1e-6);
108 EXPECT_NEAR(1, fittedLine->support().y(), 1e-6);
109 EXPECT_NEAR(0.06, fittedLine.chi2(), 1e-6);
110 B2INFO(fittedLine.lineCovariance());
111 }
112}
static double fit(const CDCFacet &facet, int nSteps=100)
Fits a proper line to facet and returns the chi2.
Definition: FacetFitter.cc:166
const Vector2D & support() const
Gives the support vector of the line.
const Vector2D & tangential() const
Gives the tangential vector of the line.
static PlainMatrix< T, M, N > Constant(T t)
Construct a matrix with all elements set to a constant.
Definition: PlainMatrix.h:83
static PlainMatrix< T, M, N > Zero()
Construct a matrix initialized with zeros.
Definition: PlainMatrix.h:67
A parameter line including including an line covariance matrix which is interpreted as located in the...
const LineCovariance & lineCovariance() const
Getter for the whole covariance matrix of the line parameters.
double chi2() const
Getter for the chi square value of the line fit.
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:595
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:605
Abstract base class for different kinds of events.