Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SolenoidBFieldTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SolenoidBFieldTests.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 
20 
21 #include <cstddef>
22 #include <fstream>
23 
24 namespace bdata = boost::unit_test::data;
25 namespace tt = boost::test_tools;
26 using namespace Acts::UnitLiterals;
27 
28 namespace Acts {
29 namespace Test {
30 
31 BOOST_AUTO_TEST_CASE(TestSolenoidBField) {
32  // Create a test context
34 
36  cfg.length = 5.8_m;
37  cfg.radius = (2.56 + 2.46) * 0.5 * 0.5_m;
38  cfg.nCoils = 1154;
39  cfg.bMagCenter = 2_T;
41 
42  auto cache = bField.makeCache(mfContext);
43  CHECK_CLOSE_ABS(bField.getField({0, 0, 0}, cache).value(),
44  Vector3(0, 0, 2.0_T), 1e-6_T);
45 
46  // std::ofstream outf("solenoid.csv");
47  // outf << "x;y;z;B_x;B_y;B_z" << std::endl;
48 
49  double tol = 1e-6;
50  double tol_B = 1e-6_T;
51  size_t steps = 20;
52  for (size_t i = 0; i < steps; i++) {
53  double r = 1.5 * cfg.radius / steps * i;
54  BOOST_TEST_CONTEXT("r=" << r) {
55  Vector3 B1 = bField.getField({r, 0, 0}, cache).value();
56  Vector3 B2 = bField.getField({-r, 0, 0}, cache).value();
57  CHECK_SMALL(B1.x(), tol);
58  CHECK_SMALL(B1.y(), tol);
59  BOOST_CHECK_GT(std::abs(B1.z()), tol_B); // greater than zero
60  // check symmetry: at z=0 it should be exactly symmetric
61  CHECK_CLOSE_ABS(B1, B2, tol_B);
62 
63  // at this point in r, go along the length
64  for (size_t j = 0; j <= steps; j++) {
65  // double z = cfg.L/steps * j - (cfg.L/2.);
66  double z = (1.5 * cfg.length / 2.) / steps * j;
67  BOOST_TEST_CONTEXT("z=" << z) {
68  Vector3 B_zp_rp = bField.getField({r, 0, z}, cache).value();
69  Vector3 B_zn_rp = bField.getField({r, 0, -z}, cache).value();
70  Vector3 B_zp_rn = bField.getField({-r, 0, z}, cache).value();
71  Vector3 B_zn_rn = bField.getField({-r, 0, -z}, cache).value();
72 
73  // outf << r << ";0;" << z << ";" << B_zp_rp.x() << ";" <<
74  // B_zp_rp.y() << ";" << B_zp_rp.z() << std::endl;
75  // if(j>0) {
76  // outf << r << ";0;" << -z << ";" << B_zn_rp.x() << ";" <<
77  // B_zn_rp.y() << ";" << B_zn_rp.z() << std::endl;
78  //}
79  // if(i>0) {
80  // outf << -r << ";0;" << z << ";" << B_zp_rn.x() << ";" <<
81  // B_zp_rn.y() << ";" << B_zp_rn.z() << std::endl;
82  //}
83  // if(i>0 && j>0) {
84  // outf << -r << ";0;" << -z << ";" << B_zn_rn.x() << ";" <<
85  // B_zn_rn.y() << ";" << B_zn_rn.z() << std::endl;
86  //}
87 
88  // non-zero z
89  BOOST_CHECK_GT(std::abs(B_zp_rp.z()), tol_B);
90  BOOST_CHECK_GT(std::abs(B_zn_rp.z()), tol_B);
91  BOOST_CHECK_GT(std::abs(B_zn_rn.z()), tol_B);
92  BOOST_CHECK_GT(std::abs(B_zp_rn.z()), tol_B);
93  if (i > 0) {
94  // z components should be the same for +- r
95  CHECK_CLOSE_ABS(B_zp_rp.z(), B_zp_rn.z(), tol_B);
96  CHECK_CLOSE_ABS(B_zn_rp.z(), B_zn_rn.z(), tol_B);
97  // x components should be exactly opposite
98  CHECK_CLOSE_ABS(B_zp_rp.x(), -B_zp_rn.x(), tol_B);
99  CHECK_CLOSE_ABS(B_zn_rp.x(), -B_zn_rn.x(), tol_B);
100  }
101  if (j > 0) {
102  // z components should be the same for +- z
103  CHECK_CLOSE_ABS(B_zp_rp.z(), B_zn_rp.z(), tol_B);
104  CHECK_CLOSE_ABS(B_zp_rn.z(), B_zn_rn.z(), tol_B);
105  // x components should be exactly opposite
106  CHECK_CLOSE_ABS(B_zp_rp.x(), -B_zn_rp.x(), tol_B);
107  CHECK_CLOSE_ABS(B_zp_rn.x(), -B_zn_rn.x(), tol_B);
108  }
109  }
110  }
111  }
112  }
113  // outf.close();
114 }
115 
116 } // namespace Test
117 } // namespace Acts