Belle II Software development
twohitfilters.h
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/vxdCaTracking/TwoHitFilters.h>
9#include <gtest/gtest.h>
10
11namespace Belle2 {
18 class TwoHitFiltersTest : public ::testing::Test {
19 protected:
20 };
21
23 TEST_F(TwoHitFiltersTest, TestEmptyFilter)
24 {
25 TwoHitFilters aFilter = TwoHitFilters();
26
27 EXPECT_DOUBLE_EQ(0., aFilter.calcDist3D());
28
29 EXPECT_DOUBLE_EQ(0., aFilter.fullDist3D());
30
31 EXPECT_DOUBLE_EQ(0., aFilter.calcDistXY());
32
33 EXPECT_DOUBLE_EQ(0., aFilter.fullDistXY());
34
35 EXPECT_DOUBLE_EQ(0., aFilter.calcDistZ());
36
37 EXPECT_DOUBLE_EQ(0., aFilter.calcSlopeRZ());
38
39 EXPECT_DOUBLE_EQ(0., aFilter.calcNormedDist3D());
40
41 EXPECT_DOUBLE_EQ(42., aFilter.filterNan(42.));
42
43 EXPECT_DOUBLE_EQ(42, aFilter.filterNan(42));
44
45 EXPECT_DOUBLE_EQ(42., aFilter.filterNan(42));
46
47 EXPECT_DOUBLE_EQ(0., aFilter.filterNan(1. / 0.));
48
49 }
50
52 TEST_F(TwoHitFiltersTest, TestFilledFilter)
53 {
54 B2Vector3D innerHit(1, 2, 3);
55 B2Vector3D outerHit(2, 3, 4);
56
57 TwoHitFilters aFilter = TwoHitFilters(outerHit, innerHit); // correct order
58
59 EXPECT_DOUBLE_EQ(3., aFilter.calcDist3D()); // does calc dist (outer - innerHit)^2!
60
61 EXPECT_DOUBLE_EQ(sqrt(3.), aFilter.fullDist3D()); // does calc dist (outer - innerHit)
62
63 EXPECT_DOUBLE_EQ(2., aFilter.calcDistXY()); // does calc dist (outer - innerHit)^2!
64
65 EXPECT_DOUBLE_EQ(sqrt(2.), aFilter.fullDistXY()); // does calc dist (outer - innerHit)calcDistXY
66
67 EXPECT_DOUBLE_EQ(1., aFilter.calcDistZ());
68
69 EXPECT_DOUBLE_EQ(atan(sqrt(2.)),
70 aFilter.calcSlopeRZ()); // normal slope is fullDistXY/calcDistZ = sqrt(2), here atan of slope is calculated
71
72 EXPECT_DOUBLE_EQ(2. / 3., aFilter.calcNormedDist3D());
73
74
75 TwoHitFilters bFilter =
76 TwoHitFilters(); // initialising an empty filter first to check whether the resetting function is doing its job...
77
78 bFilter.resetValues(innerHit, outerHit); // wrong order
79
80 EXPECT_DOUBLE_EQ(aFilter.calcDist3D(), bFilter.calcDist3D()); // does calc dist (outer - innerHit)^2!
81
82 EXPECT_DOUBLE_EQ(aFilter.fullDist3D(), bFilter.fullDist3D()); // does calc dist (outer - innerHit)
83
84 EXPECT_DOUBLE_EQ(aFilter.calcDistXY(), bFilter.calcDistXY()); // does calc dist (outer - innerHit)^2!
85
86 EXPECT_DOUBLE_EQ(aFilter.fullDistXY(), bFilter.fullDistXY()); // does calc dist (outer - innerHit)
87
88 EXPECT_DOUBLE_EQ(-aFilter.calcDistZ(), bFilter.calcDistZ());
89
90 EXPECT_DOUBLE_EQ(-aFilter.calcSlopeRZ(), bFilter.calcSlopeRZ());
91
92 EXPECT_DOUBLE_EQ(aFilter.calcNormedDist3D(), bFilter.calcNormedDist3D());
93 }
94
95
96
98 TEST_F(TwoHitFiltersTest, testLargeFilter)
99 {
100 B2Vector3D innerHit(1e150, 0, 0);
101 B2Vector3D outerHit(0, 0, 0);
102 B2Vector3D innerHit2(1, 2, 3);
103 B2Vector3D outerHit2(2, 3, 4);
104
105 TwoHitFilters aFilter = TwoHitFilters(outerHit, innerHit); // correct order
106
107 EXPECT_DOUBLE_EQ(1e300, aFilter.calcDist3D()); // does calc dist (outer - innerHit)^2!
108
109 aFilter.resetValues(innerHit2, outerHit2);
110
111 // does currently give an error at the clang-build:
112 // EXPECT_DOUBLE_EQ(-atan(sqrt(2.)), aFilter.calcSlopeRZ());
113 }
114
115
117 TEST_F(TwoHitFiltersTest, testOutOfRangeFilter) //approx 1.8e308 ... largest possible value of a double
118 {
119 B2Vector3D innerHit(1e300, 0, 0);
121
122 // \cond Doxygen is confused
123 TwoHitFilters aFilter = TwoHitFilters(outerHit, innerHit); // correct order
124
125 // EXPECT_DOUBLE_EQ(1e600, aFilter.calcDist3D()); // does calc dist (outer - innerHit)^2!
126 EXPECT_DOUBLE_EQ(innerHit * innerHit, aFilter.calcDist3D()); // does calc dist (outer - innerHit)^2!
127 // \endcond
128
129 }
130
133 TestOutOfRangeNormedDistFilter) //FAILS, because both calcDistXY() and calcDist3D() are too large to be stored in a double.
134 {
135 B2Vector3D innerHit(1e300, 0, 1e300);
136 B2Vector3D outerHit(0, 0, 0);
137 double correctResult = 1. / 2.; // this should be the result which is analytically correct
138 double wrongResult = 0.; // this is the result because of out of range of double precision
139
140 TwoHitFilters aFilter = TwoHitFilters(outerHit, innerHit); // correct order
141
142 // however, the values exceed the range of double, therefore the result is NOT EQUAL to the correct value:
143 EXPECT_NE(correctResult, aFilter.calcNormedDist3D());
144 EXPECT_DOUBLE_EQ(wrongResult, aFilter.calcNormedDist3D());
145 }
147} // namespace
Set up a few arrays and objects in the datastore.
Definition: twohitfilters.h:18
The class 'TwoHitFilters' bundles filter methods using 2 hits which are stored in B2Vector3Ds.
Definition: TwoHitFilters.h:22
double calcNormedDist3D() const
calculates the normed distance between the hits (3D), return unit: none
Definition: TwoHitFilters.h:81
double calcDist3D() const
calculates the distance between the hits (3D), returning unit: cm^2 for speed optimization
Definition: TwoHitFilters.h:55
double calcDistXY() const
calculates the distance between the hits (XY), returning unit: cm^2 for speed optimization
Definition: TwoHitFilters.h:61
double fullDistXY() const
calculates the real distance between the hits (XY), returning unit: cm
Definition: TwoHitFilters.h:64
double filterNan(double value) const
nice little nanChecker returns 0 if value was nan or inf, else returns value itself
double calcSlopeRZ() const
calculates the angle of the slope of the hits in RZ, returnValue = theta = atan(r/z)
Definition: TwoHitFilters.h:70
double fullDist3D() const
calculates the real distance between the hits (3D), returning unit: cm
Definition: TwoHitFilters.h:58
double calcDistZ() const
calculates the distance between the hits (Z only), returning unit: cm
Definition: TwoHitFilters.h:67
void resetValues(const B2Vector3D &outerHit, const B2Vector3D &innerHit)
Overrides Constructor-Setup.
Definition: TwoHitFilters.h:46
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516
double atan(double a)
atan for double
Definition: beamHelpers.h:34
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
B2Vector3D outerHit(0, 0, 0)
testing out of range behavior
Abstract base class for different kinds of events.