HepMC event record
pythia8_example.cc
1 /**
2  * @example pythia8_example.cc
3  * @brief Basic example of use for pythia8 interface
4  *
5  */
6 #include "HepMC/GenEvent.h"
7 #include "HepMC/WriterAscii.h"
8 #include "HepMC/Print.h"
9 
10 #include "Pythia8/Pythia.h"
11 #include "Pythia8/Pythia8ToHepMC3.h"
12 
13 #include <iostream>
14 using namespace HepMC;
15 
16 /** Main program */
17 int main(int argc, char **argv) {
18  if (argc < 3) {
19  cout << "Usage: " << argv[0] << " <pythia_config_file> <output_hepmc3_file>" << endl;
20  exit(-1);
21  }
22 
23  Pythia8::Pythia pythia;
24  Pythia8ToHepMC3 pythiaToHepMC;
25  pythia.readFile(argv[1]);
26  pythia.init();
27 
28  WriterAscii file(argv[2]);
29 
30  int nEvent = pythia.mode("Main:numberOfEvents");
31 
32  for( int i = 0; i< nEvent; ++i ) {
33  if( !pythia.next() ) continue;
34 
35  HepMC::GenEvent hepmc( Units::GEV, Units::MM );
36 
37  pythiaToHepMC.fill_next_event(pythia.event, &hepmc, -1, &pythia.info);
38 
39  if( i==0 ) {
40  std::cout << "First event: " << std::endl;
41  Print::listing(hepmc);
42  }
43 
44  file.write_event(hepmc);
45  }
46 
47  file.close();
48  pythia.stat();
49 }
static void listing(const GenEvent &event, unsigned short precision=2)
Print event in listing (HepMC2) format.
Definition: Print.cc:57
Stores event-related information.
GenEvent I/O serialization for structured text files.
int main(int argc, char **argv)
Definition of template class SmartPointer.