ECCE @ 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 
21 
23  const FW::Options::Variables& vm, FW::Sequencer& sequencer,
24  std::shared_ptr<const FW::RandomNumbers> randomNumberSvc) {
25  // Read the standard options
26  auto logLevel = FW::Options::readLogLevel(vm);
27 
28  // Add requested event generator
29  auto evgenInput = vm["evg-input-type"].template as<std::string>();
30  if (evgenInput == "gun") {
31  auto evgCfg = FW::Options::readParticleGunOptions(vm);
32  evgCfg.output = "event_generated";
33  evgCfg.randomNumbers = randomNumberSvc;
34  sequencer.addReader(std::make_shared<FW::EventGenerator>(evgCfg, logLevel));
35 
36  } else if (evgenInput == "pythia8") {
37  auto evgCfg = FW::Options::readPythia8Options(vm, logLevel);
38  evgCfg.output = "event_generated";
39  evgCfg.randomNumbers = randomNumberSvc;
40  sequencer.addReader(std::make_shared<FW::EventGenerator>(evgCfg, logLevel));
41 
42  } else {
43  throw std::runtime_error("unknown event generator input: " + evgenInput);
44  }
45 
46  // Convert to particles for the writers and subsequent algorithms
48  flatten.inputEvent = "event_generated";
49  flatten.outputParticles = "particles_generated";
50  sequencer.addAlgorithm(std::make_shared<FW::FlattenEvent>(flatten, logLevel));
51 
52  // Output directory
53  std::string outputDir = vm["output-dir"].template as<std::string>();
54 
55  // Write generated particles as CSV files
56  if (vm["output-csv"].template as<bool>()) {
57  FW::CsvParticleWriter::Config pWriterCsvConfig;
58  pWriterCsvConfig.inputParticles = flatten.outputParticles;
59  pWriterCsvConfig.outputDir = outputDir;
60  pWriterCsvConfig.outputStem = "particles_generated";
61  sequencer.addWriter(
62  std::make_shared<FW::CsvParticleWriter>(pWriterCsvConfig, logLevel));
63  }
64 
65  // Write generated particles as ROOT file
66  if (vm["output-root"].template as<bool>()) {
67  // Write particles as ROOT TTree
68  FW::RootParticleWriter::Config pWriterRootConfig;
69  pWriterRootConfig.inputParticles = flatten.outputParticles;
70  pWriterRootConfig.filePath = FW::joinPaths(outputDir, "particles.root");
71  sequencer.addWriter(
72  std::make_shared<FW::RootParticleWriter>(pWriterRootConfig, logLevel));
73  }
74 }