source: HiSusy/trunk/Pythia8/pythia8170/examples/main62.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.8 KB
Line 
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.
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 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.
14
15// WARNING: typically one needs 25 MB/100 events at the LHC.
16// Therefore large event samples may be impractical.
17
18#include "Pythia.h"
19#include "HepMCInterface.h"
20
21#include "HepMC/GenEvent.h"   
22#include "HepMC/IO_GenEvent.h"
23
24// Following line is a deprecated alternative, removed in recent versions.
25//#include "HepMC/IO_Ascii.h"
26//#include "HepMC/IO_AsciiParticles.h"
27
28// Following line to be used with HepMC 2.04 onwards.
29#ifdef HEPMC_HAS_UNITS
30#include "HepMC/Units.h"
31#endif
32
33using namespace Pythia8; 
34
35int main(int argc, char* argv[]) {
36
37  // Check that correct number of command-line arguments
38  if (argc != 3) {
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;
42    return 1;
43  }
44
45  // Check that the provided input name corresponds to an existing file.
46  ifstream is(argv[1]); 
47  if (!is) {
48    cerr << " Command-line file " << argv[1] << " was not found. \n"
49         << " Program stopped! " << endl;
50    return 1;
51  }
52
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;
57
58  // Interface for conversion from Pythia8::Event to HepMC one.
59  HepMC::I_Pythia8 ToHepMC;
60  //  ToHepMC.set_crash_on_problem();
61
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);
68 
69  // Generator.
70  Pythia pythia;
71
72  // Read in subrun-independent commands from external file.
73  pythia.readFile( argv[1]);   
74                         
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");
78  int iAbort  = 0;
79
80  // Begin loop over subruns.
81  for (int iSubrun = 1; iSubrun <= nSubrun; ++iSubrun) {
82 
83    // Read in subrun-specific data from external file.
84    pythia.readFile( argv[1], iSubrun); 
85
86    // Initialization.
87    pythia.init();
88
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"
93         << endl; 
94
95    // Begin infinite event loop - to be exited at end of file.
96    for (int iEvent = 0; ; ++iEvent) {
97
98      // Generate event.
99      if (!pythia.next()) {
100
101        // Leave event loop if at end of file.
102        if (pythia.info.atEndOfFile()) break;
103
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"; 
107        break;
108      }
109
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);
116#else
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();
120#endif
121
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 );
126
127      // Write the HepMC event to file. Done with it.
128      ascii_io << hepmcevt;
129      delete hepmcevt;
130
131    // End of event loop.
132    }
133 
134  // End of subrun loop.
135  }
136
137  // Statistics.
138  pythia.stat();
139
140  // Done.
141  return 0;
142}
Note: See TracBrowser for help on using the repository browser.