Analysis Software
Documentation for sPHENIX simulation 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 #include <array>
17 #include <vector>
18 
19 namespace Acts {
20 
21 using namespace detail;
22 
23 namespace Test {
24 
25 BOOST_AUTO_TEST_CASE(interpolation_1d) {
26  using Point = std::array<double, 1u>;
27  using Values = std::array<double, 2u>;
28 
29  Point low = {{1.}};
30  Point high = {{2.}};
31  Values v = {{10., 20.}};
32 
33  CHECK_CLOSE_REL(interpolate(Point({{0.5}}), low, high, v), 5., 1e-6);
34  CHECK_CLOSE_REL(interpolate(Point({{1.}}), low, high, v), 10., 1e-6);
35  CHECK_CLOSE_REL(interpolate(Point({{1.3}}), low, high, v), 13., 1e-6);
36  CHECK_CLOSE_REL(interpolate(Point({{1.5}}), low, high, v), 15., 1e-6);
37  CHECK_CLOSE_REL(interpolate(Point({{1.8}}), low, high, v), 18., 1e-6);
38  CHECK_CLOSE_REL(interpolate(Point({{2.}}), low, high, v), 20., 1e-6);
39  CHECK_CLOSE_REL(interpolate(Point({{2.3}}), low, high, v), 23., 1e-6);
40 }
41 
42 BOOST_AUTO_TEST_CASE(interpolation_2d) {
43  using Point = std::array<double, 2u>;
44  using Values = std::array<double, 4u>;
45 
46  Point low = {{1., 1.}};
47  Point high = {{2., 3.}};
48  Values v = {{10., 30., 20., 40.}};
49 
50  CHECK_CLOSE_REL(interpolate(Point({{1., 1.}}), low, high, v), 10., 1e-6);
51  CHECK_CLOSE_REL(interpolate(Point({{2., 1.}}), low, high, v), 20., 1e-6);
52  CHECK_CLOSE_REL(interpolate(Point({{1., 3.}}), low, high, v), 30., 1e-6);
53  CHECK_CLOSE_REL(interpolate(Point({{2., 3.}}), low, high, v), 40., 1e-6);
54  CHECK_CLOSE_REL(interpolate(Point({{1.3, 1.}}), low, high, v), 13., 1e-6);
55  CHECK_CLOSE_REL(interpolate(Point({{1.5, 1.}}), low, high, v), 15., 1e-6);
56  CHECK_CLOSE_REL(interpolate(Point({{1.8, 1.}}), low, high, v), 18., 1e-6);
57  CHECK_CLOSE_REL(interpolate(Point({{1.3, 3.}}), low, high, v), 33., 1e-6);
58  CHECK_CLOSE_REL(interpolate(Point({{1.5, 3.}}), low, high, v), 35., 1e-6);
59  CHECK_CLOSE_REL(interpolate(Point({{1.8, 3.}}), low, high, v), 38., 1e-6);
60  CHECK_CLOSE_REL(interpolate(Point({{1., 1.7}}), low, high, v), 17., 1e-6);
61  CHECK_CLOSE_REL(interpolate(Point({{1., 2.}}), low, high, v), 20., 1e-6);
62  CHECK_CLOSE_REL(interpolate(Point({{1., 2.5}}), low, high, v), 25., 1e-6);
63  CHECK_CLOSE_REL(interpolate(Point({{2., 1.7}}), low, high, v), 27., 1e-6);
64  CHECK_CLOSE_REL(interpolate(Point({{2., 2.}}), low, high, v), 30., 1e-6);
65  CHECK_CLOSE_REL(interpolate(Point({{2., 2.5}}), low, high, v), 35., 1e-6);
66  CHECK_CLOSE_REL(interpolate(Point({{1.5, 2.}}), low, high, v), 25., 1e-6);
67  CHECK_CLOSE_REL(interpolate(Point({{1.3, 1.7}}), low, high, v), 20., 1e-6);
68  CHECK_CLOSE_REL(interpolate(Point({{1.3, 2.5}}), low, high, v), 28., 1e-6);
69  CHECK_CLOSE_REL(interpolate(Point({{1.8, 1.7}}), low, high, v), 25., 1e-6);
70  CHECK_CLOSE_REL(interpolate(Point({{1.8, 2.5}}), low, high, v), 33., 1e-6);
71 }
72 
73 BOOST_AUTO_TEST_CASE(interpolation_3d) {
74  using Point = std::array<double, 3u>;
75  using Values = std::array<double, 8u>;
76 
77  Point low = {{1., 1., 1.}};
78  Point high = {{2., 3., 4.}};
79  Values v = {{10., 50., 30., 70., 20., 60., 40., 80.}};
80 
81  CHECK_CLOSE_REL(interpolate(Point({{1., 1., 1.}}), low, high, v), 10., 1e-6);
82  CHECK_CLOSE_REL(interpolate(Point({{2., 1., 1.}}), low, high, v), 20., 1e-6);
83  CHECK_CLOSE_REL(interpolate(Point({{1., 3., 1.}}), low, high, v), 30., 1e-6);
84  CHECK_CLOSE_REL(interpolate(Point({{2., 3., 1.}}), low, high, v), 40., 1e-6);
85  CHECK_CLOSE_REL(interpolate(Point({{1., 1., 4.}}), low, high, v), 50., 1e-6);
86  CHECK_CLOSE_REL(interpolate(Point({{2., 1., 4.}}), low, high, v), 60., 1e-6);
87  CHECK_CLOSE_REL(interpolate(Point({{1., 3., 4.}}), low, high, v), 70., 1e-6);
88  CHECK_CLOSE_REL(interpolate(Point({{2., 3., 4.}}), low, high, v), 80., 1e-6);
89  CHECK_CLOSE_REL(interpolate(Point({{1.5, 1., 1.}}), low, high, v), 15., 1e-6);
90  CHECK_CLOSE_REL(interpolate(Point({{1.5, 3., 1.}}), low, high, v), 35., 1e-6);
91  CHECK_CLOSE_REL(interpolate(Point({{1., 2., 1.}}), low, high, v), 20., 1e-6);
92  CHECK_CLOSE_REL(interpolate(Point({{2., 2., 1.}}), low, high, v), 30., 1e-6);
93  CHECK_CLOSE_REL(interpolate(Point({{1.5, 1., 4.}}), low, high, v), 55., 1e-6);
94  CHECK_CLOSE_REL(interpolate(Point({{1.5, 3., 4.}}), low, high, v), 75., 1e-6);
95  CHECK_CLOSE_REL(interpolate(Point({{1., 2., 4.}}), low, high, v), 60., 1e-6);
96  CHECK_CLOSE_REL(interpolate(Point({{2., 2., 4.}}), low, high, v), 70., 1e-6);
97  CHECK_CLOSE_REL(interpolate(Point({{1., 1., 2.5}}), low, high, v), 30., 1e-6);
98  CHECK_CLOSE_REL(interpolate(Point({{1., 3., 2.5}}), low, high, v), 50., 1e-6);
99  CHECK_CLOSE_REL(interpolate(Point({{2., 1., 2.5}}), low, high, v), 40., 1e-6);
100  CHECK_CLOSE_REL(interpolate(Point({{2., 3., 2.5}}), low, high, v), 60., 1e-6);
101  CHECK_CLOSE_REL(interpolate(Point({{1.5, 2., 2.5}}), low, high, v), 360. / 8,
102  1e-6);
103  CHECK_CLOSE_REL(interpolate(Point({{1.3, 2.1, 1.6}}), low, high, v), 32.,
104  1e-6);
105 }
106 
107 BOOST_AUTO_TEST_CASE(interpolation_mixed_point_values) {
108  using Point1 = ActsVector<1>;
109  using Point2 = std::array<double, 1u>;
110  using Point3 = std::vector<double>;
111  using Values = std::array<double, 2u>;
112 
113  Point2 low = {{1.}};
114  Point3 high = {2.};
115  Values v = {{10., 20.}};
116 
117  Point1 p;
118  CHECK_CLOSE_REL(interpolate((p << 0.5).finished(), low, high, v), 5., 1e-6);
119  CHECK_CLOSE_REL(interpolate((p << 1.).finished(), low, high, v), 10., 1e-6);
120  CHECK_CLOSE_REL(interpolate((p << 1.3).finished(), low, high, v), 13., 1e-6);
121  CHECK_CLOSE_REL(interpolate((p << 1.5).finished(), low, high, v), 15., 1e-6);
122  CHECK_CLOSE_REL(interpolate((p << 1.8).finished(), low, high, v), 18., 1e-6);
123  CHECK_CLOSE_REL(interpolate((p << 2.).finished(), low, high, v), 20., 1e-6);
124  CHECK_CLOSE_REL(interpolate((p << 2.3).finished(), low, high, v), 23., 1e-6);
125 }
126 } // namespace Test
127 
128 } // namespace Acts