ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InterpolationTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InterpolationTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
15 
16 namespace Acts {
17 
18 using namespace detail;
19 
20 namespace Test {
21 
22 BOOST_AUTO_TEST_CASE(interpolation_1d) {
23  using Point = std::array<double, 1u>;
24  using Values = std::array<double, 2u>;
25 
26  Point low = {{1.}};
27  Point high = {{2.}};
28  Values v = {{10., 20.}};
29 
30  CHECK_CLOSE_REL(interpolate(Point({{0.5}}), low, high, v), 5., 1e-6);
31  CHECK_CLOSE_REL(interpolate(Point({{1.}}), low, high, v), 10., 1e-6);
32  CHECK_CLOSE_REL(interpolate(Point({{1.3}}), low, high, v), 13., 1e-6);
33  CHECK_CLOSE_REL(interpolate(Point({{1.5}}), low, high, v), 15., 1e-6);
34  CHECK_CLOSE_REL(interpolate(Point({{1.8}}), low, high, v), 18., 1e-6);
35  CHECK_CLOSE_REL(interpolate(Point({{2.}}), low, high, v), 20., 1e-6);
36  CHECK_CLOSE_REL(interpolate(Point({{2.3}}), low, high, v), 23., 1e-6);
37 }
38 
39 BOOST_AUTO_TEST_CASE(interpolation_2d) {
40  using Point = std::array<double, 2u>;
41  using Values = std::array<double, 4u>;
42 
43  Point low = {{1., 1.}};
44  Point high = {{2., 3.}};
45  Values v = {{10., 30., 20., 40.}};
46 
47  CHECK_CLOSE_REL(interpolate(Point({{1., 1.}}), low, high, v), 10., 1e-6);
48  CHECK_CLOSE_REL(interpolate(Point({{2., 1.}}), low, high, v), 20., 1e-6);
49  CHECK_CLOSE_REL(interpolate(Point({{1., 3.}}), low, high, v), 30., 1e-6);
50  CHECK_CLOSE_REL(interpolate(Point({{2., 3.}}), low, high, v), 40., 1e-6);
51  CHECK_CLOSE_REL(interpolate(Point({{1.3, 1.}}), low, high, v), 13., 1e-6);
52  CHECK_CLOSE_REL(interpolate(Point({{1.5, 1.}}), low, high, v), 15., 1e-6);
53  CHECK_CLOSE_REL(interpolate(Point({{1.8, 1.}}), low, high, v), 18., 1e-6);
54  CHECK_CLOSE_REL(interpolate(Point({{1.3, 3.}}), low, high, v), 33., 1e-6);
55  CHECK_CLOSE_REL(interpolate(Point({{1.5, 3.}}), low, high, v), 35., 1e-6);
56  CHECK_CLOSE_REL(interpolate(Point({{1.8, 3.}}), low, high, v), 38., 1e-6);
57  CHECK_CLOSE_REL(interpolate(Point({{1., 1.7}}), low, high, v), 17., 1e-6);
58  CHECK_CLOSE_REL(interpolate(Point({{1., 2.}}), low, high, v), 20., 1e-6);
59  CHECK_CLOSE_REL(interpolate(Point({{1., 2.5}}), low, high, v), 25., 1e-6);
60  CHECK_CLOSE_REL(interpolate(Point({{2., 1.7}}), low, high, v), 27., 1e-6);
61  CHECK_CLOSE_REL(interpolate(Point({{2., 2.}}), low, high, v), 30., 1e-6);
62  CHECK_CLOSE_REL(interpolate(Point({{2., 2.5}}), low, high, v), 35., 1e-6);
63  CHECK_CLOSE_REL(interpolate(Point({{1.5, 2.}}), low, high, v), 25., 1e-6);
64  CHECK_CLOSE_REL(interpolate(Point({{1.3, 1.7}}), low, high, v), 20., 1e-6);
65  CHECK_CLOSE_REL(interpolate(Point({{1.3, 2.5}}), low, high, v), 28., 1e-6);
66  CHECK_CLOSE_REL(interpolate(Point({{1.8, 1.7}}), low, high, v), 25., 1e-6);
67  CHECK_CLOSE_REL(interpolate(Point({{1.8, 2.5}}), low, high, v), 33., 1e-6);
68 }
69 
70 BOOST_AUTO_TEST_CASE(interpolation_3d) {
71  using Point = std::array<double, 3u>;
72  using Values = std::array<double, 8u>;
73 
74  Point low = {{1., 1., 1.}};
75  Point high = {{2., 3., 4.}};
76  Values v = {{10., 50., 30., 70., 20., 60., 40., 80.}};
77 
78  CHECK_CLOSE_REL(interpolate(Point({{1., 1., 1.}}), low, high, v), 10., 1e-6);
79  CHECK_CLOSE_REL(interpolate(Point({{2., 1., 1.}}), low, high, v), 20., 1e-6);
80  CHECK_CLOSE_REL(interpolate(Point({{1., 3., 1.}}), low, high, v), 30., 1e-6);
81  CHECK_CLOSE_REL(interpolate(Point({{2., 3., 1.}}), low, high, v), 40., 1e-6);
82  CHECK_CLOSE_REL(interpolate(Point({{1., 1., 4.}}), low, high, v), 50., 1e-6);
83  CHECK_CLOSE_REL(interpolate(Point({{2., 1., 4.}}), low, high, v), 60., 1e-6);
84  CHECK_CLOSE_REL(interpolate(Point({{1., 3., 4.}}), low, high, v), 70., 1e-6);
85  CHECK_CLOSE_REL(interpolate(Point({{2., 3., 4.}}), low, high, v), 80., 1e-6);
86  CHECK_CLOSE_REL(interpolate(Point({{1.5, 1., 1.}}), low, high, v), 15., 1e-6);
87  CHECK_CLOSE_REL(interpolate(Point({{1.5, 3., 1.}}), low, high, v), 35., 1e-6);
88  CHECK_CLOSE_REL(interpolate(Point({{1., 2., 1.}}), low, high, v), 20., 1e-6);
89  CHECK_CLOSE_REL(interpolate(Point({{2., 2., 1.}}), low, high, v), 30., 1e-6);
90  CHECK_CLOSE_REL(interpolate(Point({{1.5, 1., 4.}}), low, high, v), 55., 1e-6);
91  CHECK_CLOSE_REL(interpolate(Point({{1.5, 3., 4.}}), low, high, v), 75., 1e-6);
92  CHECK_CLOSE_REL(interpolate(Point({{1., 2., 4.}}), low, high, v), 60., 1e-6);
93  CHECK_CLOSE_REL(interpolate(Point({{2., 2., 4.}}), low, high, v), 70., 1e-6);
94  CHECK_CLOSE_REL(interpolate(Point({{1., 1., 2.5}}), low, high, v), 30., 1e-6);
95  CHECK_CLOSE_REL(interpolate(Point({{1., 3., 2.5}}), low, high, v), 50., 1e-6);
96  CHECK_CLOSE_REL(interpolate(Point({{2., 1., 2.5}}), low, high, v), 40., 1e-6);
97  CHECK_CLOSE_REL(interpolate(Point({{2., 3., 2.5}}), low, high, v), 60., 1e-6);
98  CHECK_CLOSE_REL(interpolate(Point({{1.5, 2., 2.5}}), low, high, v), 360. / 8,
99  1e-6);
100  CHECK_CLOSE_REL(interpolate(Point({{1.3, 2.1, 1.6}}), low, high, v), 32.,
101  1e-6);
102 }
103 
104 BOOST_AUTO_TEST_CASE(interpolation_mixed_point_values) {
105  using Point1 = ActsVectorD<1>;
106  using Point2 = std::array<double, 1u>;
107  using Point3 = std::vector<double>;
108  using Values = std::array<double, 2u>;
109 
110  Point2 low = {{1.}};
111  Point3 high = {2.};
112  Values v = {{10., 20.}};
113 
114  Point1 p;
115  CHECK_CLOSE_REL(interpolate((p << 0.5).finished(), low, high, v), 5., 1e-6);
116  CHECK_CLOSE_REL(interpolate((p << 1.).finished(), low, high, v), 10., 1e-6);
117  CHECK_CLOSE_REL(interpolate((p << 1.3).finished(), low, high, v), 13., 1e-6);
118  CHECK_CLOSE_REL(interpolate((p << 1.5).finished(), low, high, v), 15., 1e-6);
119  CHECK_CLOSE_REL(interpolate((p << 1.8).finished(), low, high, v), 18., 1e-6);
120  CHECK_CLOSE_REL(interpolate((p << 2.).finished(), low, high, v), 20., 1e-6);
121  CHECK_CLOSE_REL(interpolate((p << 2.3).finished(), low, high, v), 23., 1e-6);
122 }
123 } // namespace Test
124 
125 } // namespace Acts