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 
30 
31 #include <memory>
32 
33 #include <boost/program_options.hpp>
34 
35 namespace po = boost::program_options;
36 
37 namespace {
49 template <typename bfield_t>
50 ActsExamples::ProcessCode setupPropagation(
51  ActsExamples::Sequencer& sequencer, bfield_t bfield, po::variables_map& vm,
52  std::shared_ptr<ActsExamples::RandomNumbers> randomNumberSvc,
53  std::shared_ptr<const Acts::TrackingGeometry> tGeometry) {
54  // Get the log level
55  auto logLevel = ActsExamples::Options::readLogLevel(vm);
56 
57  // Get a Navigator
58  Acts::Navigator navigator(tGeometry);
62 
63  // Resolve the bfield map template and create the propgator
65  bfield_t,
70  Stepper stepper(std::move(bfield));
71  Propagator propagator(std::move(stepper), std::move(navigator));
72 
73  // Read the propagation config and create the algorithms
74  auto pAlgConfig =
76  pAlgConfig.randomNumberSvc = randomNumberSvc;
77  pAlgConfig.recordMaterialInteractions = true;
78  auto propagationAlg =
79  std::make_shared<ActsExamples::PropagationAlgorithm<Propagator>>(
80  pAlgConfig, logLevel);
81 
82  // Add the propagation algorithm
83  sequencer.addAlgorithm({propagationAlg});
84 
86 }
87 
96 ActsExamples::ProcessCode setupStraightLinePropagation(
97  ActsExamples::Sequencer& sequencer, po::variables_map& vm,
98  std::shared_ptr<ActsExamples::RandomNumbers> randomNumberSvc,
99  std::shared_ptr<const Acts::TrackingGeometry> tGeometry) {
100  // Get the log level
101  auto logLevel = ActsExamples::Options::readLogLevel(vm);
102 
103  // Get a Navigator
104  Acts::Navigator navigator(tGeometry);
105 
106  // Straight line stepper
107  using SlStepper = Acts::StraightLineStepper;
109  // Make stepper and propagator
110  SlStepper stepper;
111  Propagator propagator(std::move(stepper), std::move(navigator));
112 
113  // Read the propagation config and create the algorithms
114  auto pAlgConfig =
116  pAlgConfig.randomNumberSvc = randomNumberSvc;
117  auto propagationAlg =
118  std::make_shared<ActsExamples::PropagationAlgorithm<Propagator>>(
119  pAlgConfig, logLevel);
120 
121  // Add the propagation algorithm
122  sequencer.addAlgorithm({propagationAlg});
123 
125 }
126 
127 } // namespace
128 
129 int materialValidationExample(int argc, char* argv[],
130  ActsExamples::IBaseDetector& detector) {
131  // Setup and parse options
140 
141  // Add specific options for this geometry
142  detector.addOptions(desc);
143  auto vm = ActsExamples::Options::parse(desc, argc, argv);
144  if (vm.empty()) {
145  return EXIT_FAILURE;
146  }
147 
148  ActsExamples::Sequencer sequencer(
150 
151  // Now read the standard options
152  auto logLevel = ActsExamples::Options::readLogLevel(vm);
153 
154  // The geometry, material and decoration
155  auto geometry = ActsExamples::Geometry::build(vm, detector);
156  auto tGeometry = geometry.first;
157  auto contextDecorators = geometry.second;
158 
159  // Create the random number engine
160  auto randomNumberSvcCfg = ActsExamples::Options::readRandomNumbersConfig(vm);
161  auto randomNumberSvc =
162  std::make_shared<ActsExamples::RandomNumbers>(randomNumberSvcCfg);
163 
164  // Create BField service
165  auto bFieldVar = ActsExamples::Options::readBField(vm);
166 
167  if (vm["prop-stepper"].template as<int>() == 0) {
168  // Straight line stepper was chosen
169  setupStraightLinePropagation(sequencer, vm, randomNumberSvc, tGeometry);
170  } else {
171  std::visit(
172  [&](auto& bField) {
173  using field_type =
174  typename std::decay_t<decltype(bField)>::element_type;
176  setupPropagation(sequencer, fieldMap, vm, randomNumberSvc, tGeometry);
177  },
178  bFieldVar);
179  }
180 
181  // ---------------------------------------------------------------------------------
182  // Output directory
183  std::string outputDir = vm["output-dir"].template as<std::string>();
184  auto matCollection = vm["prop-material-collection"].as<std::string>();
185 
186  if (vm["output-root"].template as<bool>()) {
187  // Write the propagation steps as ROOT TTree
188  ActsExamples::RootMaterialTrackWriter::Config matTrackWriterRootConfig;
189  matTrackWriterRootConfig.collection = matCollection;
190  matTrackWriterRootConfig.filePath =
191  ActsExamples::joinPaths(outputDir, matCollection + ".root");
192  matTrackWriterRootConfig.storeSurface = true;
193  matTrackWriterRootConfig.storeVolume = true;
194  auto matTrackWriterRoot =
195  std::make_shared<ActsExamples::RootMaterialTrackWriter>(
196  matTrackWriterRootConfig, logLevel);
197  sequencer.addWriter(matTrackWriterRoot);
198  }
199 
200  // Initiate the run
201  sequencer.run();
202  // Return success code
203  return 0;
204 }