ECCE @ EIC 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 
14 #include <fstream>
15 
20 #include "Acts/Utilities/Units.hpp"
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 BOOST_AUTO_TEST_CASE(TestSolenoidBField) {
30  // Create a test context
32 
34  cfg.length = 5.8_m;
35  cfg.radius = (2.56 + 2.46) * 0.5 * 0.5_m;
36  cfg.nCoils = 1154;
37  cfg.bMagCenter = 2_T;
39 
40  SolenoidBField::Cache cache(mfContext);
41  CHECK_CLOSE_ABS(bField.getField({0, 0, 0}, cache), Vector3D(0, 0, 2.0_T),
42  1e-6_T);
43 
44  // std::ofstream outf("solenoid.csv");
45  // outf << "x;y;z;B_x;B_y;B_z" << std::endl;
46 
47  double tol = 1e-6;
48  double tol_B = 1e-6_T;
49  size_t steps = 20;
50  for (size_t i = 0; i < steps; i++) {
51  double r = 1.5 * cfg.radius / steps * i;
52  BOOST_TEST_CONTEXT("r=" << r) {
53  Vector3D B1 = bField.getField({r, 0, 0}, cache);
54  Vector3D B2 = bField.getField({-r, 0, 0}, cache);
55  CHECK_SMALL(B1.x(), tol);
56  CHECK_SMALL(B1.y(), tol);
57  BOOST_CHECK_GT(std::abs(B1.z()), tol_B); // greater than zero
58  // check symmetry: at z=0 it should be exactly symmetric
59  CHECK_CLOSE_ABS(B1, B2, tol_B);
60 
61  // at this point in r, go along the length
62  for (size_t j = 0; j <= steps; j++) {
63  // double z = cfg.L/steps * j - (cfg.L/2.);
64  double z = (1.5 * cfg.length / 2.) / steps * j;
65  BOOST_TEST_CONTEXT("z=" << z) {
66  Vector3D B_zp_rp = bField.getField({r, 0, z}, cache);
67  Vector3D B_zn_rp = bField.getField({r, 0, -z}, cache);
68  Vector3D B_zp_rn = bField.getField({-r, 0, z}, cache);
69  Vector3D B_zn_rn = bField.getField({-r, 0, -z}, cache);
70 
71  // outf << r << ";0;" << z << ";" << B_zp_rp.x() << ";" <<
72  // B_zp_rp.y() << ";" << B_zp_rp.z() << std::endl;
73  // if(j>0) {
74  // outf << r << ";0;" << -z << ";" << B_zn_rp.x() << ";" <<
75  // B_zn_rp.y() << ";" << B_zn_rp.z() << std::endl;
76  //}
77  // if(i>0) {
78  // outf << -r << ";0;" << z << ";" << B_zp_rn.x() << ";" <<
79  // B_zp_rn.y() << ";" << B_zp_rn.z() << std::endl;
80  //}
81  // if(i>0 && j>0) {
82  // outf << -r << ";0;" << -z << ";" << B_zn_rn.x() << ";" <<
83  // B_zn_rn.y() << ";" << B_zn_rn.z() << std::endl;
84  //}
85 
86  // non-zero z
87  BOOST_CHECK_GT(std::abs(B_zp_rp.z()), tol_B);
88  BOOST_CHECK_GT(std::abs(B_zn_rp.z()), tol_B);
89  BOOST_CHECK_GT(std::abs(B_zn_rn.z()), tol_B);
90  BOOST_CHECK_GT(std::abs(B_zp_rn.z()), tol_B);
91  if (i > 0) {
92  // z components should be the same for +- r
93  CHECK_CLOSE_ABS(B_zp_rp.z(), B_zp_rn.z(), tol_B);
94  CHECK_CLOSE_ABS(B_zn_rp.z(), B_zn_rn.z(), tol_B);
95  // x components should be exactly opposite
96  CHECK_CLOSE_ABS(B_zp_rp.x(), -B_zp_rn.x(), tol_B);
97  CHECK_CLOSE_ABS(B_zn_rp.x(), -B_zn_rn.x(), tol_B);
98  }
99  if (j > 0) {
100  // z components should be the same for +- z
101  CHECK_CLOSE_ABS(B_zp_rp.z(), B_zn_rp.z(), tol_B);
102  CHECK_CLOSE_ABS(B_zp_rn.z(), B_zn_rn.z(), tol_B);
103  // x components should be exactly opposite
104  CHECK_CLOSE_ABS(B_zp_rp.x(), -B_zn_rp.x(), tol_B);
105  CHECK_CLOSE_ABS(B_zp_rn.x(), -B_zn_rn.x(), tol_B);
106  }
107  }
108  }
109  }
110  }
111  // outf.close();
112 }
113 
114 } // namespace Test
115 } // namespace Acts