Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-24 08:20:25

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/tools/floating_point_comparison.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0013 #include "Acts/MagneticField/MultiRangeBField.hpp"
0014 #include "Acts/Utilities/Result.hpp"
0015 
0016 using namespace Acts;
0017 
0018 namespace ActsTests {
0019 
0020 MagneticFieldContext mfContext = MagneticFieldContext();
0021 
0022 BOOST_AUTO_TEST_SUITE(MagneticFieldSuite)
0023 
0024 BOOST_AUTO_TEST_CASE(TestMultiRangeBField) {
0025   std::vector<std::pair<RangeXD<3, double>, Vector3>> inputs;
0026 
0027   inputs.emplace_back(RangeXD<3, double>{{0., 0., 0.}, {3., 3., 3.}},
0028                       Vector3{0., 0., 2.});
0029   inputs.emplace_back(RangeXD<3, double>{{1., 1., 1.}, {2., 2., 10.}},
0030                       Vector3{2., 0., 0.});
0031 
0032   const MultiRangeBField bfield(std::move(inputs));
0033 
0034   auto bcache = bfield.makeCache(mfContext);
0035 
0036   // Test a point inside the first volume.
0037   {
0038     Result<Vector3> r = bfield.getField({0.5, 0.5, 0.5}, bcache);
0039     BOOST_CHECK(r.ok());
0040     BOOST_CHECK_CLOSE((*r)[0], 0., 0.05);
0041     BOOST_CHECK_CLOSE((*r)[1], 0., 0.05);
0042     BOOST_CHECK_CLOSE((*r)[2], 2., 0.05);
0043   }
0044 
0045   // Test a point inside the second volume, not overlapping the first.
0046   {
0047     Result<Vector3> r = bfield.getField({1.5, 1.5, 5.}, bcache);
0048     BOOST_CHECK(r.ok());
0049     BOOST_CHECK_CLOSE((*r)[0], 2., 0.05);
0050     BOOST_CHECK_CLOSE((*r)[1], 0., 0.05);
0051     BOOST_CHECK_CLOSE((*r)[2], 0., 0.05);
0052   }
0053 
0054   // Test a point inside the first volume again.
0055   {
0056     Result<Vector3> r = bfield.getField({2.5, 2.5, 2.5}, bcache);
0057     BOOST_CHECK(r.ok());
0058     BOOST_CHECK_CLOSE((*r)[0], 0., 0.05);
0059     BOOST_CHECK_CLOSE((*r)[1], 0., 0.05);
0060     BOOST_CHECK_CLOSE((*r)[2], 2., 0.05);
0061   }
0062 
0063   // Test a point inside the second volume in the overlap region.
0064   {
0065     Result<Vector3> r = bfield.getField({1.5, 1.5, 1.5}, bcache);
0066     BOOST_CHECK(r.ok());
0067     BOOST_CHECK_CLOSE((*r)[0], 2., 0.05);
0068     BOOST_CHECK_CLOSE((*r)[1], 0., 0.05);
0069     BOOST_CHECK_CLOSE((*r)[2], 0., 0.05);
0070   }
0071 
0072   // Test a point outside all volumes.
0073   {
0074     Result<Vector3> r = bfield.getField({-1., -1., -1}, bcache);
0075     BOOST_CHECK(!r.ok());
0076   }
0077 }
0078 
0079 BOOST_AUTO_TEST_SUITE_END()
0080 
0081 }  // namespace ActsTests