Basic example of use for pythia8 interface.
#include "Pythia8/Pythia.h"
#ifdef HEPMC3_USE_INTERFACE_FROM_PYTHIA8
#include "Pythia8Plugins/HepMC3.h"
#else
#include "Pythia8ToHepMC3.h"
#endif
#include <iostream>
int main(int argc, char **argv) {
if (argc < 3) {
std::cout << "Usage: " << argv[0] << " <pythia_config_file> <output_hepmc3_file>" << std::endl;
exit(-1);
}
Pythia8::Pythia pythia;
pythia.readFile(argv[1]);
pythia.init();
std::shared_ptr<GenRunInfo> run = std::make_shared<GenRunInfo>();
struct GenRunInfo::ToolInfo generator={std::string(
"Pythia8"),std::to_string(PYTHIA_VERSION).substr(0,5),std::string(
"Used generator")};
run->tools().push_back(generator);
run->tools().push_back(config);
std::vector<std::string> names;
for (int iWeight=0; iWeight < pythia.info.nWeights(); ++iWeight) {
std::string s=pythia.info.weightLabel(iWeight);
if (!s.length()) s=std::to_string((long long int)iWeight);
names.push_back(s);
}
if (!names.size()) names.push_back("default");
run->set_weight_names(names);
int nEvent = pythia.mode("Main:numberOfEvents");
for( int i = 0; i< nEvent; ++i ) {
if( !pythia.next() ) continue;
GenEvent hepmc( Units::GEV, Units::MM );
pythiaToHepMC.
fill_next_event(pythia.event, &hepmc, -1, &pythia.info);
if( i==0 ) {
std::cout << "First event: " << std::endl;
Print::listing(hepmc);
}
}
pythia.stat();
}
Definition of class GenEvent.
Definition of static class Print.
Definition of class WriterAscii.
Stores event-related information.
GenEvent I/O serialization for structured text files.
void close() override
Close file stream.
void write_event(const GenEvent &evt) override
Write event to file.