ECCE @ 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 
18 #include <boost/program_options.hpp>
19 #include <memory>
20 
33 
34 int propagationExample(int argc, char* argv[], FW::IBaseDetector& detector) {
35  // Setup and parse options
44 
45  // Add specific options for this geometry
46  detector.addOptions(desc);
47  auto vm = FW::Options::parse(desc, argc, argv);
48  if (vm.empty()) {
49  return EXIT_FAILURE;
50  }
52 
53  // Now read the standard options
54  auto logLevel = FW::Options::readLogLevel(vm);
55 
56  // The geometry, material and decoration
57  auto geometry = FW::Geometry::build(vm, detector);
58  auto tGeometry = geometry.first;
59  auto contextDecorators = geometry.second;
60  // Add the decorator to the sequencer
61  for (auto cdr : contextDecorators) {
62  sequencer.addContextDecorator(cdr);
63  }
64 
65  // Create the random number engine
66  auto randomNumberSvcCfg = FW::Options::readRandomNumbersConfig(vm);
67  auto randomNumberSvc =
68  std::make_shared<FW::RandomNumbers>(randomNumberSvcCfg);
69 
70  // Create BField service
71  auto bFieldVar = FW::Options::readBField(vm);
72  // auto field2D = std::get<std::shared_ptr<InterpolatedBFieldMap2D>>(bField);
73  // auto field3D = std::get<std::shared_ptr<InterpolatedBFieldMap3D>>(bField);
74 
75  // Get a Navigator
77 
78  std::visit(
79  [&](auto& bField) {
80  // Resolve the bfield map and create the propgator
81  using field_type =
82  typename std::decay_t<decltype(bField)>::element_type;
84 
85  using field_map_type = decltype(fieldMap);
86 
87  std::optional<std::variant<Acts::EigenStepper<field_map_type>,
90  var_stepper;
91 
92  // translate option to variant
93  if (vm["prop-stepper"].template as<int>() == 0) {
94  var_stepper = Acts::StraightLineStepper{};
95  } else if (vm["prop-stepper"].template as<int>() == 1) {
96  var_stepper = Acts::EigenStepper<field_map_type>{std::move(fieldMap)};
97  } else if (vm["prop-stepper"].template as<int>() == 2) {
98  var_stepper = Acts::AtlasStepper<field_map_type>{std::move(fieldMap)};
99  }
100 
101  // resolve stepper, setup propagator
102  std::visit(
103  [&](auto& stepper) {
104  using Stepper = std::decay_t<decltype(stepper)>;
106  Propagator propagator(std::move(stepper), std::move(navigator));
107 
108  // Read the propagation config and create the algorithms
109  auto pAlgConfig =
110  FW::Options::readPropagationConfig(vm, propagator);
111  pAlgConfig.randomNumberSvc = randomNumberSvc;
112  sequencer.addAlgorithm(
113  std::make_shared<FW::PropagationAlgorithm<Propagator>>(
114  pAlgConfig, logLevel));
115  },
116  *var_stepper);
117  },
118  bFieldVar);
119 
120  // ---------------------------------------------------------------------------------
121  // Output directory
122  std::string outputDir = vm["output-dir"].template as<std::string>();
123  auto psCollection = vm["prop-step-collection"].as<std::string>();
124 
125  if (vm["output-root"].template as<bool>()) {
126  // Write the propagation steps as ROOT TTree
127  FW::RootPropagationStepsWriter::Config pstepWriterRootConfig;
128  pstepWriterRootConfig.collection = psCollection;
129  pstepWriterRootConfig.filePath =
130  FW::joinPaths(outputDir, psCollection + ".root");
131  sequencer.addWriter(std::make_shared<FW::RootPropagationStepsWriter>(
132  pstepWriterRootConfig));
133  }
134 
135  if (vm["output-obj"].template as<bool>()) {
137  using ObjPropagationStepsWriter =
139 
140  // Write the propagation steps as Obj TTree
141  ObjPropagationStepsWriter::Config pstepWriterObjConfig;
142  pstepWriterObjConfig.collection = psCollection;
143  pstepWriterObjConfig.outputDir = outputDir;
144  sequencer.addWriter(
145  std::make_shared<ObjPropagationStepsWriter>(pstepWriterObjConfig));
146  }
147 
148  return sequencer.run();
149 }