1 // main61.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 identical with main42, except that it is compiled with LHAPDF.
9 // Input and output files are specified on the command line, e.g. like
10 // ./main61.exe main61.cmnd hepmcout61.dat > out
11 // The main program contains no analysis; this is intended to happen later.
12 // It therefore "never" has to be recompiled to handle different tasks.
14 // WARNING: typically one needs 25 MB/100 events at the LHC.
15 // Therefore large event samples may be impractical.
18 #include "HepMCInterface.h"
20 #include "HepMC/GenEvent.h"
21 #include "HepMC/IO_GenEvent.h"
23 // Following line is a deprecated alternative, removed in recent versions.
24 //#include "HepMC/IO_Ascii.h"
25 //#include "HepMC/IO_AsciiParticles.h"
27 // Following line to be used with HepMC 2.04 onwards.
28 #ifdef HEPMC_HAS_UNITS
29 #include "HepMC/Units.h"
32 using namespace Pythia8;
34 int main(int argc, char* argv[]) {
36 // Check that correct number of command-line arguments
38 cerr << " Unexpected number of command-line arguments. \n You are"
39 << " expected to provide one input and one output file name. \n"
40 << " Program stopped! " << endl;
44 // Check that the provided input name corresponds to an existing file.
47 cerr << " Command-line file " << argv[1] << " was not found. \n"
48 << " Program stopped! " << endl;
52 // Confirm that external files will be used for input and output.
53 cout << "\n >>> PYTHIA settings will be read from file " << argv[1]
54 << " <<< \n >>> HepMC events will be written to file "
55 << argv[2] << " <<< \n" << endl;
57 // Interface for conversion from Pythia8::Event to HepMC one.
58 HepMC::I_Pythia8 ToHepMC;
59 // ToHepMC.set_crash_on_problem();
61 // Specify file where HepMC events will be stored.
62 HepMC::IO_GenEvent ascii_io(argv[2], std::ios::out);
63 // Following line is a deprecated alternative, removed in recent versions
64 // HepMC::IO_Ascii ascii_io("hepmcout32.dat", std::ios::out);
65 // Line below is an eye-readable one-way output, uncomment the include above
66 // HepMC::IO_AsciiParticles ascii_io("hepmcout32.dat", std::ios::out);
71 // Read in commands from external file.
72 pythia.readFile(argv[1]);
74 // Extract settings to be used in the main program.
75 int nEvent = pythia.mode("Main:numberOfEvents");
76 int nAbort = pythia.mode("Main:timesAllowErrors");
83 for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
88 // If failure because reached end of file then exit event loop.
89 if (pythia.info.atEndOfFile()) {
90 cout << " Aborted since reached end of Les Houches Event File\n";
94 // First few failures write off as "acceptable" errors, then quit.
95 if (++iAbort < nAbort) continue;
96 cout << " Event generation aborted prematurely, owing to error!\n";
100 // Construct new empty HepMC event.
101 #ifdef HEPMC_HAS_UNITS
102 // This form with arguments is only meaningful for HepMC 2.04 onwards,
103 // and even then unnecessary if HepMC was built with GeV and mm as units.
104 HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(
105 HepMC::Units::GEV, HepMC::Units::MM);
107 // This form is needed for backwards compatibility.
108 // In HepMCInterface.cc a conversion from GeV to MeV will be done.
109 HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
112 // Fill HepMC event, including PDF info.
113 ToHepMC.fill_next_event( pythia, hepmcevt );
114 // This alternative older method fills event, without PDF info.
115 // ToHepMC.fill_next_event( pythia.event, hepmcevt );
117 // Write the HepMC event to file. Done with it.
118 ascii_io << hepmcevt;
121 // End of event loop. Statistics.