1 | // main32.cc is a part of the PYTHIA event generator. |
---|
2 | // Copyright (C) 2012 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 | // Author: Richard Corke (richard.corke@thep.lu.se) |
---|
7 | // This is a sample program showing the usage of: |
---|
8 | // AlpgenHooks: a UserHooks derived class provided by 'LHAupAlpgen.h' |
---|
9 | // for reading in ALPGEN format event files |
---|
10 | // MLMhooks: a UserHooks derived class provided by 'MLMhooks.h' |
---|
11 | // for performing the MLM merging procedure |
---|
12 | // Some user supplied options are available, made functional through |
---|
13 | // these two UserHooks, and are described in the 'Alpgen and MLM Merging' |
---|
14 | // manual page. Further details of the different classes provided |
---|
15 | // in these header files is also given on the manual page. |
---|
16 | |
---|
17 | // Includes and namespace |
---|
18 | #include "Pythia.h" |
---|
19 | #include "LHAupAlpgen.h" |
---|
20 | #include "MLMhooks.h" |
---|
21 | using namespace Pythia8; |
---|
22 | |
---|
23 | //========================================================================== |
---|
24 | |
---|
25 | // AlpgenAndMLMhooks: |
---|
26 | // A small UserHooks class that gives the functionality of |
---|
27 | // both AlpgenHooks and MLMhooks. These classes only have two |
---|
28 | // overlapping functions, the constructor and 'initAfterBeams()', |
---|
29 | // which are both overridden here such that both are called. |
---|
30 | |
---|
31 | class AlpgenAndMLMhooks : public AlpgenHooks, public MLMhooks { |
---|
32 | |
---|
33 | public: |
---|
34 | AlpgenAndMLMhooks(Pythia &pythia) |
---|
35 | : AlpgenHooks(pythia), MLMhooks() {} |
---|
36 | |
---|
37 | virtual bool initAfterBeams() { |
---|
38 | // Call init of both AlpgenHooks and MLMhooks (order important) |
---|
39 | if (!AlpgenHooks::initAfterBeams()) return false; |
---|
40 | if (!MLMhooks::initAfterBeams()) return false; |
---|
41 | return true; |
---|
42 | } |
---|
43 | }; |
---|
44 | |
---|
45 | //========================================================================== |
---|
46 | |
---|
47 | // Main program: initialise Pythia with AlpgenAndMLMhooks as above |
---|
48 | |
---|
49 | int main() { |
---|
50 | |
---|
51 | // Generator and read in commands |
---|
52 | Pythia pythia; |
---|
53 | pythia.readFile("main32.cmnd"); |
---|
54 | |
---|
55 | // Extract settings to be used in the main program. |
---|
56 | int nEvent = pythia.mode("Main:numberOfEvents"); |
---|
57 | int nAbort = pythia.mode("Main:timesAllowErrors"); |
---|
58 | |
---|
59 | // Create AlpgenAndMLMhooks class and pass to Pythia |
---|
60 | UserHooks *alpgenAndMLMhooks = new AlpgenAndMLMhooks(pythia); |
---|
61 | pythia.setUserHooksPtr(alpgenAndMLMhooks); |
---|
62 | |
---|
63 | // Initialise Pythia |
---|
64 | if (!pythia.init()) { |
---|
65 | cout << "Error: could not initialise Pythia" << endl; |
---|
66 | return 1; |
---|
67 | }; |
---|
68 | |
---|
69 | // Begin event loop. |
---|
70 | int iAbort = 0, iEvent = 0; |
---|
71 | for (; ; ++iEvent) { |
---|
72 | // Check if iEvent > nEvent |
---|
73 | if (nEvent > 0 && iEvent >= nEvent) break; |
---|
74 | |
---|
75 | // Generate events. Quit if many failures. |
---|
76 | if (!pythia.next()) { |
---|
77 | if (pythia.info.atEndOfFile()) { |
---|
78 | cout << "Info: end of input file reached" << endl; |
---|
79 | break; |
---|
80 | } |
---|
81 | if (++iAbort < nAbort) continue; |
---|
82 | cout << "Abort: too many errors in generation" << endl; |
---|
83 | break; |
---|
84 | } |
---|
85 | |
---|
86 | // Event analysis here |
---|
87 | |
---|
88 | // End of event loop. |
---|
89 | } |
---|
90 | |
---|
91 | // Final statistics. |
---|
92 | pythia.stat(); |
---|
93 | |
---|
94 | // Clean up and done. |
---|
95 | delete alpgenAndMLMhooks; |
---|
96 | return 0; |
---|
97 | } |
---|