1
// main42.cc is a part of the PYTHIA event generator.
2
// Copyright (C) 2012 Mikhail Kirsanov, Torbjorn Sjostrand.
3
// PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
4
// Please respect the MCnet Guidelines, see GUIDELINES for details.
6
// This is a simple test program.
7
// It illustrates how a file with HepMC events can be generated by Pythia8.
8
// Input and output files are specified on the command line, e.g. like
9
// ./main42.exe main42.cmnd hepmcout41.dat > out
10
// The main program contains no analysis; this is intended to happen later.
11
// It therefore "never" has to be recompiled to handle different tasks.
13
// WARNING: typically one needs 25 MB/100 events at the LHC.
14
// Therefore large event samples may be impractical.
17
#include "HepMCInterface.h"
19
#include "HepMC/GenEvent.h"
20
#include "HepMC/IO_GenEvent.h"
22
// Following line is a deprecated alternative, removed in recent versions.
23
//#include "HepMC/IO_Ascii.h"
24
//#include "HepMC/IO_AsciiParticles.h"
26
// Following line to be used with HepMC 2.04 onwards.
27
#ifdef HEPMC_HAS_UNITS
28
#include "HepMC/Units.h"
31
using namespace Pythia8;
33
int main(int argc, char* argv[]) {
35
// Check that correct number of command-line arguments
37
cerr << " Unexpected number of command-line arguments. \n You are"
38
<< " expected to provide one input and one output file name. \n"
39
<< " Program stopped! " << endl;
43
// Check that the provided input name corresponds to an existing file.
46
cerr << " Command-line file " << argv[1] << " was not found. \n"
47
<< " Program stopped! " << endl;
51
// Confirm that external files will be used for input and output.
52
cout << "\n >>> PYTHIA settings will be read from file " << argv[1]
53
<< " <<< \n >>> HepMC events will be written to file "
54
<< argv[2] << " <<< \n" << endl;
56
// Interface for conversion from Pythia8::Event to HepMC one.
57
HepMC::I_Pythia8 ToHepMC;
58
// ToHepMC.set_crash_on_problem();
60
// Specify file where HepMC events will be stored.
61
HepMC::IO_GenEvent ascii_io(argv[2], std::ios::out);
62
// Following line is a deprecated alternative, removed in recent versions
63
// HepMC::IO_Ascii ascii_io("hepmcout32.dat", std::ios::out);
64
// Line below is an eye-readable one-way output, uncomment the include above
65
// HepMC::IO_AsciiParticles ascii_io("hepmcout32.dat", std::ios::out);
70
// Read in commands from external file.
71
pythia.readFile(argv[1]);
73
// Extract settings to be used in the main program.
74
int nEvent = pythia.mode("Main:numberOfEvents");
75
int nAbort = pythia.mode("Main:timesAllowErrors");
82
for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
87
// If failure because reached end of file then exit event loop.
88
if (pythia.info.atEndOfFile()) {
89
cout << " Aborted since reached end of Les Houches Event File\n";
93
// First few failures write off as "acceptable" errors, then quit.
94
if (++iAbort < nAbort) continue;
95
cout << " Event generation aborted prematurely, owing to error!\n";
99
// Construct new empty HepMC event.
100
#ifdef HEPMC_HAS_UNITS
101
// This form with arguments is only meaningful for HepMC 2.04 onwards,
102
// and even then unnecessary if HepMC was built with GeV and mm as units.
103
HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(
104
HepMC::Units::GEV, HepMC::Units::MM);
106
// This form is needed for backwards compatibility.
107
// In HepMCInterface.cc a conversion from GeV to MeV will be done.
108
HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
111
// Fill HepMC event, including PDF info.
112
ToHepMC.fill_next_event( pythia, hepmcevt );
113
// This alternative older method fills event, without PDF info.
114
// ToHepMC.fill_next_event( pythia.event, hepmcevt );
116
// Write the HepMC event to file. Done with it.
117
ascii_io << hepmcevt;
120
// End of event loop. Statistics.