24 #include <dfe/dfe_io_dsv.hpp>
26 namespace ActsExamples {
27 template <CsvBFieldWriter::CoordinateType Coord,
bool Gr
id>
33 using ConfigType = std::decay_t<decltype(config)>;
42 std::vector<std::string> fields;
44 if constexpr (Coord == CoordinateType::XYZ) {
45 fields = {
"x",
"y",
"z",
"Bx",
"By",
"Bz"};
47 fields = {
"r",
"z",
"Br",
"Bz"};
57 std::array<std::size_t, ConfigType::NDims>
bins{};
63 if (
bins.size() != ConfigType::NDims ||
64 field.getMin().size() != ConfigType::NDims ||
65 field.getMax().size() != ConfigType::NDims) {
66 throw std::invalid_argument(
"Incorrect input B-field dimensionality.");
72 for (std::size_t
i = 0;
i < ConfigType::NDims; ++
i) {
75 bins[
i] = field.getNBins()[
i];
76 min[
i] = field.getMin()[
i];
77 max[
i] = field.getMax()[
i];
96 for (std::size_t
i = 0;
i < ConfigType::NDims; ++
i) {
106 for (std::size_t
i = 0;
i < ConfigType::NDims; ++
i) {
107 delta[
i] = (max[
i] - min[
i]) / (
bins[
i] - 1);
113 typename FieldType::Cache cache = field.makeCache(mctx);
118 if constexpr (Coord == CoordinateType::XYZ) {
120 <<
" x " <<
bins[2] <<
" to file "
128 for (std::size_t
x = 0;
x < bins[0]; ++
x) {
129 for (std::size_t
y = 0;
y < bins[1]; ++
y) {
130 for (std::size_t
z = 0;
z < bins[2]; ++
z) {
134 z * delta[2] + min[2]};
138 dynamic_cast<const Acts::InterpolatedMagneticField*>(
143 bField = fieldMap->getFieldUnchecked(pos);
153 throw std::runtime_error(
"B-field returned a non-extant value!");
167 std::size_t
idx = (
x * bins[1] * bins[2]) + (
y * bins[2]) +
z + 1;
169 if (idx % 10000 == 0 || idx == total_items) {
170 ACTS_VERBOSE(
"Wrote " << idx <<
" out of " << total_items
171 <<
" items (" << std::setprecision(3)
172 << ((100.
f * idx) / total_items) <<
"%).");
182 std::size_t total_items =
bins[0] *
bins[1];
187 for (std::size_t
r = 0;
r < bins[0]; ++
r) {
188 for (std::size_t
z = 0;
z < bins[1]; ++
z) {
195 dynamic_cast<const Acts::InterpolatedMagneticField*>(&field)) {
199 bField = fieldMap->getFieldUnchecked(pos);
210 throw std::runtime_error(
"B-field returned a non-extant value!");
221 std::size_t
idx = (
r * bins[1]) +
z + 1;
223 if (idx % 10000 == 0 || idx == total_items) {
224 ACTS_VERBOSE(
"Wrote " << idx <<
" out of " << total_items
225 <<
" items (" << std::setprecision(3)
226 << ((100.
f * idx) / total_items) <<
"%).");
238 template void CsvBFieldWriter::run<CsvBFieldWriter::CoordinateType::XYZ, true>(
240 template void CsvBFieldWriter::run<CsvBFieldWriter::CoordinateType::RZ, true>(
242 template void CsvBFieldWriter::run<CsvBFieldWriter::CoordinateType::XYZ, false>(
244 template void CsvBFieldWriter::run<CsvBFieldWriter::CoordinateType::RZ, false>(