source: HiSusy/trunk/Pythia8/pythia8170/examples/main61.cc @ 1

Last change on this file since 1 was 1, checked in by zerwas, 11 years ago

first import of structure, PYTHIA8 and DELPHES

File size: 4.3 KB
Line 
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.
5
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.
13
14// WARNING: typically one needs 25 MB/100 events at the LHC.
15// Therefore large event samples may be impractical.
16
17#include "Pythia.h"
18#include "HepMCInterface.h"
19
20#include "HepMC/GenEvent.h"   
21#include "HepMC/IO_GenEvent.h"
22
23// Following line is a deprecated alternative, removed in recent versions.
24//#include "HepMC/IO_Ascii.h"
25//#include "HepMC/IO_AsciiParticles.h"
26
27// Following line to be used with HepMC 2.04 onwards.
28#ifdef HEPMC_HAS_UNITS
29#include "HepMC/Units.h"
30#endif
31
32using namespace Pythia8; 
33
34int main(int argc, char* argv[]) {
35
36  // Check that correct number of command-line arguments
37  if (argc != 3) {
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;
41    return 1;
42  }
43
44  // Check that the provided input name corresponds to an existing file.
45  ifstream is(argv[1]); 
46  if (!is) {
47    cerr << " Command-line file " << argv[1] << " was not found. \n"
48         << " Program stopped! " << endl;
49    return 1;
50  }
51
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;
56
57  // Interface for conversion from Pythia8::Event to HepMC one.
58  HepMC::I_Pythia8 ToHepMC;
59  //  ToHepMC.set_crash_on_problem();
60
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);
67 
68  // Generator.
69  Pythia pythia;
70
71  // Read in commands from external file.
72  pythia.readFile(argv[1]);   
73
74  // Extract settings to be used in the main program.
75  int    nEvent    = pythia.mode("Main:numberOfEvents");
76  int    nAbort    = pythia.mode("Main:timesAllowErrors");
77 
78  // Initialization.
79  pythia.init();
80
81  // Begin event loop.
82  int iAbort = 0; 
83  for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
84
85    // Generate event.
86    if (!pythia.next()) {
87
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"; 
91        break; 
92      }
93
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"; 
97      break;
98    }
99
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);
106#else
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();
110#endif
111
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 );
116
117    // Write the HepMC event to file. Done with it.
118    ascii_io << hepmcevt;
119    delete hepmcevt;
120
121  // End of event loop. Statistics.
122  }
123  pythia.stat();
124
125  // Done.
126  return 0;
127}
Note: See TracBrowser for help on using the repository browser.