ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pythia8.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Pythia8.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 
23 
24 using namespace Acts::UnitLiterals;
25 using namespace FW;
26 
27 int main(int argc, char* argv[]) {
28  // setup and parse options
34  auto vm = Options::parse(desc, argc, argv);
35  if (vm.empty()) {
36  return EXIT_FAILURE;
37  }
38 
39  auto logLevel = Options::readLogLevel(vm);
41  Sequencer sequencer(sequencerCfg);
42 
43  // basic services
44  auto rnd =
45  std::make_shared<RandomNumbers>(Options::readRandomNumbersConfig(vm));
46 
47  // event generation w/ internal pythia8 instance
49  evgen.output = "event";
50  evgen.randomNumbers = rnd;
51  sequencer.addReader(std::make_shared<EventGenerator>(evgen, logLevel));
52 
53  // event selection
54  ParticleSelector::Config selectorCfg;
55  selectorCfg.inputEvent = evgen.output;
56  selectorCfg.outputEvent = "event_selected";
57  selectorCfg.absEtaMax = 5.0;
58  selectorCfg.ptMin = 250_MeV;
59  // retain only charged particles
60  selectorCfg.removeNeutral = true;
61  sequencer.addAlgorithm(
62  std::make_shared<ParticleSelector>(selectorCfg, logLevel));
63 
64  // flatten event to just particles
65  FlattenEvent::Config flatten;
66  flatten.inputEvent = selectorCfg.outputEvent;
67  flatten.outputParticles = "particles";
68  sequencer.addAlgorithm(std::make_shared<FlattenEvent>(flatten, logLevel));
69 
70  // print generated particles
71  PrintParticles::Config printCfg;
72  printCfg.inputParticles = flatten.outputParticles;
73  sequencer.addAlgorithm(std::make_shared<PrintParticles>(printCfg, logLevel));
74 
75  // different output modes
76  auto outputDir = ensureWritableDirectory(vm["output-dir"].as<std::string>());
77  if (vm["output-csv"].as<bool>()) {
78  CsvParticleWriter::Config csvWriterCfg;
79  csvWriterCfg.inputParticles = flatten.outputParticles;
80  csvWriterCfg.outputDir = outputDir;
81  csvWriterCfg.outputStem = "particles";
82  sequencer.addWriter(
83  std::make_shared<CsvParticleWriter>(csvWriterCfg, logLevel));
84  }
85  if (vm["output-root"].as<bool>()) {
86  RootParticleWriter::Config rootWriterCfg;
87  rootWriterCfg.inputParticles = flatten.outputParticles;
88  rootWriterCfg.filePath = joinPaths(outputDir, "particles.root");
89  sequencer.addWriter(
90  std::make_shared<RootParticleWriter>(rootWriterCfg, logLevel));
91  }
92 
93  return sequencer.run();
94 }