Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:03

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/Tests/CommonHelpers/FloatComparisons.hpp"
0012 #include "Acts/Visualization/Interpolation3D.hpp"
0013 
0014 #include <numbers>
0015 
0016 namespace Acts::Test {
0017 
0018 BOOST_AUTO_TEST_SUITE(Visualization)
0019 
0020 BOOST_AUTO_TEST_CASE(SplineInterpolationEigen) {
0021   /// Define the input vector
0022   double R = 10.;
0023   std::vector<Acts::Vector3> inputs;
0024 
0025   // Interpolate the points options
0026   std::vector<Acts::Vector3> trajectory;
0027 
0028   // Empty in empty out check
0029   trajectory = Acts::Interpolation3D::spline(inputs, 10);
0030   BOOST_CHECK(trajectory.empty());
0031 
0032   for (double phi = 0; phi < 2 * std::numbers::pi;
0033        phi += std::numbers::pi / 4) {
0034     inputs.push_back(Acts::Vector3(R * cos(phi), R * sin(phi), 0.));
0035   }
0036 
0037   // (0) - nothing happens
0038   trajectory = Acts::Interpolation3D::spline(inputs, 1);
0039   // Check input and output size are the same
0040   BOOST_CHECK_EQUAL(trajectory.size(), inputs.size());
0041 
0042   // (1) - interpolate between the points with 12 points in total
0043   trajectory = Acts::Interpolation3D::spline(inputs, 12);
0044   // Check the output size is correct
0045   BOOST_CHECK_EQUAL(trajectory.size(), 12);
0046 
0047   for (const auto& point : trajectory) {
0048     // Check the interpolated points are on the circle
0049     // with a tolerance of course
0050     CHECK_CLOSE_ABS(point.norm(), R, 0.1);
0051     // Verify points remain in the XY plane
0052     CHECK_CLOSE_ABS(point.z(), 0., 0.1);
0053   }
0054 }
0055 
0056 BOOST_AUTO_TEST_CASE(SplineInterpolationArray) {
0057   /// Define the input vector
0058   std::vector<std::array<double, 3u>> inputs;
0059 
0060   for (double x = 0; x < 10; x += 1) {
0061     inputs.push_back({x, x * x, 0.});
0062   }
0063 
0064   // This time we keep the original hits
0065   auto trajectory = Acts::Interpolation3D::spline(inputs, 100, true);
0066 
0067   // Check the outpu type is correct
0068   constexpr bool isOutput =
0069       std::is_same_v<decltype(trajectory), decltype(inputs)>;
0070   BOOST_CHECK(isOutput);
0071 
0072   // Check the output size is correct
0073   BOOST_CHECK_EQUAL(trajectory.size(), 108);
0074 }
0075 
0076 BOOST_AUTO_TEST_CASE(SplineInterpolationErrors) {
0077   std::vector<std::array<double, 3u>> inputs;
0078 
0079   // Test with single point
0080   inputs.push_back({0., 0., 0.});
0081   auto result = Acts::Interpolation3D::spline(inputs, 10);
0082   BOOST_CHECK_EQUAL(result.size(), 1);
0083 
0084   // Test with two points
0085   inputs.push_back({1., 1., 1.});
0086   result = Acts::Interpolation3D::spline(inputs, 10);
0087   BOOST_CHECK_EQUAL(result.size(), 2);
0088 }
0089 
0090 BOOST_AUTO_TEST_SUITE_END()
0091 
0092 }  // namespace Acts::Test