Analysis Software
Documentation for sPHENIX simulation 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-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 namespace po = boost::program_options;
33 
34 namespace {
46 ActsExamples::ProcessCode setupPropagation(
47  ActsExamples::Sequencer& sequencer,
48  std::shared_ptr<const Acts::MagneticFieldProvider> bfield,
49  po::variables_map& vm,
50  std::shared_ptr<ActsExamples::RandomNumbers> randomNumberSvc,
51  std::shared_ptr<const Acts::TrackingGeometry> tGeometry) {
52  // Get the log level
54 
55  // Get a Navigator
57  cfg.trackingGeometry = std::move(tGeometry);
58  cfg.resolvePassive = true;
59  cfg.resolveMaterial = true;
60  cfg.resolveSensitive = true;
62 
63  // Resolve the bfield map template and create the propagator
69  Stepper stepper(std::move(bfield));
71 
72  // Read the propagation config and create the algorithms
74  pAlgConfig.randomNumberSvc = std::move(randomNumberSvc);
75  pAlgConfig.recordMaterialInteractions = true;
76 
77  pAlgConfig.propagatorImpl =
78  std::make_shared<ActsExamples::ConcretePropagator<Propagator>>(
79  std::move(propagator));
80 
81  auto propagationAlg = std::make_shared<ActsExamples::PropagationAlgorithm>(
82  pAlgConfig, logLevel);
83 
84  // Add the propagation algorithm
85  sequencer.addAlgorithm({propagationAlg});
86 
88 }
89 
98 ActsExamples::ProcessCode setupStraightLinePropagation(
99  ActsExamples::Sequencer& sequencer, po::variables_map& vm,
100  std::shared_ptr<ActsExamples::RandomNumbers> randomNumberSvc,
101  std::shared_ptr<const Acts::TrackingGeometry> tGeometry) {
102  // Get the log level
104 
105  // Get a Navigator
106  Acts::Navigator navigator({std::move(tGeometry)});
107 
108  // Straight line stepper
109  using SlStepper = Acts::StraightLineStepper;
111  // Make stepper and propagator
112  SlStepper stepper;
113  Propagator propagator(stepper, std::move(navigator));
114 
115  // Read the propagation config and create the algorithms
116  auto pAlgConfig = ActsExamples::Options::readPropagationConfig(vm);
117 
118  pAlgConfig.randomNumberSvc = std::move(randomNumberSvc);
119  pAlgConfig.propagatorImpl =
120  std::make_shared<ActsExamples::ConcretePropagator<Propagator>>(
121  std::move(propagator));
122  auto propagationAlg = std::make_shared<ActsExamples::PropagationAlgorithm>(
123  pAlgConfig, logLevel);
124 
125  // Add the propagation algorithm
126  sequencer.addAlgorithm({propagationAlg});
127 
129 }
130 
131 } // namespace
132 
133 int materialValidationExample(int argc, char* argv[],
135  // Setup and parse options
144  ActsExamples::OutputFormat::Root);
145 
146  // Add specific options for this geometry
147  detector.addOptions(desc);
148  auto vm = ActsExamples::Options::parse(desc, argc, argv);
149  if (vm.empty()) {
150  return EXIT_FAILURE;
151  }
152 
153  ActsExamples::Sequencer sequencer(
155 
156  // Now read the standard options
158 
159  // The geometry, material and decoration
160  auto geometry = ActsExamples::Geometry::build(vm, detector);
161  auto tGeometry = geometry.first;
162  auto contextDecorators = geometry.second;
163  for (const auto& cdr : contextDecorators) {
164  sequencer.addContextDecorator(cdr);
165  }
166 
167  // Create the random number engine
168  auto randomNumberSvcCfg = ActsExamples::Options::readRandomNumbersConfig(vm);
169  auto randomNumberSvc =
170  std::make_shared<ActsExamples::RandomNumbers>(randomNumberSvcCfg);
171 
172  // Create BField service
175 
176  if (vm["prop-stepper"].template as<int>() == 0) {
177  // Straight line stepper was chosen
178  setupStraightLinePropagation(sequencer, vm, randomNumberSvc, tGeometry);
179  } else {
180  setupPropagation(sequencer, bField, vm, randomNumberSvc, tGeometry);
181  }
182 
183  // ---------------------------------------------------------------------------------
184  // Output directory
185  std::string outputDir = vm["output-dir"].template as<std::string>();
186  auto matCollection = vm["prop-material-collection"].as<std::string>();
187 
188  if (vm["output-root"].template as<bool>()) {
189  // Write the propagation steps as ROOT TTree
190  ActsExamples::RootMaterialTrackWriter::Config matTrackWriterRootConfig;
191  matTrackWriterRootConfig.collection = matCollection;
192  matTrackWriterRootConfig.filePath =
193  ActsExamples::joinPaths(outputDir, matCollection + ".root");
194  matTrackWriterRootConfig.storeSurface = true;
195  matTrackWriterRootConfig.storeVolume = true;
196  auto matTrackWriterRoot =
197  std::make_shared<ActsExamples::RootMaterialTrackWriter>(
198  matTrackWriterRootConfig, logLevel);
199  sequencer.addWriter(matTrackWriterRoot);
200  }
201 
202  // Initiate the run
203  sequencer.run();
204  // Return success code
205  return 0;
206 }