Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FatrasCommon.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FatrasCommon.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 
10 
29 
30 #include <memory>
31 #include <string>
32 
33 #include <boost/program_options.hpp>
34 
35 using namespace ActsExamples;
36 
37 namespace {
38 
39 // simulation handling
40 
41 void setupFatrasSimulation(
43  ActsExamples::Sequencer& sequencer,
44  std::shared_ptr<const ActsExamples::RandomNumbers> randomNumbers,
45  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry) {
46  auto logLevel = Options::readLogLevel(vars);
47  auto fatrasCfg = Options::readFatrasConfig(vars);
48  fatrasCfg.inputParticles = Simulation::kParticlesSelection;
49  fatrasCfg.outputParticlesInitial = Simulation::kParticlesInitial;
50  fatrasCfg.outputParticlesFinal = Simulation::kParticlesFinal;
51  fatrasCfg.outputSimHits = Simulation::kSimHits;
52  fatrasCfg.randomNumbers = std::move(randomNumbers);
53  fatrasCfg.trackingGeometry = std::move(trackingGeometry);
54  fatrasCfg.magneticField = ActsExamples::Options::readMagneticField(vars);
55 
56  sequencer.addAlgorithm(
57  std::make_shared<FatrasSimulation>(std::move(fatrasCfg), logLevel));
58 }
59 
60 } // namespace
61 
66 int runFatras(int argc, char* argv[],
67  const std::shared_ptr<ActsExamples::IBaseDetector>& detector) {
68  using namespace ActsExamples;
69 
70  // Setup and parse options
71  auto desc = Options::makeDefaultOptions();
75  Options::addOutputOptions(desc, OutputFormat::Root | OutputFormat::Csv);
76  // Add general and detector-specific geometry options
78  detector->addOptions(desc);
81  // Algorithm-specific options
83 
84  auto vars = Options::parse(desc, argc, argv);
85  if (vars.empty()) {
86  return EXIT_FAILURE;
87  }
88 
89  // Basic services
90  auto randomNumbers =
91  std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vars));
92 
93  // Setup sequencer
94  Sequencer sequencer(Options::readSequencerConfig(vars));
95  // Setup detector geometry and material and the magnetic field
96  auto [trackingGeometry, contextDecorators] = Geometry::build(vars, *detector);
97  for (const auto& cdr : contextDecorators) {
98  sequencer.addContextDecorator(cdr);
99  }
100  // Setup input, algorithm chain, output
101  Simulation::setupInput(vars, sequencer, randomNumbers);
102  setupFatrasSimulation(vars, sequencer, randomNumbers, trackingGeometry);
103  Simulation::setupOutput(vars, sequencer);
104 
105  // Run the simulation
106  return sequencer.run();
107 }