19 #include <boost/optional.hpp>
35 template <
typename bfield_t>
49 std::shared_ptr<const bfield_t>
bField =
nullptr;
56 boost::optional<std::array<double, 2>>
rBounds;
60 boost::optional<std::array<double, 2>>
zBounds;
77 std::unique_ptr<const Acts::Logger> p_logger =
88 throw std::invalid_argument(
"Missing tree name");
90 throw std::invalid_argument(
"Missing file name");
92 throw std::invalid_argument(
"Missing interpolated magnetic field");
99 throw std::ios_base::failure(
"Could not open '" + cfg.
fileName);
104 throw std::bad_alloc();
108 outputTree->Branch(
"z", &
z);
112 outputTree->Branch(
"Bz", &
Bz);
115 auto mapper = cfg.
bField->getMapper();
118 auto minima = mapper.getMin();
119 auto maxima = mapper.getMax();
120 auto nBins = mapper.getNBins();
122 if (cfg.
gridType == GridType::xyz) {
123 ACTS_INFO(
"Map will be written out in cartesian coordinates (x,y,z).");
126 double stepX = 0., stepY = 0., stepZ = 0.;
127 double minX = 0.,
minY = 0., minZ = 0.;
128 double maxX = 0.,
maxY = 0.,
maxZ = 0.;
129 size_t nBinsX = 0, nBinsY = 0,
nBinsZ = 0;
133 outputTree->Branch(
"x", &x);
135 outputTree->Branch(
"y", &y);
138 outputTree->Branch(
"Bx", &Bx);
140 outputTree->Branch(
"By", &By);
144 ACTS_INFO(
"User defined ranges handed over.");
161 "No user defined ranges handed over - printing out whole map.");
164 if (minima.size() == 3 && maxima.size() == 3) {
173 nBinsX = nBins.at(0);
174 nBinsY = nBins.at(1);
177 }
else if (minima.size() == 2 && maxima.size() == 2) {
178 minX = -maxima.at(0);
179 minY = -maxima.at(0);
186 nBinsX = nBins.at(0);
187 nBinsY = nBins.at(0);
190 std::ostringstream errorMsg;
192 <<
"BField has wrong dimension. The dimension needs to be "
193 "either 2 (r,z,Br,Bz) or 3(x,y,z,Bx,By,Bz) in order to be "
194 "written out by this writer.";
195 throw std::invalid_argument(errorMsg.str());
199 stepX = fabs(minX - maxX) / nBinsX;
203 for (
size_t i = 0; i <= nBinsX; i++) {
204 double raw_x = minX + i * stepX;
205 for (
size_t j = 0; j <= nBinsY; j++) {
206 double raw_y =
minY + j * stepY;
208 double raw_z = minZ +
k * stepZ;
210 if (cfg.
bField->isInside(position)) {
225 ACTS_INFO(
"Map will be written out in cylinder coordinates (r,z).");
228 outputTree->Branch(
"r", &r);
231 outputTree->Branch(
"Br", &Br);
233 double minR = 0, maxR = 0;
234 double minZ = 0,
maxZ = 0;
236 double stepR = 0, stepZ = 0;
239 ACTS_INFO(
"User defined ranges handed over.");
252 "No user defined ranges handed over - printing out whole map.");
254 if (minima.size() == 3 && maxima.size() == 3) {
261 nBinsR = nBins.at(0);
265 }
else if (minima.size() == 2 || maxima.size() == 2) {
272 nBinsR = nBins.at(0);
277 std::ostringstream errorMsg;
279 <<
"BField has wrong dimension. The dimension needs to be "
280 "either 2 (r,z,Br,Bz) or 3(x,y,z,Bx,By,Bz) in order to be "
281 "written out by this writer.";
282 throw std::invalid_argument(errorMsg.str());
286 stepR = fabs(minR - maxR) /
nBinsR;
288 double stepPhi = (2 *
M_PI) / nBinsPhi;
290 for (
size_t i = 0; i < nBinsPhi; i++) {
291 double phi = minPhi + i * stepPhi;
293 double raw_z = minZ +
k * stepZ;
294 for (
size_t j = 0; j <
nBinsR; j++) {
295 double raw_r = minR + j * stepR;
297 if (cfg.
bField->isInside(position)) {