11 #include <boost/program_options.hpp>
24 namespace po = boost::program_options;
45 opt.add_options()(
"bf-map", po::value<std::string>()->default_value(
""),
46 "Set this string to point to the bfield source file."
47 "That can either be a '.txt', a '.csv' or a '.root' file. "
48 "Omit for a constant magnetic field.")(
49 "bf-name", po::value<std::string>()->default_value(
"bField"),
50 "In case your field map file is given in root format, please specify "
52 "name of the TTree.")(
53 "bf-gridpoints", po::value<size_t>()->default_value(100000),
54 "Estimate of number of grid points, "
55 "needed for allocation, only for txt and csv files.")(
56 "bf-lscalor", po::value<double>()->default_value(1.),
57 "The default unit for the grid "
58 "points is mm. In case the grid points of your field map has another "
59 "unit, please set the scalor to mm.")(
60 "bf-bscalor", po::value<double>()->default_value(1.),
61 "The default unit for the magnetic field values is Tesla. In case the "
62 "grid points of your field map has another unit, please set the "
65 "bf-rz", po::value<bool>()->default_value(
false),
66 "Please set this flag to true, if your grid points and your "
67 "magnetic field values are given in 'rz'. The default is 'xyz'.")(
68 "bf-foctant", po::value<bool>()->default_value(
false),
69 "Please set this flag to true, if your field map is only given for the "
70 "first octant/quadrant and should be symmetrically created for all "
72 "octants/quadrants.")(
74 po::value<read_range>()->multitoken()->default_value({0., 0., 0.}),
75 "In case no magnetic field map is handed over. A constant magnetic "
76 "field will be created automatically. The values can be set with this "
77 "options. Please hand over the coordinates in cartesian coordinates: "
78 "{Bx,By,Bz} in Tesla.")(
79 "bf-context-scalable", po::value<bool>()->default_value(
false),
80 "This is for testing the event dependent magnetic field scaling.");
85 std::string bfieldmap =
"constfield";
87 enum BFieldMapType { constant = 0, root = 1, text = 2 };
89 std::shared_ptr<InterpolatedBFieldMap2D> map2D =
nullptr;
90 std::shared_ptr<InterpolatedBFieldMap3D> map3D =
nullptr;
91 std::shared_ptr<Acts::ConstantBField> mapConst =
nullptr;
92 std::shared_ptr<FW::BField::ScalableBField> mapScale =
nullptr;
94 int bfieldmaptype = constant;
95 if (vm.count(
"bf-map") && vm[
"bf-map"].template as<std::string>() !=
"") {
96 bfieldmap = vm[
"bf-map"].template as<std::string>();
97 std::cout <<
"- read in magnetic field map: "
98 << vm[
"bf-map"].template as<std::string>() << std::endl;
99 if (bfieldmap.find(
".root") != std::string::npos) {
100 std::cout <<
"- root format for magnetic field detected" << std::endl;
101 bfieldmaptype = root;
102 }
else if (bfieldmap.find(
".txt") != std::string::npos ||
103 bfieldmap.find(
".csv") != std::string::npos) {
104 std::cout <<
"- txt format for magnetic field detected" << std::endl;
105 bfieldmaptype = text;
107 std::cout <<
"- magnetic field format could not be detected";
108 std::cout <<
" use '.root', '.txt', or '.csv'." << std::endl;
109 throw std::runtime_error(
"Invalid BField options");
112 if (bfieldmaptype == text && vm.count(
"bf-gridpoints")) {
113 std::cout <<
"- number of points set to: "
114 << vm[
"bf-gridpoints"].template as<size_t>() << std::endl;
117 if (bfieldmaptype != constant && vm.count(
"bf-lscalor")) {
118 lscalor = vm[
"bf-lscalor"].template as<double>();
119 std::cout <<
"- length scalor to mm set to: " << lscalor << std::endl;
122 if (vm.count(
"bf-bscalor")) {
123 bscalor = vm[
"bf-bscalor"].template as<double>();
124 std::cout <<
"- BField (scalor to/in) Tesla set to: " << bscalor
127 if (bfieldmaptype != constant && vm[
"bf-rz"].
template as<bool>())
128 std::cout <<
"- BField map is given in 'rz' coordiantes." << std::endl;
129 else if (bfieldmaptype != constant)
130 std::cout <<
"- BField map is given in 'xyz' coordiantes." << std::endl;
132 if (bfieldmaptype != constant && vm[
"bf-foctant"].
template as<bool>()) {
134 <<
"- Only the first octant/quadrant is given, bField map will be "
135 "symmetrically created for all other octants/quadrants"
144 if (bfieldmaptype == root) {
145 if (vm[
"bf-rz"].
template as<bool>()) {
147 [](std::array<size_t, 2> binsRZ, std::array<size_t, 2> nBinsRZ) {
148 return (binsRZ.at(1) * nBinsRZ.at(0) + binsRZ.at(0));
150 vm[
"bf-map"].template as<std::string>(),
151 vm[
"bf-name"].
template as<std::string>(), lengthUnit, BFieldUnit,
152 vm[
"bf-foctant"].template as<bool>());
156 config2D.
scale = bscalor;
158 return std::make_shared<InterpolatedBFieldMap2D>(std::move(config2D));
162 [](std::array<size_t, 3> binsXYZ, std::array<size_t, 3> nBinsXYZ) {
163 return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
164 binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
166 vm[
"bf-map"].template as<std::string>(),
167 vm[
"bf-name"].
template as<std::string>(), lengthUnit, BFieldUnit,
168 vm[
"bf-foctant"].template as<bool>());
172 config3D.
scale = bscalor;
174 return std::make_shared<InterpolatedBFieldMap3D>(std::move(config3D));
176 }
else if (bfieldmaptype == text) {
177 if (vm[
"bf-rz"].
template as<bool>()) {
179 [](std::array<size_t, 2> binsRZ, std::array<size_t, 2> nBinsRZ) {
180 return (binsRZ.at(1) * nBinsRZ.at(0) + binsRZ.at(0));
182 vm[
"bf-map"].template as<std::string>(), lengthUnit, BFieldUnit,
183 vm[
"bf-gridpoints"].
template as<size_t>(),
184 vm[
"bf-foctant"].template as<bool>());
188 config2D.
scale = bscalor;
190 return std::make_shared<InterpolatedBFieldMap2D>(std::move(config2D));
194 [](std::array<size_t, 3> binsXYZ, std::array<size_t, 3> nBinsXYZ) {
195 return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
196 binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
198 vm[
"bf-map"].template as<std::string>(), lengthUnit, BFieldUnit,
199 vm[
"bf-gridpoints"].
template as<size_t>(),
200 vm[
"bf-foctant"].template as<bool>());
204 config3D.
scale = bscalor;
206 return std::make_shared<InterpolatedBFieldMap3D>(std::move(config3D));
211 auto bFieldValues = vm[
"bf-values"].template as<read_range>();
212 if (bFieldValues.size() != 3) {
213 throw std::invalid_argument(
214 "- The values handed over for the constant magnetic field "
215 "have wrong dimension. Needs to have 3 dimension. Please "
216 "hand over the coordinates in cartesian coordinates: "
217 "{Bx,By,Bz} in Tesla.");
219 if (vm[
"bf-context-scalable"].
template as<bool>()) {
221 return std::make_shared<FW::BField::ScalableBField>(
227 return std::make_shared<Acts::ConstantBField>(