22 #include <initializer_list>
34 std::array<size_t, 2> nBinsRZ)>&
36 std::vector<double> rPos, std::vector<double> zPos,
38 double BFieldUnit,
bool firstQuadrant) {
44 rPos.erase(std::unique(rPos.begin(), rPos.end()), rPos.end());
45 zPos.erase(std::unique(zPos.begin(), zPos.end()), zPos.end());
49 size_t nBinsR = rPos.size();
50 size_t nBinsZ = zPos.size();
54 double rMin = rPos[0];
55 double zMin = zPos[0];
56 double rMax = rPos[nBinsR - 1];
57 double zMax = zPos[nBinsZ - 1];
60 double stepZ = std::fabs(zMax - zMin) / (nBinsZ - 1);
61 double stepR = std::fabs(rMax - rMin) / (nBinsR - 1);
65 zMin = -zPos[nBinsZ - 1];
66 nBinsZ =
static_cast<size_t>(2. * nBinsZ - 1);
78 Acts::detail::EquidistantAxis>;
84 std::array<size_t, 2> nIndices = {{rPos.size(), zPos.size()}};
85 Grid_t::index_t indices = {{
i,
j}};
90 size_t n = std::abs(
int(
j) -
int(zPos.size()));
91 Grid_t::index_t indicesFirstQuadrant = {{
i - 1, n}};
93 grid.atLocalBins(indices) =
94 bField.at(localToGlobalBin(indicesFirstQuadrant, nIndices)) *
100 grid.atLocalBins(indices) =
101 bField.at(localToGlobalBin({{
i - 1,
j - 1}}, nIndices)) *
106 grid.setExteriorBins(Acts::Vector2::Zero());
116 auto transformBField = [](
const Acts::Vector2&
field,
118 double r_sin_theta_2 =
pos.x() *
pos.x() +
pos.y() *
pos.y();
119 double cos_phi = 0, sin_phi = 0;
121 double inv_r_sin_theta = 1. / sqrt(r_sin_theta_2);
122 cos_phi =
pos.x() * inv_r_sin_theta;
123 sin_phi =
pos.y() * inv_r_sin_theta;
128 return Acts::Vector3(field.x() * cos_phi, field.x() * sin_phi, field.y());
134 {transformPos, transformBField,
std::move(grid)});
139 Acts::detail::EquidistantAxis>>
141 std::array<size_t, 3> nBinsXYZ)>&
143 std::vector<double> xPos, std::vector<double> yPos,
144 std::vector<double> zPos, std::vector<Acts::Vector3>
bField,
145 double lengthUnit,
double BFieldUnit,
bool firstOctant) {
152 xPos.erase(std::unique(xPos.begin(), xPos.end()), xPos.end());
153 yPos.erase(std::unique(yPos.begin(), yPos.end()), yPos.end());
154 zPos.erase(std::unique(zPos.begin(), zPos.end()), zPos.end());
155 xPos.shrink_to_fit();
156 yPos.shrink_to_fit();
157 zPos.shrink_to_fit();
159 size_t nBinsX = xPos.size();
160 size_t nBinsY = yPos.size();
161 size_t nBinsZ = zPos.size();
166 double xMin = xPos[0];
167 double yMin = yPos[0];
168 double zMin = zPos[0];
170 double xMax = xPos[nBinsX - 1];
171 double yMax = yPos[nBinsY - 1];
172 double zMax = zPos[nBinsZ - 1];
175 double stepZ = std::fabs(zMax - zMin) / (nBinsZ - 1);
176 double stepY = std::fabs(yMax - yMin) / (nBinsY - 1);
177 double stepX = std::fabs(xMax - xMin) / (nBinsX - 1);
184 xMin = -xPos[nBinsX - 1];
185 yMin = -yPos[nBinsY - 1];
186 zMin = -zPos[nBinsZ - 1];
187 nBinsX = 2 * nBinsX - 1;
188 nBinsY = 2 * nBinsY - 1;
189 nBinsZ = 2 * nBinsZ - 1;
191 Acts::detail::EquidistantAxis xAxis(xMin * lengthUnit, xMax * lengthUnit,
193 Acts::detail::EquidistantAxis yAxis(yMin * lengthUnit, yMax * lengthUnit,
195 Acts::detail::EquidistantAxis zAxis(zMin * lengthUnit, zMax * lengthUnit,
201 Acts::detail::EquidistantAxis>;
206 for (
size_t i = 1;
i <= nBinsX; ++
i) {
207 for (
size_t j = 1;
j <= nBinsY; ++
j) {
209 Grid_t::index_t indices = {{
i,
j,
k}};
210 std::array<size_t, 3> nIndices = {
211 {xPos.size(), yPos.size(), zPos.size()}};
216 size_t m = std::abs(
int(
i) - (
int(xPos.size())));
217 size_t n = std::abs(
int(
j) - (
int(yPos.size())));
218 size_t l = std::abs(
int(
k) - (
int(zPos.size())));
219 Grid_t::index_t indicesFirstOctant = {{
m,
n, l}};
221 grid.atLocalBins(indices) =
222 bField.at(localToGlobalBin(indicesFirstOctant, nIndices)) *
229 grid.atLocalBins(indices) =
230 bField.at(localToGlobalBin({{
i - 1,
j - 1,
k - 1}}, nIndices)) *
236 grid.setExteriorBins(Acts::Vector3::Zero());
240 auto transformPos = [](
const Acts::Vector3&
pos) {
return pos; };
244 auto transformBField = [](
const Acts::Vector3&
field,
245 const Acts::Vector3& ) {
return field; };
250 {transformPos, transformBField,
std::move(grid)});
255 Acts::detail::EquidistantAxis>>
257 std::pair<double, double> zlim,
258 std::pair<size_t, size_t>
nbins,
260 double rMin = 0, rMax = 0, zMin = 0, zMax = 0;
261 std::tie(rMin, rMax) = rlim;
262 std::tie(zMin, zMax) = zlim;
267 double stepZ = std::abs(zMax - zMin) / (
nBinsZ - 1);
268 double stepR = std::abs(rMax - rMin) / (nBinsR - 1);
274 Acts::detail::EquidistantAxis rAxis(rMin, rMax, nBinsR);
275 Acts::detail::EquidistantAxis zAxis(zMin, zMax,
nBinsZ);
280 Acts::detail::EquidistantAxis>;
285 auto transformPos = [](
const Acts::Vector3&
pos) {
291 auto transformBField = [](
const Acts::Vector2& bfield,
292 const Acts::Vector3&
pos) {
293 double r_sin_theta_2 =
pos.x() *
pos.x() +
pos.y() *
pos.y();
294 double cos_phi = 0, sin_phi = 0;
296 double inv_r_sin_theta = 1. / sqrt(r_sin_theta_2);
297 cos_phi =
pos.x() * inv_r_sin_theta;
298 sin_phi =
pos.y() * inv_r_sin_theta;
303 return Acts::Vector3(bfield.x() * cos_phi, bfield.x() * sin_phi,
309 for (
size_t i = 0;
i <= nBinsR + 1;
i++) {
310 for (
size_t j = 0;
j <=
nBinsZ + 1;
j++) {
312 if (
i == 0 ||
j == 0 ||
i == nBinsR + 1 ||
j ==
nBinsZ + 1) {
317 Grid_t::point_t lowerLeft = grid.lowerLeftBinEdge(
index);
320 grid.atLocalBins(
index) = B;
328 {transformPos, transformBField,
std::move(grid)});