Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 08:23:02

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/Interpolation.hpp"
0013 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0014 
0015 #include <array>
0016 #include <vector>
0017 
0018 using namespace Acts;
0019 
0020 namespace ActsTests {
0021 
0022 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0023 
0024 BOOST_AUTO_TEST_CASE(interpolation_1d) {
0025   using Point = std::array<double, 1u>;
0026   using Values = std::array<double, 2u>;
0027 
0028   const Point low{1.};
0029   const Point high{2.};
0030   const Values v{10., 20.};
0031 
0032   CHECK_CLOSE_REL(interpolate(Point{1.}, low, high, v), 10., 1e-6);
0033   CHECK_CLOSE_REL(interpolate(Point{1.3}, low, high, v), 13., 1e-6);
0034   CHECK_CLOSE_REL(interpolate(Point{1.5}, low, high, v), 15., 1e-6);
0035   CHECK_CLOSE_REL(interpolate(Point{1.8}, low, high, v), 18., 1e-6);
0036   CHECK_CLOSE_REL(interpolate(Point{2.}, low, high, v), 20., 1e-6);
0037 }
0038 
0039 BOOST_AUTO_TEST_CASE(interpolation_2d) {
0040   using Point = std::array<double, 2u>;
0041   using Values = std::array<double, 4u>;
0042 
0043   const Point low{1., 1.};
0044   const Point high{2., 3.};
0045   const Values v{10., 30., 20., 40.};
0046 
0047   CHECK_CLOSE_REL(interpolate(Point{1., 1.}, low, high, v), 10., 1e-6);
0048   CHECK_CLOSE_REL(interpolate(Point{2., 1.}, low, high, v), 20., 1e-6);
0049   CHECK_CLOSE_REL(interpolate(Point{1., 3.}, low, high, v), 30., 1e-6);
0050   CHECK_CLOSE_REL(interpolate(Point{2., 3.}, low, high, v), 40., 1e-6);
0051   CHECK_CLOSE_REL(interpolate(Point{1.3, 1.}, low, high, v), 13., 1e-6);
0052   CHECK_CLOSE_REL(interpolate(Point{1.5, 1.}, low, high, v), 15., 1e-6);
0053   CHECK_CLOSE_REL(interpolate(Point{1.8, 1.}, low, high, v), 18., 1e-6);
0054   CHECK_CLOSE_REL(interpolate(Point{1.3, 3.}, low, high, v), 33., 1e-6);
0055   CHECK_CLOSE_REL(interpolate(Point{1.5, 3.}, low, high, v), 35., 1e-6);
0056   CHECK_CLOSE_REL(interpolate(Point{1.8, 3.}, low, high, v), 38., 1e-6);
0057   CHECK_CLOSE_REL(interpolate(Point{1., 1.7}, low, high, v), 17., 1e-6);
0058   CHECK_CLOSE_REL(interpolate(Point{1., 2.}, low, high, v), 20., 1e-6);
0059   CHECK_CLOSE_REL(interpolate(Point{1., 2.5}, low, high, v), 25., 1e-6);
0060   CHECK_CLOSE_REL(interpolate(Point{2., 1.7}, low, high, v), 27., 1e-6);
0061   CHECK_CLOSE_REL(interpolate(Point{2., 2.}, low, high, v), 30., 1e-6);
0062   CHECK_CLOSE_REL(interpolate(Point{2., 2.5}, low, high, v), 35., 1e-6);
0063   CHECK_CLOSE_REL(interpolate(Point{1.5, 2.}, low, high, v), 25., 1e-6);
0064   CHECK_CLOSE_REL(interpolate(Point{1.3, 1.7}, low, high, v), 20., 1e-6);
0065   CHECK_CLOSE_REL(interpolate(Point{1.3, 2.5}, low, high, v), 28., 1e-6);
0066   CHECK_CLOSE_REL(interpolate(Point{1.8, 1.7}, low, high, v), 25., 1e-6);
0067   CHECK_CLOSE_REL(interpolate(Point{1.8, 2.5}, low, high, v), 33., 1e-6);
0068 }
0069 
0070 BOOST_AUTO_TEST_CASE(interpolation_3d) {
0071   using Point = std::array<double, 3u>;
0072   using Values = std::array<double, 8u>;
0073 
0074   const Point low{1., 1., 1.};
0075   const Point high{2., 3., 4.};
0076   const Values v{10., 50., 30., 70., 20., 60., 40., 80.};
0077 
0078   CHECK_CLOSE_REL(interpolate(Point{1., 1., 1.}, low, high, v), 10., 1e-6);
0079   CHECK_CLOSE_REL(interpolate(Point{2., 1., 1.}, low, high, v), 20., 1e-6);
0080   CHECK_CLOSE_REL(interpolate(Point{1., 3., 1.}, low, high, v), 30., 1e-6);
0081   CHECK_CLOSE_REL(interpolate(Point{2., 3., 1.}, low, high, v), 40., 1e-6);
0082   CHECK_CLOSE_REL(interpolate(Point{1., 1., 4.}, low, high, v), 50., 1e-6);
0083   CHECK_CLOSE_REL(interpolate(Point{2., 1., 4.}, low, high, v), 60., 1e-6);
0084   CHECK_CLOSE_REL(interpolate(Point{1., 3., 4.}, low, high, v), 70., 1e-6);
0085   CHECK_CLOSE_REL(interpolate(Point{2., 3., 4.}, low, high, v), 80., 1e-6);
0086   CHECK_CLOSE_REL(interpolate(Point{1.5, 1., 1.}, low, high, v), 15., 1e-6);
0087   CHECK_CLOSE_REL(interpolate(Point{1.5, 3., 1.}, low, high, v), 35., 1e-6);
0088   CHECK_CLOSE_REL(interpolate(Point{1., 2., 1.}, low, high, v), 20., 1e-6);
0089   CHECK_CLOSE_REL(interpolate(Point{2., 2., 1.}, low, high, v), 30., 1e-6);
0090   CHECK_CLOSE_REL(interpolate(Point{1.5, 1., 4.}, low, high, v), 55., 1e-6);
0091   CHECK_CLOSE_REL(interpolate(Point{1.5, 3., 4.}, low, high, v), 75., 1e-6);
0092   CHECK_CLOSE_REL(interpolate(Point{1., 2., 4.}, low, high, v), 60., 1e-6);
0093   CHECK_CLOSE_REL(interpolate(Point{2., 2., 4.}, low, high, v), 70., 1e-6);
0094   CHECK_CLOSE_REL(interpolate(Point{1., 1., 2.5}, low, high, v), 30., 1e-6);
0095   CHECK_CLOSE_REL(interpolate(Point{1., 3., 2.5}, low, high, v), 50., 1e-6);
0096   CHECK_CLOSE_REL(interpolate(Point{2., 1., 2.5}, low, high, v), 40., 1e-6);
0097   CHECK_CLOSE_REL(interpolate(Point{2., 3., 2.5}, low, high, v), 60., 1e-6);
0098   CHECK_CLOSE_REL(interpolate(Point{1.5, 2., 2.5}, low, high, v), 360. / 8,
0099                   1e-6);
0100   CHECK_CLOSE_REL(interpolate(Point{1.3, 2.1, 1.6}, low, high, v), 32., 1e-6);
0101 }
0102 
0103 BOOST_AUTO_TEST_CASE(interpolation_mixed_point_values) {
0104   using Point1 = Vector<1>;
0105   using Point2 = std::array<double, 1u>;
0106   using Point3 = std::vector<double>;
0107   using Values = std::array<double, 2u>;
0108 
0109   const Point2 low{1.};
0110   const Point3 high{2.};
0111   const Values v{{10., 20.}};
0112 
0113   CHECK_CLOSE_REL(interpolate(Point1{1}, low, high, v), 10., 1e-6);
0114   CHECK_CLOSE_REL(interpolate(Point1{1.3}, low, high, v), 13., 1e-6);
0115   CHECK_CLOSE_REL(interpolate(Point1{1.5}, low, high, v), 15., 1e-6);
0116   CHECK_CLOSE_REL(interpolate(Point1{1.8}, low, high, v), 18., 1e-6);
0117   CHECK_CLOSE_REL(interpolate(Point1{2}, low, high, v), 20., 1e-6);
0118 }
0119 
0120 BOOST_AUTO_TEST_SUITE_END()
0121 
0122 }  // namespace ActsTests