|
| 1 | +// configures a TPythia6 class |
| 2 | +// usage: o2sim -g external --configKeyValues 'GeneratorExternal.fileName=pythia6.C;GeneratorExternal.funcName="pythia6(14000., "pythia.settings")"' |
| 3 | + |
| 4 | +/// \author R+Preghenella - October 2018 |
| 5 | + |
| 6 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 7 | +#include "TPythia6.h" |
| 8 | +#include "FairGenerator.h" |
| 9 | +#include "Generators/GeneratorTGenerator.h" |
| 10 | +#include <fstream> |
| 11 | +#include <iostream> |
| 12 | +#endif |
| 13 | + |
| 14 | +R__LOAD_LIBRARY(libpythia6) |
| 15 | + |
| 16 | +void configure(TPythia6* py6, const char* params); |
| 17 | + |
| 18 | +FairGenerator* |
| 19 | + pythia6(double energy = 14000., const char* params = nullptr) |
| 20 | +{ |
| 21 | + // instance and configure Pythia6 |
| 22 | + auto py6 = TPythia6::Instance(); |
| 23 | + if (params) |
| 24 | + configure(py6, params); |
| 25 | + py6->Initialize("CMS", "p", "p", energy); |
| 26 | + |
| 27 | + // instance and configure TGenerator interface |
| 28 | + auto tgen = new o2::eventgen::GeneratorTGenerator(); |
| 29 | + tgen->setMomentumUnit(1.); // [GeV/c] |
| 30 | + tgen->setEnergyUnit(1.); // [GeV/c] |
| 31 | + tgen->setPositionUnit(0.1); // [cm] |
| 32 | + tgen->setTimeUnit(3.3356410e-12); // [s] |
| 33 | + tgen->setTGenerator(py6); |
| 34 | + return tgen; |
| 35 | +} |
| 36 | + |
| 37 | +void configure(TPythia6* py6, const char* params) |
| 38 | +{ |
| 39 | + std::ifstream file(params); |
| 40 | + if (!file.is_open()) { |
| 41 | + std::cerr << "Cannot open configuration file: " << params << std::endl; |
| 42 | + return; |
| 43 | + }; |
| 44 | + std::string line, command; |
| 45 | + while (std::getline(file, line)) { |
| 46 | + /** remove comments **/ |
| 47 | + command = line.substr(0, line.find_first_of("#")); |
| 48 | + if (command.length() == 0) |
| 49 | + continue; |
| 50 | + py6->Pygive(command.c_str()); |
| 51 | + } |
| 52 | + file.close(); |
| 53 | +} |
0 commit comments