Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:42

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