EIC 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 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 
13 
14 #include <string>
15 
16 #include <boost/program_options.hpp>
17 
18 #include "BFieldWritingBase.hpp"
19 
20 namespace po = boost::program_options;
21 
22 template <class T>
23 struct always_false : std::false_type {};
24 
30 
31 int main(int argc, char* argv[]) {
33 
34  // setup and parse options
37  desc.add_options()("bf-file-out",
38  value<std::string>()->default_value("BFieldOut.root"),
39  "Set this name for an output root file.")(
40  "bf-map-out", value<std::string>()->default_value("bField"),
41  "Set this name for the tree in the out file.")(
42  "bf-out-rz", value<bool>()->default_value(false),
43  "Please set this flag to true, if you want to print out the field map in "
44  "cylinder coordinates (r,z). The default are cartesian coordinates "
45  "(x,y,z). ")(
46  "bf-rRange", value<read_range>()->multitoken(),
47  "[optional] range which the bfield map should be written out in either r "
48  "(cylinder "
49  "coordinates) or x/y (cartesian coordinates) in [mm]. In case no value "
50  "is handed over the whole map will be written out. Please "
51  "hand over by simply seperating the values by space")(
52  "bf-zRange", value<read_range>()->multitoken(),
53  "[optional] range which the bfield map should be written out in z in "
54  "[mm].In case no value is handed over for 'bf-rRange' and 'bf-zRange the "
55  "whole map will be written out. "
56  "Please hand over by simply seperating the values by space")(
57  "bf-rBins", value<size_t>()->default_value(200),
58  "[optional] The number of bins in r. This parameter only needs to be "
59  "specified if 'bf-rRange' and 'bf-zRange' are given.")(
60  "bf-ZBins", value<size_t>()->default_value(300),
61  "[optional] The number of bins in z. This parameter only needs to be "
62  "specified if 'bf-rRange' and 'bf-zRange' are given.")(
63  "bf-PhiBins", value<size_t>()->default_value(100),
64  "[optional] The number of bins in phi. This parameter only needs to be "
65  "specified if 'bf-rRange' and 'bf-zRange' are given and 'bf-out-rz' is "
66  "turned on.");
67  auto vm = ActsExamples::Options::parse(desc, argc, argv);
68  if (vm.empty()) {
69  return EXIT_FAILURE;
70  }
71 
72  auto bFieldVar = ActsExamples::Options::readBField(vm);
73 
74  return std::visit(
75  [&](auto& bField) -> int {
76  using field_type =
77  typename std::decay_t<decltype(bField)>::element_type;
78  if constexpr (!std::is_same_v<field_type, InterpolatedBFieldMap2D> &&
79  !std::is_same_v<field_type, InterpolatedBFieldMap3D>) {
80  std::cout << "Bfield map could not be read. Exiting." << std::endl;
81  return EXIT_FAILURE;
82  } else {
83  ActsExamples::BField::writeField<field_type>(vm, bField);
84  return EXIT_SUCCESS;
85  }
86  },
87  bFieldVar);
88 }