ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InterpolatedBFieldMapTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InterpolatedBFieldMapTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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/unit_test.hpp>
12 
19 
20 namespace tt = boost::test_tools;
21 
23 
24 namespace Acts {
25 
26 namespace Test {
27 
28 // Create a test context
30 
31 BOOST_AUTO_TEST_CASE(InterpolatedBFieldMap_rz) {
32  // definition of dummy BField
33  struct BField {
34  static Vector3D value(const std::array<double, 2>& rz) {
35  double r = rz.at(0);
36  double z = rz.at(1);
37  // linear in r and z so interpolation should be exact
38  return Vector3D(r * z, 3 * r, -2 * z);
39  }
40  };
41 
42  // map (x,y,z) -> (r,z)
43  auto transformPos = [](const Vector3D& pos) {
44  return ActsVectorD<2>(perp(pos), pos.z());
45  };
46 
47  // map (Bx,By,Bz) -> (Bx,By,Bz)
48  auto transformBField = [](const Vector3D& field, const Vector3D&) {
49  return field;
50  };
51 
52  // magnetic field known on grid in (r,z)
53  detail::EquidistantAxis r(0.0, 4.0, 4u);
54  detail::EquidistantAxis z(-5, 5, 5u);
55 
56  using Grid_t =
58  using Mapper_t = InterpolatedBFieldMapper<Grid_t>;
59  using BField_t = InterpolatedBFieldMap<Mapper_t>;
60 
61  Grid_t g(std::make_tuple(std::move(r), std::move(z)));
62 
63  // set grid values
64  for (size_t i = 1; i <= g.numLocalBins().at(0) + 1; ++i) {
65  for (size_t j = 1; j <= g.numLocalBins().at(1) + 1; ++j) {
66  Grid_t::index_t indices = {{i, j}};
67  const auto& llCorner = g.lowerLeftBinEdge(indices);
68  g.atLocalBins(indices) = BField::value(llCorner);
69  }
70  }
71 
72  // create field mapping
73  Mapper_t mapper(transformPos, transformBField, std::move(g));
74  BField_t::Config config(std::move(mapper));
75  config.scale = 1.;
76 
77  // create BField service
78  BField_t b(std::move(config));
79 
80  Vector3D pos;
81  pos << -3, 2.5, 1.7;
82  // test the cache interface
83  BField_t::Cache bCache(mfContext);
84  CHECK_CLOSE_REL(b.getField(pos, bCache),
85  BField::value({{perp(pos), pos.z()}}), 1e-6);
86 
87  CHECK_CLOSE_REL(b.getField(pos, bCache),
88  BField::value({{perp(pos), pos.z()}}), 1e-6);
89  auto& c = *bCache.fieldCell;
90  BOOST_CHECK(c.isInside(pos));
91  CHECK_CLOSE_REL(c.getField(pos), BField::value({{perp(pos), pos.z()}}), 1e-6);
92 
93  pos << 0, 1.5, -2.5;
94  BField_t::Cache bCache2(mfContext);
95  CHECK_CLOSE_REL(b.getField(pos, bCache2),
96  BField::value({{perp(pos), pos.z()}}), 1e-6);
97  c = *bCache2.fieldCell;
98  BOOST_CHECK(c.isInside(pos));
99  CHECK_CLOSE_REL(c.getField(pos), BField::value({{perp(pos), pos.z()}}), 1e-6);
100 
101  pos << 2, 3, -4;
102  BField_t::Cache bCache3(mfContext);
103  CHECK_CLOSE_REL(b.getField(pos, bCache3),
104  BField::value({{perp(pos), pos.z()}}), 1e-6);
105  c = *bCache3.fieldCell;
106  BOOST_CHECK(c.isInside(pos));
107  CHECK_CLOSE_REL(c.getField(pos), BField::value({{perp(pos), pos.z()}}), 1e-6);
108 
109  // some field cell tests
110  BOOST_CHECK(c.isInside((pos << 3, 2, -3.7).finished()));
111  BOOST_CHECK(c.isInside((pos << -2, 3, -4.7).finished()));
112  BOOST_CHECK(not c.isInside((pos << -2, 3, 4.7).finished()));
113  BOOST_CHECK(not c.isInside((pos << 0, 2, -4.7).finished()));
114  BOOST_CHECK(not c.isInside((pos << 5, 2, 14.).finished()));
115 }
116 } // namespace Test
117 
118 } // namespace Acts