28 #include <boost/optional.hpp>
30 namespace ActsExamples {
36 template <
typename bfield_t>
50 std::shared_ptr<const bfield_t>
bField =
nullptr;
57 boost::optional<std::array<double, 2>>
rBounds;
61 boost::optional<std::array<double, 2>>
zBounds;
78 std::unique_ptr<const Acts::Logger> p_logger =
89 throw std::invalid_argument(
"Missing tree name");
91 throw std::invalid_argument(
"Missing file name");
93 throw std::invalid_argument(
"Missing interpolated magnetic field");
100 throw std::ios_base::failure(
"Could not open '" + cfg.
fileName);
105 throw std::bad_alloc();
109 outputTree->Branch(
"z", &
z);
113 outputTree->Branch(
"Bz", &
Bz);
116 auto mapper = cfg.
bField->getMapper();
119 auto minima = mapper.getMin();
120 auto maxima = mapper.getMax();
121 auto nBins = mapper.getNBins();
123 if (cfg.
gridType == GridType::xyz) {
124 ACTS_INFO(
"Map will be written out in cartesian coordinates (x,y,z).");
127 double stepX = 0., stepY = 0., stepZ = 0.;
128 double minX = 0., minY = 0., minZ = 0.;
129 double maxX = 0., maxY = 0., maxZ = 0.;
130 size_t nBinsX = 0, nBinsY = 0,
nBinsZ = 0;
134 outputTree->Branch(
"x", &x);
136 outputTree->Branch(
"y", &y);
139 outputTree->Branch(
"Bx", &Bx);
141 outputTree->Branch(
"By", &By);
145 ACTS_INFO(
"User defined ranges handed over.");
162 "No user defined ranges handed over - printing out whole map.");
165 if (minima.size() == 3 && maxima.size() == 3) {
174 nBinsX = nBins.at(0);
175 nBinsY = nBins.at(1);
178 }
else if (minima.size() == 2 && maxima.size() == 2) {
179 minX = -maxima.at(0);
180 minY = -maxima.at(0);
187 nBinsX = nBins.at(0);
188 nBinsY = nBins.at(0);
191 std::ostringstream errorMsg;
193 <<
"BField has wrong dimension. The dimension needs to be "
194 "either 2 (r,z,Br,Bz) or 3(x,y,z,Bx,By,Bz) in order to be "
195 "written out by this writer.";
196 throw std::invalid_argument(errorMsg.str());
200 stepX = fabs(minX - maxX) / nBinsX;
201 stepY = fabs(minY - maxY) / nBinsY;
202 stepZ = fabs(minZ - maxZ) /
nBinsZ;
204 for (
size_t i = 0; i <= nBinsX; i++) {
205 double raw_x = minX + i * stepX;
206 for (
size_t j = 0; j <= nBinsY; j++) {
207 double raw_y = minY + j * stepY;
209 double raw_z = minZ +
k * stepZ;
211 if (cfg.
bField->isInside(position)) {
226 ACTS_INFO(
"Map will be written out in cylinder coordinates (r,z).");
229 outputTree->Branch(
"r", &r);
232 outputTree->Branch(
"Br", &Br);
234 double minR = 0, maxR = 0;
235 double minZ = 0, maxZ = 0;
237 double stepR = 0, stepZ = 0;
240 ACTS_INFO(
"User defined ranges handed over.");
253 "No user defined ranges handed over - printing out whole map.");
255 if (minima.size() == 3 && maxima.size() == 3) {
262 nBinsR = nBins.at(0);
266 }
else if (minima.size() == 2 || maxima.size() == 2) {
273 nBinsR = nBins.at(0);
278 std::ostringstream errorMsg;
280 <<
"BField has wrong dimension. The dimension needs to be "
281 "either 2 (r,z,Br,Bz) or 3(x,y,z,Bx,By,Bz) in order to be "
282 "written out by this writer.";
283 throw std::invalid_argument(errorMsg.str());
287 stepR = fabs(minR - maxR) /
nBinsR;
288 stepZ = fabs(minZ - maxZ) /
nBinsZ;
289 double stepPhi = (2 *
M_PI) / nBinsPhi;
291 for (
size_t i = 0; i < nBinsPhi; i++) {
292 double phi = minPhi + i * stepPhi;
294 double raw_z = minZ +
k * stepZ;
295 for (
size_t j = 0; j <
nBinsR; j++) {
296 double raw_r = minR + j * stepR;
298 if (cfg.
bField->isInside(position)) {