ECCE @ EIC 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 
10 #include <cstdlib>
11 #include <memory>
12 
22 
23 using namespace FW;
24 
25 int main(int argc, char* argv[]) {
26  // setup and parse options
32  auto vm = Options::parse(desc, argc, argv);
33  if (vm.empty()) {
34  return EXIT_FAILURE;
35  }
36 
38 
40 
41  // basic services
42  auto rnd =
43  std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vm));
44 
45  // event generation w/ particle gun
47  evgenCfg.output = "event";
48  evgenCfg.randomNumbers = rnd;
49  sequencer.addReader(std::make_shared<EventGenerator>(evgenCfg, logLevel));
50 
51  // flatten event to just particles
52  FlattenEvent::Config flatten;
53  flatten.inputEvent = evgenCfg.output;
54  flatten.outputParticles = "particles";
55  sequencer.addAlgorithm(std::make_shared<FlattenEvent>(flatten, logLevel));
56 
57  // print generated particles
58  PrintParticles::Config printCfg;
59  printCfg.inputParticles = flatten.outputParticles;
60  sequencer.addAlgorithm(std::make_shared<PrintParticles>(printCfg, logLevel));
61 
62  // different output modes
63  auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>());
64  if (vm["output-csv"].as<bool>()) {
65  CsvParticleWriter::Config csvWriterCfg;
66  csvWriterCfg.inputParticles = flatten.outputParticles;
67  csvWriterCfg.outputDir = outputDir;
68  csvWriterCfg.outputStem = "particles";
69  sequencer.addWriter(
70  std::make_shared<CsvParticleWriter>(csvWriterCfg, logLevel));
71  }
72  if (vm["output-root"].as<bool>()) {
73  RootParticleWriter::Config rootWriterCfg;
74  rootWriterCfg.inputParticles = flatten.outputParticles;
75  rootWriterCfg.filePath = joinPaths(outputDir, "particles.root");
76  sequencer.addWriter(
77  std::make_shared<RootParticleWriter>(rootWriterCfg, logLevel));
78  }
79 
80  return sequencer.run();
81 }