Analysis Software
Documentation for sPHENIX simulation 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-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 
27 
28 #include <memory>
29 
30 #include <boost/program_options.hpp>
31 
32 int propagationExample(int argc, char* argv[],
34  // Setup and parse options
43  desc, ActsExamples::OutputFormat::Root | ActsExamples::OutputFormat::Obj);
44 
45  // Add specific options for this geometry
46  detector.addOptions(desc);
47  auto vm = ActsExamples::Options::parse(desc, argc, argv);
48  if (vm.empty()) {
49  return EXIT_FAILURE;
50  }
51  ActsExamples::Sequencer sequencer(
53 
54  // Now read the standard options
56 
57  // The geometry, material and decoration
58  auto geometry = ActsExamples::Geometry::build(vm, detector);
59  auto tGeometry = geometry.first;
60  auto contextDecorators = geometry.second;
61  // Add the decorator to the sequencer
62  for (const auto& cdr : contextDecorators) {
63  sequencer.addContextDecorator(cdr);
64  }
65 
66  // Create the random number engine
67  auto randomNumberSvcCfg = ActsExamples::Options::readRandomNumbersConfig(vm);
68  auto randomNumberSvc =
69  std::make_shared<ActsExamples::RandomNumbers>(randomNumberSvcCfg);
70 
71  // Create BField service
74 
75  // Check what output exists, if none exists, the SteppingLogger
76  // will switch to sterile.
77  bool rootOutput = vm["output-root"].template as<bool>();
78  bool objOutput = vm["output-obj"].template as<bool>();
79 
80  auto setupPropagator = [&](auto&& stepper) {
81  using Stepper = std::decay_t<decltype(stepper)>;
84  navCfg.resolveMaterial = vm["prop-resolve-material"].template as<bool>();
85  navCfg.resolvePassive = vm["prop-resolve-passive"].template as<bool>();
86  navCfg.resolveSensitive = vm["prop-resolve-sensitive"].template as<bool>();
87  Acts::Navigator navigator(navCfg);
88 
89  Propagator propagator(std::move(stepper), std::move(navigator));
90 
91  // Read the propagation config and create the algorithms
93  pAlgConfig.randomNumberSvc = randomNumberSvc;
94  pAlgConfig.sterileLogger = not rootOutput and not objOutput;
95 
96  pAlgConfig.propagatorImpl =
97  std::make_shared<ActsExamples::ConcretePropagator<Propagator>>(
98  std::move(propagator));
99 
100  sequencer.addAlgorithm(std::make_shared<ActsExamples::PropagationAlgorithm>(
101  pAlgConfig, logLevel));
102  };
103 
104  // translate option to variant
105  if (vm["prop-stepper"].template as<int>() == 0) {
106  setupPropagator(Acts::StraightLineStepper{});
107  } else if (vm["prop-stepper"].template as<int>() == 1) {
108  setupPropagator(Acts::EigenStepper<>{std::move(bField)});
109  } else if (vm["prop-stepper"].template as<int>() == 2) {
110  setupPropagator(Acts::AtlasStepper{std::move(bField)});
111  }
112 
113  // ---------------------------------------------------------------------------------
114  // Output directory
115  std::string outputDir = vm["output-dir"].template as<std::string>();
116  auto psCollection = vm["prop-step-collection"].as<std::string>();
117 
118  if (rootOutput) {
119  // Write the propagation steps as ROOT TTree
121  pstepWriterRootConfig.collection = psCollection;
122  pstepWriterRootConfig.filePath =
123  ActsExamples::joinPaths(outputDir, psCollection + ".root");
124  sequencer.addWriter(
125  std::make_shared<ActsExamples::RootPropagationStepsWriter>(
126  pstepWriterRootConfig));
127  }
128 
129  if (objOutput) {
131  using ObjPropagationStepsWriter =
133 
134  // Write the propagation steps as Obj TTree
135  ObjPropagationStepsWriter::Config pstepWriterObjConfig;
136  pstepWriterObjConfig.collection = psCollection;
137  pstepWriterObjConfig.outputDir = outputDir;
138  sequencer.addWriter(
139  std::make_shared<ObjPropagationStepsWriter>(pstepWriterObjConfig));
140  }
141 
142  return sequencer.run();
143 }