StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main32.cc
1 // main32.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2014 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 sample program showing Alpgen- or Madgraph-style MLM matching
7 // for Madgraph LHEF or native Alpgen format event files.
8 //
9 // Please see the 'Jet Matching Style' manual page for a description of the
10 // parameters and user options.
11 
12 // Includes and namespace
13 #include "Pythia8/Pythia.h"
14 #include "CombineMatchingInput.h"
15 using namespace Pythia8;
16 
17 //==========================================================================
18 
19 int main() {
20 
21  // Generator and read in commands.
22  Pythia pythia;
23  pythia.readFile("main32.cmnd");
24 
25  // Extract settings to be used in the main program.
26  int nEvent = pythia.mode("Main:numberOfEvents");
27  int nAbort = pythia.mode("Main:timesAllowErrors");
28  int nSkip = pythia.mode("Main:spareMode1");
29 
30  // Create UserHooks pointer. Stop if it failed. Pass pointer to Pythia.
31  CombineMatchingInput combined;
32  UserHooks* matching = combined.getHook(pythia);
33  if (!matching) return 1;
34  pythia.setUserHooksPtr(matching);
35 
36  // Initialise Pythia.
37  if (!pythia.init()) {
38  cout << "Error: could not initialise Pythia" << endl;
39  return 1;
40  };
41 
42  // Optionally skip ahead in LHEF.
43  pythia.LHAeventSkip( nSkip );
44 
45  // Begin event loop. Optionally quit it before end of file.
46  int iAbort = 0;
47  for (int iEvent = 0; ; ++iEvent) {
48  if (nEvent > 0 && iEvent >= nEvent) break;
49 
50  // Generate events. Quit if at end of file or many failures.
51  if (!pythia.next()) {
52  if (pythia.info.atEndOfFile()) {
53  cout << "Info: end of input file reached" << endl;
54  break;
55  }
56  if (++iAbort < nAbort) continue;
57  cout << "Abort: too many errors in generation" << endl;
58  break;
59  }
60 
61  // Event analysis goes here.
62 
63  // End of event loop.
64  }
65 
66  // Final statistics and done.
67  pythia.stat();
68  delete matching;
69 
70  return 0;
71 }