source: HiSusy/trunk/hepmc/x86_64-slc5-gcc41-opt/share/HepMC/examples/pythia8/main32.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.9 KB
Line 
1// main32.cc is a part of the PYTHIA event generator.
2// Copyright (C) 2011 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// Input and output files are specified on the command line, e.g. like
9// ./main32.exe main32.cmnd hepmcout32.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.
12
13// WARNING: typically one needs 25 MB/100 events at the LHC.
14// Therefore large event samples may be impractical.
15
16#include "Pythia.h"
17#include "HepMCInterface.h"
18
19#include "HepMC/GenEvent.h"   
20#include "HepMC/IO_GenEvent.h"
21
22// Following line is a deprecated alternative, removed in recent versions.
23//#include "HepMC/IO_Ascii.h"
24//#include "HepMC/IO_AsciiParticles.h"
25
26// Following line to be used with HepMC 2.04 onwards.
27#ifdef HEPMC_HAS_UNITS
28#include "HepMC/Units.h"
29#endif
30
31using namespace Pythia8; 
32
33int main(int argc, char* argv[]) {
34
35  // Check that correct number of command-line arguments
36  if (argc != 3) {
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;
40    return 1;
41  }
42
43  // Check that the provided input name corresponds to an existing file.
44  ifstream is(argv[1]); 
45  if (!is) {
46    cerr << " Command-line file " << argv[1] << " was not found. \n"
47         << " Program stopped! " << endl;
48    return 1;
49  }
50
51  // Confirm that external files will be used for input and output.
52  cout << " PYTHIA settings will be read from file " << argv[1] << endl;
53  cout << " HepMC events will be written to file " << argv[2] << endl;
54
55  // Interface for conversion from Pythia8::Event to HepMC one.
56  HepMC::I_Pythia8 ToHepMC;
57  //  ToHepMC.set_crash_on_problem();
58
59  // Specify file where HepMC events will be stored.
60  HepMC::IO_GenEvent ascii_io(argv[2], std::ios::out);
61  // Following line is a deprecated alternative, removed in recent versions
62  // HepMC::IO_Ascii ascii_io("hepmcout32.dat", std::ios::out);
63  // Line below is an eye-readable one-way output, uncomment the include above
64  // HepMC::IO_AsciiParticles ascii_io("hepmcout32.dat", std::ios::out);
65 
66  // Generator.
67  Pythia pythia;
68
69  // Read in commands from external file.
70  pythia.readFile(argv[1]);   
71
72  // Extract settings to be used in the main program.
73  int    nEvent    = pythia.mode("Main:numberOfEvents");
74  int    nShow     = pythia.mode("Main:timesToShow");
75  int    nAbort    = pythia.mode("Main:timesAllowErrors");
76  bool   showCS    = pythia.flag("Main:showChangedSettings");
77  bool   showAS    = pythia.flag("Main:showAllSettings");
78  bool   showCPD   = pythia.flag("Main:showChangedParticleData");
79  bool   showAPD   = pythia.flag("Main:showAllParticleData");
80 
81  // Initialization. Beam parameters set in .cmnd file.
82  pythia.init();
83
84  // List settings.
85  if (showCS) pythia.settings.listChanged();
86  if (showAS) pythia.settings.listAll();
87
88  // List particle data. 
89  if (showCPD) pythia.particleData.listChanged();
90  if (showAPD) pythia.particleData.listAll();
91
92  // Begin event loop.
93  int nPace  = max(1, nEvent / max(1, nShow) ); 
94  int iAbort = 0; 
95  for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
96    if (nShow > 0 && iEvent%nPace == 0) 
97      cout << " Now begin event " << iEvent << endl;
98
99    // Generate event.
100    if (!pythia.next()) {
101
102      // If failure because reached end of file then exit event loop.
103      if (pythia.info.atEndOfFile()) {
104        cout << " Aborted since reached end of Les Houches Event File\n"; 
105        break; 
106      }
107
108      // First few failures write off as "acceptable" errors, then quit.
109      if (++iAbort < nAbort) continue;
110      cout << " Event generation aborted prematurely, owing to error!\n"; 
111      break;
112    }
113
114    // Construct new empty HepMC event.
115#ifdef HEPMC_HAS_UNITS
116    // This form with arguments is only meaningful for HepMC 2.04 onwards,
117    // and even then unnecessary if HepMC was built with GeV and mm as units..
118    HepMC::GenEvent* hepmcevt = new HepMC::GenEvent( 
119      HepMC::Units::GEV, HepMC::Units::MM);
120#else
121    // This form is needed for backwards compatibility.
122    // In HepMCInterface.cc a conversion from GeV to MeV will be done.
123    HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
124#endif
125
126    // Fill HepMC event, including PDF info.
127    ToHepMC.fill_next_event( pythia, hepmcevt );
128    // This alternative older method fills event, without PDF info.
129    // ToHepMC.fill_next_event( pythia.event, hepmcevt );
130
131    // Write the HepMC event to file. Done with it.
132    ascii_io << hepmcevt;
133    delete hepmcevt;
134
135  // End of event loop. Statistics.
136  }
137  pythia.statistics();
138
139  // Done.
140  return 0;
141}
Note: See TracBrowser for help on using the repository browser.