27 namespace ActsExamples {
31 std::unique_ptr<const Acts::Logger> p_logger) {
42 throw std::invalid_argument(
"Missing tree name");
43 }
else if (config.
fileName.empty()) {
44 throw std::invalid_argument(
"Missing file name");
45 }
else if (config.
bField ==
nullptr) {
46 throw std::invalid_argument(
"Missing interpolated magnetic field");
53 if (outputFile ==
nullptr) {
54 throw std::ios_base::failure(
"Could not open '" + config.
fileName +
"'");
56 TTree* outputTree =
new TTree(config.
treeName.c_str(),
57 config.
treeName.c_str(), 99, outputFile);
58 if (outputTree ==
nullptr) {
59 throw std::bad_alloc();
63 auto minima = config.
bField->getMin();
64 auto maxima = config.
bField->getMax();
65 auto nBins = config.
bField->getNBins();
70 for (
auto m : minima) {
76 for (
auto m : maxima) {
82 for (
auto m : nBins) {
88 if (config.
gridType == GridType::xyz) {
89 ACTS_INFO(
"Map will be written out in cartesian coordinates (x,y,z).");
92 double minX = 0., minY = 0., minZ = 0.;
93 double maxX = 0., maxY = 0.,
maxZ = 0.;
94 size_t nBinsX = 0, nBinsY = 0,
nBinsZ = 0;
98 outputTree->Branch(
"x", &x);
100 outputTree->Branch(
"y", &y);
102 outputTree->Branch(
"z", &z);
106 outputTree->Branch(
"Bx", &Bx);
108 outputTree->Branch(
"By", &By);
110 outputTree->Branch(
"Bz", &Bz);
114 ACTS_INFO(
"User defined ranges handed over.");
125 nBinsX = config.
rBins;
126 nBinsY = config.
rBins;
130 ACTS_INFO(
"No user defined ranges handed over - write out whole map.");
134 if (minima.size() == 3 && maxima.size() == 3) {
143 nBinsX = nBins.at(0);
144 nBinsY = nBins.at(1);
147 }
else if (minima.size() == 2 && maxima.size() == 2) {
148 minX = -maxima.at(0);
149 minY = -maxima.at(0);
156 nBinsX = nBins.at(0);
157 nBinsY = nBins.at(0);
160 throw std::invalid_argument(
161 "BField has wrong dimension. The dimension needs to be "
162 "either 2 (r,z,Br,Bz) or 3(x,y,z,Bx,By,Bz) in order to be "
163 "written out by this writer.");
171 double stepX = (maxX - minX) / (nBinsX - 1);
172 double stepY = (maxY - minY) / (nBinsY - 1);
175 for (
size_t i = 0;
i < nBinsX;
i++) {
176 double raw_x = minX +
i * stepX;
177 for (
size_t j = 0;
j < nBinsY;
j++) {
178 double raw_y = minY +
j * stepY;
180 double raw_z = minZ +
k * stepZ;
196 ACTS_INFO(
"Map will be written out in cylinder coordinates (r,z).");
200 outputTree->Branch(
"r", &r);
202 outputTree->Branch(
"z", &z);
205 outputTree->Branch(
"Br", &Br);
207 outputTree->Branch(
"Bz", &Bz);
210 double minZ = 0,
maxZ = 0;
214 ACTS_INFO(
"User defined ranges handed over.");
222 nBinsR = config.
rBins;
225 ACTS_INFO(
"No user defined ranges handed over - printing out whole map.");
227 if (minima.size() == 3 && maxima.size() == 3) {
234 nBinsR = nBins.at(0);
237 }
else if (minima.size() == 2 || maxima.size() == 2) {
244 nBinsR = nBins.at(0);
248 throw std::invalid_argument(
249 "BField has wrong dimension. The dimension needs to be "
250 "either 2 (r,z,Br,Bz) or 3(x,y,z,Bx,By,Bz) in order to be "
251 "written out by this writer.");
258 double stepR = (
maxR -
minR) / (nBinsR - 1);
262 double raw_z = minZ +
k * stepZ;
264 double raw_r = minR +
j * stepR;
266 ACTS_VERBOSE(
"Requesting position: " << position.transpose());
267 auto bField = config.
bField->getFieldUnchecked(position);