Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConstantBFieldTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ConstantBFieldTests.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/data/test_case.hpp>
12 #include <boost/test/unit_test.hpp>
13 
19 
20 #include <utility>
21 
22 namespace bdata = boost::unit_test::data;
23 namespace tt = boost::test_tools;
24 using namespace Acts::UnitLiterals;
25 
26 namespace Acts {
27 namespace Test {
28 
29 // Create a test context
31 
39 BOOST_DATA_TEST_CASE(ConstantBField_components,
40  bdata::random(-2_T, 2_T) ^ bdata::random(-1_T, 4_T) ^
41  bdata::random(0_T, 10_T) ^ bdata::random(-10_m, 10_m) ^
42  bdata::random(-10_m, 10_m) ^
43  bdata::random(-10_m, 10_m) ^ bdata::xrange(10),
44  x, y, z, bx, by, bz, index) {
45  (void)index;
46  const Vector3 Btrue(bx, by, bz);
47  const Vector3 pos(x, y, z);
48  const ConstantBField BField(Btrue);
49 
50  auto bCache = BField.makeCache(mfContext);
51 
52  BOOST_CHECK_EQUAL(Btrue, BField.getField());
53 
54  BOOST_CHECK_EQUAL(Btrue, BField.getField(pos, bCache).value());
55  BOOST_CHECK_EQUAL(Btrue, BField.getField(Vector3(0, 0, 0), bCache).value());
56  BOOST_CHECK_EQUAL(Btrue, BField.getField(-2 * pos, bCache).value());
57 }
58 
66 BOOST_DATA_TEST_CASE(ConstantBField_update,
67  bdata::random(-2_T, 2_T) ^ bdata::random(-1_T, 4_T) ^
68  bdata::random(0_T, 10_T) ^ bdata::random(-10_m, 10_m) ^
69  bdata::random(-10_m, 10_m) ^
70  bdata::random(-10_m, 10_m) ^ bdata::xrange(10),
71  x, y, z, bx, by, bz, index) {
72  (void)index;
73 
74  ConstantBField BField{Vector3{0, 0, 0}};
75  const Vector3 Btrue(bx, by, bz);
76  const Vector3 pos(x, y, z);
77  BField.setField(Vector3{bx, by, bz});
78 
80 
81  BOOST_CHECK_EQUAL(Btrue, BField.getField());
82 
83  BOOST_CHECK_EQUAL(Btrue, BField.getField(pos, bCache).value());
84  BOOST_CHECK_EQUAL(Btrue, BField.getField(Vector3(0, 0, 0), bCache).value());
85  BOOST_CHECK_EQUAL(Btrue, BField.getField(-2 * pos, bCache).value());
86 }
87 
88 } // namespace Test
89 } // namespace Acts