00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "Pythia.h"
00017 #include "HepMCInterface.h"
00018
00019 #include "HepMC/GenEvent.h"
00020 #include "HepMC/IO_GenEvent.h"
00021
00022
00023
00024
00025
00026
00027 #ifdef HEPMC_HAS_UNITS
00028 #include "HepMC/Units.h"
00029 #endif
00030
00031 using namespace Pythia8;
00032
00033 int main(int argc, char* argv[]) {
00034
00035
00036 if (argc != 3) {
00037 cerr << " Unexpected number of command-line arguments. \n You are"
00038 << " expected to provide one input and one output file name. \n"
00039 << " Program stopped! " << endl;
00040 return 1;
00041 }
00042
00043
00044 ifstream is(argv[1]);
00045 if (!is) {
00046 cerr << " Command-line file " << argv[1] << " was not found. \n"
00047 << " Program stopped! " << endl;
00048 return 1;
00049 }
00050
00051
00052 cout << " PYTHIA settings will be read from file " << argv[1] << endl;
00053 cout << " HepMC events will be written to file " << argv[2] << endl;
00054
00055
00056 HepMC::I_Pythia8 ToHepMC;
00057
00058
00059
00060 HepMC::IO_GenEvent ascii_io(argv[2], std::ios::out);
00061
00062
00063
00064
00065
00066
00067 Pythia pythia;
00068
00069
00070 pythia.readFile(argv[1]);
00071
00072
00073 int nEvent = pythia.mode("Main:numberOfEvents");
00074 int nShow = pythia.mode("Main:timesToShow");
00075 int nAbort = pythia.mode("Main:timesAllowErrors");
00076 bool showCS = pythia.flag("Main:showChangedSettings");
00077 bool showAS = pythia.flag("Main:showAllSettings");
00078 bool showCPD = pythia.flag("Main:showChangedParticleData");
00079 bool showAPD = pythia.flag("Main:showAllParticleData");
00080
00081
00082 pythia.init();
00083
00084
00085 if (showCS) pythia.settings.listChanged();
00086 if (showAS) pythia.settings.listAll();
00087
00088
00089 if (showCPD) pythia.particleData.listChanged();
00090 if (showAPD) pythia.particleData.listAll();
00091
00092
00093 int nPace = max(1, nEvent / max(1, nShow) );
00094 int iAbort = 0;
00095 for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
00096 if (nShow > 0 && iEvent%nPace == 0)
00097 cout << " Now begin event " << iEvent << endl;
00098
00099
00100 if (!pythia.next()) {
00101
00102
00103 if (pythia.info.atEndOfFile()) {
00104 cout << " Aborted since reached end of Les Houches Event File\n";
00105 break;
00106 }
00107
00108
00109 if (++iAbort < nAbort) continue;
00110 cout << " Event generation aborted prematurely, owing to error!\n";
00111 break;
00112 }
00113
00114
00115 #ifdef HEPMC_HAS_UNITS
00116
00117
00118 HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(
00119 HepMC::Units::GEV, HepMC::Units::MM);
00120 #else
00121
00122
00123 HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
00124 #endif
00125
00126
00127 ToHepMC.fill_next_event( pythia, hepmcevt );
00128
00129
00130
00131
00132 ascii_io << hepmcevt;
00133 delete hepmcevt;
00134
00135
00136 }
00137 pythia.statistics();
00138
00139
00140 return 0;
00141 }