ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SolenoidBField.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SolenoidBField.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 
11 
12 #include <boost/math/special_functions/ellint_1.hpp>
13 #include <boost/math/special_functions/ellint_2.hpp>
14 
15 Acts::SolenoidBField::SolenoidBField(Config config) : m_cfg(std::move(config)) {
18  // we need to scale so we reproduce the expected B field strength
19  // at the center of the solenoid
20  Vector2D field = multiCoilField({0, 0}, 1.); // scale = 1
21  m_scale = m_cfg.bMagCenter / field.norm();
22 }
23 
25  using VectorHelpers::perp;
26  Vector2D rzPos(perp(position), position.z());
27  Vector2D rzField = multiCoilField(rzPos, m_scale);
28  Vector3D xyzField(0, 0, rzField[1]);
29 
30  if (rzPos[0] != 0.) {
31  // add xy field component, radially symmetric
32  Vector3D rDir = Vector3D(position.x(), position.y(), 0).normalized();
33  xyzField += rDir * rzField[0];
34  }
35 
36  return xyzField;
37 }
38 
40  Cache& /*cache*/) const {
41  return getField(position);
42 }
43 
45  return multiCoilField(position, m_scale);
46 }
47 
49  const Vector3D& position, ActsMatrixD<3, 3>& /*derivative*/) const {
50  return getField(position);
51 }
52 
54  const Vector3D& position, ActsMatrixD<3, 3>& /*derivative*/,
55  Cache& /*cache*/) const {
56  return getField(position);
57 }
58 
60  double scale) const {
61  // iterate over all coils
62  Vector2D resultField(0, 0);
63  for (size_t coil = 0; coil < m_cfg.nCoils; coil++) {
64  Vector2D shiftedPos =
65  Vector2D(pos[0], pos[1] + m_cfg.length * 0.5 - m_dz * (coil + 0.5));
66  resultField += singleCoilField(shiftedPos, scale);
67  }
68 
69  return resultField;
70 }
71 
73  double scale) const {
74  return {B_r(pos, scale), B_z(pos, scale)};
75 }
76 
77 double Acts::SolenoidBField::B_r(const Vector2D& pos, double scale) const {
78  // _
79  // 2 / pi / 2 2 2 - 1 / 2
80  // E (k ) = | ( 1 - k sin {theta} ) dtheta
81  // 1 _/ 0
82  using boost::math::ellint_1;
83  // _ ____________________
84  // 2 / pi / 2| / 2 2
85  // E (k ) = | |/ 1 - k sin {theta} dtheta
86  // 2 _/ 0
87  using boost::math::ellint_2;
88 
89  double r = std::abs(pos[0]);
90  double z = pos[1];
91 
92  if (r == 0) {
93  return 0.;
94  }
95 
96  // _ _
97  // mu I | / 2 \ |
98  // 0 kz | |2 - k | 2 2 |
99  // B (r, z) = ----- ------ | |-------|E (k ) - E (k ) |
100  // r 4pi ___ | | 2| 2 1 |
101  // | / 3 |_ \2 - 2k / _|
102  // |/ Rr
103  double k_2 = k2(r, z);
104  double k = std::sqrt(k_2);
105  double constant =
106  scale * k * z / (4 * M_PI * std::sqrt(m_cfg.radius * r * r * r));
107 
108  double B = (2. - k_2) / (2. - 2. * k_2) * ellint_2(k_2) - ellint_1(k_2);
109 
110  // pos[0] is still signed!
111  return r / pos[0] * constant * B;
112 }
113 
114 double Acts::SolenoidBField::B_z(const Vector2D& pos, double scale) const {
115  // _
116  // 2 / pi / 2 2 2 - 1 / 2
117  // E (k ) = | ( 1 - k sin {theta} ) dtheta
118  // 1 _/ 0
119  using boost::math::ellint_1;
120  // _ ____________________
121  // 2 / pi / 2| / 2 2
122  // E (k ) = | |/ 1 - k sin {theta} dtheta
123  // 2 _/ 0
124  using boost::math::ellint_2;
125 
126  double r = std::abs(pos[0]);
127  double z = pos[1];
128 
129  // _ _
130  // mu I | / 2 \ |
131  // 0 k | | (R + r)k - 2r | 2 2 |
132  // B (r,z) = ----- ---- | | -------------- | E (k ) + E (k ) |
133  // z 4pi __ | | 2 | 2 1 |
134  // |/Rr |_ \ 2r(1 - k ) / _|
135 
136  if (r == 0) {
137  double res = scale / 2. * m_R2 / (std::sqrt(m_R2 + z * z) * (m_R2 + z * z));
138  return res;
139  }
140 
141  double k_2 = k2(r, z);
142  double k = std::sqrt(k_2);
143  double constant = scale * k / (4 * M_PI * std::sqrt(m_cfg.radius * r));
144  double B = ((m_cfg.radius + r) * k_2 - 2. * r) / (2. * r * (1. - k_2)) *
145  ellint_2(k_2) +
146  ellint_1(k_2);
147 
148  return constant * B;
149 }
150 
151 double Acts::SolenoidBField::k2(double r, double z) const {
152  // 2 4Rr
153  // k = ---------------
154  // 2 2
155  // (R + r) + z
156  return 4 * m_cfg.radius * r /
157  ((m_cfg.radius + r) * (m_cfg.radius + r) + z * z);
158 }