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