ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialValidationBase.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialValidationBase.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
17 #include <boost/program_options.hpp>
18 #include <memory>
19 
31 
32 namespace po = boost::program_options;
33 
34 namespace {
46 template <typename bfield_t>
47 FW::ProcessCode setupPropagation(
48  FW::Sequencer& sequencer, bfield_t bfield, po::variables_map& vm,
49  std::shared_ptr<FW::RandomNumbers> randomNumberSvc,
50  std::shared_ptr<const Acts::TrackingGeometry> tGeometry) {
51  // Get the log level
52  auto logLevel = FW::Options::readLogLevel(vm);
53 
54  // Get a Navigator
55  Acts::Navigator navigator(tGeometry);
56 
57  // Resolve the bfield map template and create the propgator
60  Stepper stepper(std::move(bfield));
61  Propagator propagator(std::move(stepper), std::move(navigator));
62 
63  // Read the propagation config and create the algorithms
64  auto pAlgConfig = FW::Options::readPropagationConfig(vm, propagator);
65  pAlgConfig.randomNumberSvc = randomNumberSvc;
66  auto propagationAlg = std::make_shared<FW::PropagationAlgorithm<Propagator>>(
67  pAlgConfig, logLevel);
68 
69  // Add the propagation algorithm
70  sequencer.addAlgorithm({propagationAlg});
71 
73 }
74 
83 FW::ProcessCode setupStraightLinePropagation(
84  FW::Sequencer& sequencer, po::variables_map& vm,
85  std::shared_ptr<FW::RandomNumbers> randomNumberSvc,
86  std::shared_ptr<const Acts::TrackingGeometry> tGeometry) {
87  // Get the log level
88  auto logLevel = FW::Options::readLogLevel(vm);
89 
90  // Get a Navigator
91  Acts::Navigator navigator(tGeometry);
92 
93  // Straight line stepper
94  using SlStepper = Acts::StraightLineStepper;
96  // Make stepper and propagator
97  SlStepper stepper;
98  Propagator propagator(std::move(stepper), std::move(navigator));
99 
100  // Read the propagation config and create the algorithms
101  auto pAlgConfig = FW::Options::readPropagationConfig(vm, propagator);
102  pAlgConfig.randomNumberSvc = randomNumberSvc;
103  auto propagationAlg = std::make_shared<FW::PropagationAlgorithm<Propagator>>(
104  pAlgConfig, logLevel);
105 
106  // Add the propagation algorithm
107  sequencer.addAlgorithm({propagationAlg});
108 
110 }
111 
112 } // namespace
113 
114 int materialValidationExample(int argc, char* argv[],
115  FW::IBaseDetector& detector) {
116  // Setup and parse options
125 
126  // Add specific options for this geometry
127  detector.addOptions(desc);
128  auto vm = FW::Options::parse(desc, argc, argv);
129  if (vm.empty()) {
130  return EXIT_FAILURE;
131  }
132 
134 
135  // Now read the standard options
136  auto logLevel = FW::Options::readLogLevel(vm);
137 
138  // The geometry, material and decoration
139  auto geometry = FW::Geometry::build(vm, detector);
140  auto tGeometry = geometry.first;
141  auto contextDecorators = geometry.second;
142 
143  // Create the random number engine
144  auto randomNumberSvcCfg = FW::Options::readRandomNumbersConfig(vm);
145  auto randomNumberSvc =
146  std::make_shared<FW::RandomNumbers>(randomNumberSvcCfg);
147 
148  // Create BField service
149  auto bFieldVar = FW::Options::readBField(vm);
150 
151  if (vm["prop-stepper"].template as<int>() == 0) {
152  // Straight line stepper was chosen
153  setupStraightLinePropagation(sequencer, vm, randomNumberSvc, tGeometry);
154  } else {
155  std::visit(
156  [&](auto& bField) {
157  using field_type =
158  typename std::decay_t<decltype(bField)>::element_type;
160  setupPropagation(sequencer, fieldMap, vm, randomNumberSvc, tGeometry);
161  },
162  bFieldVar);
163  }
164 
165  // ---------------------------------------------------------------------------------
166  // Output directory
167  std::string outputDir = vm["output-dir"].template as<std::string>();
168  auto matCollection = vm["prop-material-collection"].as<std::string>();
169 
170  if (vm["output-root"].template as<bool>()) {
171  // Write the propagation steps as ROOT TTree
172  FW::RootMaterialTrackWriter::Config matTrackWriterRootConfig;
173  matTrackWriterRootConfig.collection = matCollection;
174  matTrackWriterRootConfig.filePath =
175  FW::joinPaths(outputDir, matCollection + ".root");
176  matTrackWriterRootConfig.storesurface = true;
177  auto matTrackWriterRoot = std::make_shared<FW::RootMaterialTrackWriter>(
178  matTrackWriterRootConfig, logLevel);
179  sequencer.addWriter(matTrackWriterRoot);
180  }
181 
182  // Initiate the run
183  sequencer.run();
184  // Return success code
185  return 0;
186 }