Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleGun.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleGun.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
18 
19 #include <cstdlib>
20 #include <memory>
21 
22 using namespace ActsExamples;
23 
24 int main(int argc, char* argv[]) {
25  // Setup and parse options
26  auto desc = Options::makeDefaultOptions();
30  Options::addOutputOptions(desc, OutputFormat::Csv | OutputFormat::Root);
31  auto vm = Options::parse(desc, argc, argv);
32  if (vm.empty()) {
33  return EXIT_FAILURE;
34  }
35 
37 
39 
40  // Basic services
41  auto rnd =
42  std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vm));
43 
44  // Event generation w/ particle gun
46  evgen.outputParticles = "particles";
47  evgen.randomNumbers = rnd;
48  sequencer.addReader(std::make_shared<EventGenerator>(evgen, logLevel));
49 
50  // Print generated particles
51  if ((logLevel == Acts::Logging::VERBOSE) or
52  (logLevel == Acts::Logging::DEBUG)) {
54  print.inputParticles = evgen.outputParticles;
55  sequencer.addAlgorithm(std::make_shared<ParticlesPrinter>(print, logLevel));
56  }
57 
58  // Different output modes
59  auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>());
60  if (vm["output-csv"].as<bool>()) {
61  CsvParticleWriter::Config csvWriter;
62  csvWriter.inputParticles = evgen.outputParticles;
63  csvWriter.outputDir = outputDir;
64  csvWriter.outputStem = "particles";
65  sequencer.addWriter(
66  std::make_shared<CsvParticleWriter>(csvWriter, logLevel));
67  }
68  if (vm["output-root"].as<bool>()) {
69  RootParticleWriter::Config rootWriter;
70  rootWriter.inputParticles = evgen.outputParticles;
71  rootWriter.filePath = joinPaths(outputDir, "particles.root");
72  sequencer.addWriter(
73  std::make_shared<RootParticleWriter>(rootWriter, logLevel));
74  }
75 
76  return sequencer.run();
77 }