EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FatrasEvgenBase.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FatrasEvgenBase.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 
9 #include "FatrasEvgenBase.hpp"
10 
20 
23  ActsExamples::Sequencer& sequencer,
24  std::shared_ptr<const ActsExamples::RandomNumbers> randomNumberSvc) {
25  // Read the standard options
26  auto logLevel = ActsExamples::Options::readLogLevel(vm);
27 
28  // Add requested event generator
29  std::string particlesCollection = "particles_generated";
30  auto evgenInput = vm["evg-input-type"].template as<std::string>();
31  if (evgenInput == "gun") {
33  evgCfg.outputParticles = particlesCollection;
34  evgCfg.randomNumbers = randomNumberSvc;
35  sequencer.addReader(std::make_shared<EventGenerator>(evgCfg, logLevel));
36 
37  } else if (evgenInput == "pythia8") {
38  auto evgCfg = ActsExamples::Options::readPythia8Options(vm, logLevel);
39  evgCfg.outputParticles = particlesCollection;
40  evgCfg.randomNumbers = randomNumberSvc;
41  sequencer.addReader(std::make_shared<EventGenerator>(evgCfg, logLevel));
42 
43  } else {
44  throw std::runtime_error("unknown event generator input: " + evgenInput);
45  }
46 
47  // Output directory
48  std::string outputDir = vm["output-dir"].template as<std::string>();
49 
50  // Write generated particles as CSV files
51  if (vm["output-csv"].template as<bool>()) {
53  pWriterCsvConfig.inputParticles = particlesCollection;
54  pWriterCsvConfig.outputDir = outputDir;
55  pWriterCsvConfig.outputStem = "particles_generated";
56  sequencer.addWriter(
57  std::make_shared<CsvParticleWriter>(pWriterCsvConfig, logLevel));
58  }
59 
60  // Write generated particles as ROOT file
61  if (vm["output-root"].template as<bool>()) {
62  // Write particles as ROOT TTree
64  pWriterRootConfig.inputParticles = particlesCollection;
65  pWriterRootConfig.filePath = joinPaths(outputDir, "particles.root");
66  sequencer.addWriter(
67  std::make_shared<RootParticleWriter>(pWriterRootConfig, logLevel));
68  }
69 }