Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BFieldExample.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BFieldExample.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
15 
16 #include <string>
17 
18 #include <boost/program_options.hpp>
19 
20 namespace po = boost::program_options;
21 
27 int main(int argc, char* argv[]) {
29 
30  // setup and parse options
33  desc.add_options()("bf-file-out",
34  value<std::string>()->default_value("BFieldOut.root"),
35  "Set this name for an output root file.")(
36  "bf-map-out", value<std::string>()->default_value("bField"),
37  "Set this name for the tree in the out file.")(
38  "bf-out-rz", value<bool>()->default_value(false),
39  "Please set this flag to true, if you want to print out the field map in "
40  "cylinder coordinates (r,z). The default are cartesian coordinates "
41  "(x,y,z). ")(
42  "bf-rRange", value<ActsExamples::Options::Reals<2>>(),
43  "[optional] range which the bfield map should be written out in either r "
44  "(cylinder "
45  "coordinates) or x/y (cartesian coordinates) in [mm]. In case no value "
46  "is handed over the whole map will be written out. Please "
47  "hand over by simply separating the values by space")(
48  "bf-zRange", value<ActsExamples::Options::Reals<2>>(),
49  "[optional] range which the bfield map should be written out in z in "
50  "[mm].In case no value is handed over for 'bf-rRange' and 'bf-zRange the "
51  "whole map will be written out. "
52  "Please hand over by simply separating the values by space")(
53  "bf-rBins", value<size_t>()->default_value(200),
54  "[optional] The number of bins in r. This parameter only needs to be "
55  "specified if 'bf-rRange' and 'bf-zRange' are given.")(
56  "bf-ZBins", value<size_t>()->default_value(300),
57  "[optional] The number of bins in z. This parameter only needs to be "
58  "specified if 'bf-rRange' and 'bf-zRange' are given.")(
59  "bf-PhiBins", value<size_t>()->default_value(100),
60  "[optional] The number of bins in phi. This parameter only needs to be "
61  "specified if 'bf-rRange' and 'bf-zRange' are given and 'bf-out-rz' is "
62  "turned on.");
63  auto vm = ActsExamples::Options::parse(desc, argc, argv);
64  if (vm.empty()) {
65  return EXIT_FAILURE;
66  }
67 
68  auto bFieldVar = ActsExamples::Options::readMagneticField(vm);
69 
70  auto bField =
72  bFieldVar);
73  if (!bField) {
74  std::cout << "Bfield map could not be read. Exiting." << std::endl;
75  return EXIT_FAILURE;
76  }
77 
79 
80  // Write the interpolated magnetic field
82  if (vm["bf-out-rz"].template as<bool>()) {
83  writerConfig.gridType = GridType::rz;
84  } else {
85  writerConfig.gridType = GridType::xyz;
86  }
87  writerConfig.treeName = vm["bf-map-out"].template as<std::string>();
88  writerConfig.fileName = vm["bf-file-out"].template as<std::string>();
89  writerConfig.bField = bField;
90  std::cout << "setting rBounds" << std::endl;
91  if (vm.count("bf-rRange") != 0u && vm.count("bf-zRange") != 0u) {
92  auto rBounds =
93  vm["bf-rRange"].template as<ActsExamples::Options::Reals<2>>();
94  auto zBounds =
95  vm["bf-zRange"].template as<ActsExamples::Options::Reals<2>>();
96 
98  rBounds[1] *= Acts::UnitConstants::mm;
99 
100  zBounds[0] *= Acts::UnitConstants::mm;
101  zBounds[1] *= Acts::UnitConstants::mm;
102 
103  writerConfig.rBounds = rBounds;
104  writerConfig.zBounds = zBounds;
105  }
106  writerConfig.rBins = vm["bf-rBins"].template as<size_t>();
107  writerConfig.zBins = vm["bf-ZBins"].template as<size_t>();
108  writerConfig.phiBins = vm["bf-PhiBins"].template as<size_t>();
109 
111 }