ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MagneticFieldInterfaceConsistencyTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MagneticFieldInterfaceConsistencyTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <boost/test/data/test_case.hpp>
12 #include <boost/test/floating_point_comparison.hpp>
13 #include <boost/test/unit_test.hpp>
14 
21 #include "Acts/Utilities/Units.hpp"
22 
23 namespace bdata = boost::unit_test::data;
24 namespace tt = boost::test_tools;
25 
26 namespace Acts {
27 
28 namespace Test {
29 
30 // Create a test context
32 
40 template <class BField_t>
41 void testInterfaceConsistency(const BField_t& field) {
42  using Cache_t = typename BField_t::Cache;
43  Vector3D pos(0, 0, 0);
44  Vector3D B;
45  ActsMatrixD<3, 3> gradient;
46 
47  // test interface method without cache
48  field.getField(pos);
49  field.getFieldGradient(pos, gradient);
50 
51  // test interface method with cache
52  Cache_t cache(mfContext);
53  field.getField(pos, cache);
54  field.getFieldGradient(pos, gradient, cache);
55 }
56 
57 BOOST_AUTO_TEST_CASE(TestConstantBFieldInterfaceConsistency) {
58  ConstantBField field(1, 1, 1);
60 }
61 
62 BOOST_AUTO_TEST_CASE(TestSolenoidBFieldInterfaceConsistency) {
63  SolenoidBField field({100, 1000, 20, 5});
65 }
66 
67 BOOST_AUTO_TEST_CASE(TestInterpolatedBFieldMapInterfaceConsistency) {
68  // define dummy mapper and field cell, we don't need them to do anything
69  struct DummyFieldCell {
70  Vector3D getField(const Vector3D&) const { return {0, 0, 0}; }
71  bool isInside(const Vector3D&) const { return true; }
72  };
73 
74  struct DummyMapper : DummyFieldCell {
75  using FieldCell = DummyFieldCell;
76 
77  DummyFieldCell getFieldCell(const Vector3D&) const {
78  return DummyFieldCell();
79  }
80  std::vector<size_t> getNBins() const { return {42}; }
81  std::vector<double> getMin() const { return {5}; }
82  std::vector<double> getMax() const { return {15}; }
83  };
84 
85  DummyMapper m;
87  config.scale = 1.;
88 
89  // create BField service
90  InterpolatedBFieldMap<DummyMapper> b(std::move(config));
91 
93 }
94 
95 BOOST_AUTO_TEST_CASE(TestSharedBFieldInterfaceConsistency) {
97  std::make_shared<ConstantBField>(Vector3D(1, 1, 1)));
99 }
100 } // namespace Test
101 
102 } // namespace Acts