Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-26 07:56:19

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/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/MagneticField/ConstantBField.hpp"
0015 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0016 #include "Acts/Utilities/Result.hpp"
0017 
0018 namespace bdata = boost::unit_test::data;
0019 
0020 using namespace Acts;
0021 using namespace Acts::UnitLiterals;
0022 
0023 namespace ActsTests {
0024 
0025 // Create a test context
0026 MagneticFieldContext mfContext = MagneticFieldContext();
0027 
0028 BOOST_AUTO_TEST_SUITE(MagneticFieldSuite)
0029 
0030 /// @brief unit test for construction of constant magnetic field
0031 ///
0032 /// Tests the correct behavior and consistency of
0033 /// -# ConstantBField::ConstantBField(double Bx,double By,double Bz)
0034 /// -# ConstantBField::ConstantBField(Vector3 B)
0035 /// -# ConstantBField::getField(const double* xyz, double* B) const
0036 /// -# ConstantBField::getField(const Vector3& pos) const
0037 BOOST_DATA_TEST_CASE(
0038     ConstantBField_components,
0039     bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
0040                    bdata::distribution =
0041                        std::uniform_real_distribution<double>(-2_T, 2_T))) ^
0042         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0043                        bdata::distribution =
0044                            std::uniform_real_distribution<double>(-1_T, 4_T))) ^
0045         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
0046                        bdata::distribution =
0047                            std::uniform_real_distribution<double>(0_T, 10_T))) ^
0048         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
0049                        bdata::distribution =
0050                            std::uniform_real_distribution<double>(-10_m,
0051                                                                   10_m))) ^
0052         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
0053                        bdata::distribution =
0054                            std::uniform_real_distribution<double>(-10_m,
0055                                                                   10_m))) ^
0056         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
0057                        bdata::distribution =
0058                            std::uniform_real_distribution<double>(-10_m,
0059                                                                   10_m))) ^
0060         bdata::xrange(10),
0061     x, y, z, bx, by, bz, index) {
0062   (void)index;
0063   const Vector3 Btrue(bx, by, bz);
0064   const Vector3 pos(x, y, z);
0065   const ConstantBField BField(Btrue);
0066 
0067   auto bCache = BField.makeCache(mfContext);
0068 
0069   BOOST_CHECK_EQUAL(Btrue, BField.getField());
0070 
0071   BOOST_CHECK_EQUAL(Btrue, BField.getField(pos, bCache).value());
0072   BOOST_CHECK_EQUAL(Btrue, BField.getField(Vector3(0, 0, 0), bCache).value());
0073   BOOST_CHECK_EQUAL(Btrue, BField.getField(-2 * pos, bCache).value());
0074 }
0075 
0076 /// @brief unit test for update of constant magnetic field
0077 ///
0078 /// Tests the correct behavior and consistency of
0079 /// -# ConstantBField::setField(double Bx, double By, double Bz)
0080 /// -# ConstantBField::setField(const Vector3& B)
0081 /// -# ConstantBField::getField(const double* xyz, double* B) const
0082 /// -# ConstantBField::getField(const Vector3& pos) const
0083 BOOST_DATA_TEST_CASE(
0084     ConstantBField_update,
0085     bdata::random((bdata::engine = std::mt19937(), bdata::seed = 1,
0086                    bdata::distribution =
0087                        std::uniform_real_distribution<double>(-2_T, 2_T))) ^
0088         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 2,
0089                        bdata::distribution =
0090                            std::uniform_real_distribution<double>(-1_T, 4_T))) ^
0091         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 3,
0092                        bdata::distribution =
0093                            std::uniform_real_distribution<double>(0_T, 10_T))) ^
0094         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 4,
0095                        bdata::distribution =
0096                            std::uniform_real_distribution<double>(-10_m,
0097                                                                   10_m))) ^
0098         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 5,
0099                        bdata::distribution =
0100                            std::uniform_real_distribution<double>(-10_m,
0101                                                                   10_m))) ^
0102         bdata::random((bdata::engine = std::mt19937(), bdata::seed = 6,
0103                        bdata::distribution =
0104                            std::uniform_real_distribution<double>(-10_m,
0105                                                                   10_m))) ^
0106         bdata::xrange(10),
0107     x, y, z, bx, by, bz, index) {
0108   (void)index;
0109 
0110   ConstantBField BField{Vector3{0, 0, 0}};
0111   const Vector3 Btrue(bx, by, bz);
0112   const Vector3 pos(x, y, z);
0113   BField.setField(Vector3{bx, by, bz});
0114 
0115   auto bCache = BField.makeCache(mfContext);
0116 
0117   BOOST_CHECK_EQUAL(Btrue, BField.getField());
0118 
0119   BOOST_CHECK_EQUAL(Btrue, BField.getField(pos, bCache).value());
0120   BOOST_CHECK_EQUAL(Btrue, BField.getField(Vector3(0, 0, 0), bCache).value());
0121   BOOST_CHECK_EQUAL(Btrue, BField.getField(-2 * pos, bCache).value());
0122 }
0123 
0124 BOOST_AUTO_TEST_SUITE_END()
0125 
0126 }  // namespace ActsTests