Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:22

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/tools/floating_point_comparison.hpp>
0011 #include <boost/test/unit_test.hpp>
0012 
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/Definitions/Units.hpp"
0015 #include "Acts/MagneticField/ConstantBField.hpp"
0016 #include "Acts/MagneticField/InterpolatedBFieldMap.hpp"
0017 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0018 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0019 #include "Acts/MagneticField/SolenoidBField.hpp"
0020 
0021 namespace Acts {
0022 namespace Test {
0023 
0024 // Create a test context
0025 MagneticFieldContext mfContext = MagneticFieldContext();
0026 
0027 /// This is the canonical interface that all field implementations
0028 /// need to comply with.
0029 /// This test group is should include ALL field implementations,
0030 /// to make sure they conform to the interface, even if they are
0031 /// not implicitly tested by some of the other tests (e.g. Propagation)
0032 /// The function does not assert any functionality, it just ensures
0033 /// the interface compiles
0034 template <class BField_t>
0035 void testInterfaceConsistency(const BField_t& field) {
0036   using Cache_t = typename BField_t::Cache;
0037   Vector3 pos(0, 0, 0);
0038   Vector3 B;
0039   ActsMatrix<3, 3> gradient;
0040 
0041   // test interface method without cache
0042   field.getField(pos);
0043   field.getFieldGradient(pos, gradient);
0044 
0045   // test interface method with cache
0046   Cache_t cache(mfContext);
0047   field.getField(pos, cache);
0048   field.getFieldGradient(pos, gradient, cache);
0049 }
0050 
0051 BOOST_AUTO_TEST_CASE(TestConstantBFieldInterfaceConsistency) {
0052   ConstantBField field(1, 1, 1);
0053   testInterfaceConsistency(field);
0054 }
0055 
0056 BOOST_AUTO_TEST_CASE(TestSolenoidBFieldInterfaceConsistency) {
0057   SolenoidBField field({100, 1000, 20, 5});
0058   testInterfaceConsistency(field);
0059 }
0060 
0061 BOOST_AUTO_TEST_CASE(TestInterpolatedBFieldMapInterfaceConsistency) {
0062   // define dummy mapper and field cell, we don't need them to do anything
0063   struct DummyFieldCell {
0064     Vector3 getField(const Vector3&) const { return {0, 0, 0}; }
0065     bool isInside(const Vector3&) const { return true; }
0066   };
0067 
0068   struct DummyMapper : DummyFieldCell {
0069     using FieldCell = DummyFieldCell;
0070 
0071     DummyFieldCell getFieldCell(const Vector3&) const {
0072       return DummyFieldCell();
0073     }
0074     std::vector<std::size_t> getNBins() const { return {42}; }
0075     std::vector<double> getMin() const { return {5}; }
0076     std::vector<double> getMax() const { return {15}; }
0077   };
0078 
0079   DummyMapper m;
0080   InterpolatedBFieldMap<DummyMapper>::Config config(std::move(m));
0081   config.scale = 1.;
0082 
0083   // create BField service
0084   InterpolatedBFieldMap<DummyMapper> b(std::move(config));
0085 
0086   testInterfaceConsistency(b);
0087 }
0088 
0089 }  // namespace Test
0090 }  // namespace Acts