1
// main62.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
// It is similar to main42, except that it is compiled with LHAPDF
9
// and allows for several subruns, e.g. from related LHEF.
10
// Input and output files are specified on the command line, e.g. like
11
// ./main62.exe main62.cmnd hepmcout62.dat > out
12
// The main program contains no analysis; this is intended to happen later.
13
// It therefore "never" has to be recompiled to handle different tasks.
15
// WARNING: typically one needs 25 MB/100 events at the LHC.
16
// Therefore large event samples may be impractical.
19
#include "HepMCInterface.h"
21
#include "HepMC/GenEvent.h"
22
#include "HepMC/IO_GenEvent.h"
24
// Following line is a deprecated alternative, removed in recent versions.
25
//#include "HepMC/IO_Ascii.h"
26
//#include "HepMC/IO_AsciiParticles.h"
28
// Following line to be used with HepMC 2.04 onwards.
29
#ifdef HEPMC_HAS_UNITS
30
#include "HepMC/Units.h"
33
using namespace Pythia8;
35
int main(int argc, char* argv[]) {
37
// Check that correct number of command-line arguments
39
cerr << " Unexpected number of command-line arguments. \n You are"
40
<< " expected to provide one input and one output file name. \n"
41
<< " Program stopped! " << endl;
45
// Check that the provided input name corresponds to an existing file.
48
cerr << " Command-line file " << argv[1] << " was not found. \n"
49
<< " Program stopped! " << endl;
53
// Confirm that external files will be used for input and output.
54
cout << "\n >>> PYTHIA settings will be read from file " << argv[1]
55
<< " <<< \n >>> HepMC events will be written to file "
56
<< argv[2] << " <<< \n" << endl;
58
// Interface for conversion from Pythia8::Event to HepMC one.
59
HepMC::I_Pythia8 ToHepMC;
60
// ToHepMC.set_crash_on_problem();
62
// Specify file where HepMC events will be stored.
63
HepMC::IO_GenEvent ascii_io(argv[2], std::ios::out);
64
// Following line is a deprecated alternative, removed in recent versions
65
// HepMC::IO_Ascii ascii_io("hepmcout32.dat", std::ios::out);
66
// Line below is an eye-readable one-way output, uncomment the include above
67
// HepMC::IO_AsciiParticles ascii_io("hepmcout32.dat", std::ios::out);
72
// Read in subrun-independent commands from external file.
73
pythia.readFile( argv[1]);
75
// Extract data to be used in main program. Set counters.
76
int nSubrun = pythia.mode("Main:numberOfSubruns");
77
int nAbort = pythia.mode("Main:timesAllowErrors");
80
// Begin loop over subruns.
81
for (int iSubrun = 1; iSubrun <= nSubrun; ++iSubrun) {
83
// Read in subrun-specific data from external file.
84
pythia.readFile( argv[1], iSubrun);
89
// Print name of Les Houches Event File.
90
string lheFile = pythia.settings.word("Beams:LHEF");
91
cout << "\n >>> Now begin subrun " << iSubrun
92
<< " with events from file " << lheFile << " <<< \n"
95
// Begin infinite event loop - to be exited at end of file.
96
for (int iEvent = 0; ; ++iEvent) {
101
// Leave event loop if at end of file.
102
if (pythia.info.atEndOfFile()) break;
104
// First few failures write off as "acceptable" errors, then quit.
105
if (++iAbort < nAbort) continue;
106
cout << " Event generation aborted prematurely, owing to error!\n";
110
// Construct new empty HepMC event.
111
#ifdef HEPMC_HAS_UNITS
112
// This form with arguments is only meaningful for HepMC 2.04 onwards,
113
// and even then unnecessary if HepMC was built with GeV and mm as units.
114
HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(
115
HepMC::Units::GEV, HepMC::Units::MM);
117
// This form is needed for backwards compatibility.
118
// In HepMCInterface.cc a conversion from GeV to MeV will be done.
119
HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
122
// Fill HepMC event, including PDF info.
123
ToHepMC.fill_next_event( pythia, hepmcevt );
124
// This alternative older method fills event, without PDF info.
125
// ToHepMC.fill_next_event( pythia.event, hepmcevt );
127
// Write the HepMC event to file. Done with it.
128
ascii_io << hepmcevt;
131
// End of event loop.
134
// End of subrun loop.