EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PropagationExampleBase.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PropagationExampleBase.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
30 
31 #include <memory>
32 
33 #include <boost/program_options.hpp>
34 
35 int propagationExample(int argc, char* argv[],
36  ActsExamples::IBaseDetector& detector) {
37  // Setup and parse options
46 
47  // Add specific options for this geometry
48  detector.addOptions(desc);
49  auto vm = ActsExamples::Options::parse(desc, argc, argv);
50  if (vm.empty()) {
51  return EXIT_FAILURE;
52  }
53  ActsExamples::Sequencer sequencer(
55 
56  // Now read the standard options
57  auto logLevel = ActsExamples::Options::readLogLevel(vm);
58 
59  // The geometry, material and decoration
60  auto geometry = ActsExamples::Geometry::build(vm, detector);
61  auto tGeometry = geometry.first;
62  auto contextDecorators = geometry.second;
63  // Add the decorator to the sequencer
64  for (auto cdr : contextDecorators) {
65  sequencer.addContextDecorator(cdr);
66  }
67 
68  // Create the random number engine
69  auto randomNumberSvcCfg = ActsExamples::Options::readRandomNumbersConfig(vm);
70  auto randomNumberSvc =
71  std::make_shared<ActsExamples::RandomNumbers>(randomNumberSvcCfg);
72 
73  // Create BField service
74  auto bFieldVar = ActsExamples::Options::readBField(vm);
75  // auto field2D = std::get<std::shared_ptr<InterpolatedBFieldMap2D>>(bField);
76  // auto field3D = std::get<std::shared_ptr<InterpolatedBFieldMap3D>>(bField);
77 
78  // Get a Navigator
80 
81  std::visit(
82  [&](auto& bField) {
83  // Resolve the bfield map and create the propgator
84  using field_type =
85  typename std::decay_t<decltype(bField)>::element_type;
87 
88  using field_map_type = decltype(fieldMap);
89 
90  std::optional<std::variant<Acts::EigenStepper<field_map_type>,
93  var_stepper;
94 
95  // translate option to variant
96  if (vm["prop-stepper"].template as<int>() == 0) {
97  var_stepper = Acts::StraightLineStepper{};
98  } else if (vm["prop-stepper"].template as<int>() == 1) {
99  var_stepper = Acts::EigenStepper<field_map_type>{std::move(fieldMap)};
100  } else if (vm["prop-stepper"].template as<int>() == 2) {
101  var_stepper = Acts::AtlasStepper<field_map_type>{std::move(fieldMap)};
102  }
103 
104  // resolve stepper, setup propagator
105  std::visit(
106  [&](auto& stepper) {
107  using Stepper = std::decay_t<decltype(stepper)>;
109  Propagator propagator(std::move(stepper), std::move(navigator));
110 
111  // Read the propagation config and create the algorithms
112  auto pAlgConfig =
114  pAlgConfig.randomNumberSvc = randomNumberSvc;
115  sequencer.addAlgorithm(
116  std::make_shared<
118  pAlgConfig, logLevel));
119  },
120  *var_stepper);
121  },
122  bFieldVar);
123 
124  // ---------------------------------------------------------------------------------
125  // Output directory
126  std::string outputDir = vm["output-dir"].template as<std::string>();
127  auto psCollection = vm["prop-step-collection"].as<std::string>();
128 
129  if (vm["output-root"].template as<bool>()) {
130  // Write the propagation steps as ROOT TTree
132  pstepWriterRootConfig.collection = psCollection;
133  pstepWriterRootConfig.filePath =
134  ActsExamples::joinPaths(outputDir, psCollection + ".root");
135  sequencer.addWriter(
136  std::make_shared<ActsExamples::RootPropagationStepsWriter>(
137  pstepWriterRootConfig));
138  }
139 
140  if (vm["output-obj"].template as<bool>()) {
142  using ObjPropagationStepsWriter =
144 
145  // Write the propagation steps as Obj TTree
146  ObjPropagationStepsWriter::Config pstepWriterObjConfig;
147  pstepWriterObjConfig.collection = psCollection;
148  pstepWriterObjConfig.outputDir = outputDir;
149  sequencer.addWriter(
150  std::make_shared<ObjPropagationStepsWriter>(pstepWriterObjConfig));
151  }
152 
153  return sequencer.run();
154 }