1 // main51.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2010 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.
6 // This is a simple test program illustrating how to link in Pythia 6.4
7 // for the generation of hard processes. That part is now considered
8 // obsolete, but for some debug work this example has been collected
9 // from various code pieces that were separately available up until
10 // Pythia 8.125. In addition to modifying the below code to fit your
11 // needs, you also have to modify examples/Makefile to link properly
12 // for main51, including the Pythia 6.4xx library to be used (where
13 // xx is the current subversion number).
15 // All hard PYTHIA 6.4 processes should be available for full generation
16 // in PYTHIA 8, at least to the extent that they are defined for p p,
17 // pbar p or e+ e-collisions. Soft processes, i.e. elastic and diffractive
18 // scattering, as well as minimum-bias events, require a different
19 // kinematics machinery, and can only be generated with the internal
20 // PYTHIA 8 processes.
22 // PYTHIA 6.4 does its own rejection of events internally, according to
23 // the strategy option 3. However, the current runtime interface does not
24 // take cross-section information from PYTHIA 6.4. This means that both
25 // the initial maxima and the final cross sections printed by the PYTHIA 8
26 // routines are irrelevant in this case. Instead you have to study the
27 // standard PYTHIA 6.4 initialization printout and call on pystat(...)
28 // at the end of the run to obtain this information. It also means that
29 // you cannot mix with internally generated PYTHIA 8 events.
31 //==========================================================================
34 #include "LHAFortran.h"
36 using namespace Pythia8;
38 //==========================================================================
40 // Declare the Fortran subroutines that may be used.
41 // This code section is generic.
44 #define pygive_ PYGIVE
45 #define pyinit_ PYINIT
46 #define pyupin_ PYUPIN
47 #define pyupev_ PYUPEV
48 #define pylist_ PYLIST
49 #define pystat_ PYSTAT
54 extern void pyinit_(const char*, int, const char*, int, const char*, int, double&);
56 extern void pyinit_(const char*, const char*, const char*, double&, int, int, int);
61 extern void pygive_(const char*, int);
62 extern void pyupin_();
63 extern void pyupev_();
64 extern void pylist_(int&);
65 extern void pystat_(int&);
68 //==========================================================================
70 // Interfaces to the above routines, to make the C++ calls similar to Fortran.
71 // This code section is generic.
73 class Pythia6Interface {
77 // Give in a command to change a setting.
78 static void pygive(const string cmnd) {
79 const char* cstring = cmnd.c_str(); int len = cmnd.length();
80 pygive_(cstring, len);
83 // Initialize the generation for the given beam confiuration.
84 static void pyinit(const string frame, const string beam,
85 const string target, double wIn) {
86 const char* cframe = frame.c_str(); int lenframe = frame.length();
87 const char* cbeam = beam.c_str(); int lenbeam = beam.length();
88 const char* ctarget = target.c_str(); int lentarget = target.length();
90 pyinit_(cframe, lenframe, cbeam, lenbeam, ctarget, lentarget, wIn);
92 pyinit_(cframe, cbeam, ctarget, wIn, lenframe, lenbeam, lentarget);
96 // Fill the initialization information in the HEPRUP commonblock.
97 static void pyupin() {pyupin_();}
99 // Generate the next hard process and
100 // fill the event information in the HEPEUP commonblock
101 static void pyupev() {pyupev_();}
103 // List the event at the process level.
104 static void pylist(int mode) {pylist_(mode);}
106 // Print statistics on the event generation process.
107 static void pystat(int mode) {pystat_(mode);}
111 //==========================================================================
113 // Implement initialization fillHepRup method for Pythia6 example.
114 // This code section is specific to the kind of precesses you generate.
116 // Of all parameters that could be set with pygive, only those that
117 // influence the generation of the hard processes have any impact,
118 // since this is the only part of the Fortran code that is used.
120 bool LHAupFortran::fillHepRup() {
122 // Set process to generate.
123 // Example 1: QCD production; must set pTmin.
124 //Pythia6Interface::pygive("msel = 1");
125 //Pythia6Interface::pygive("ckin(3) = 20.");
126 // Example 2: t-tbar production.
127 //Pythia6Interface::pygive("msel = 6");
128 // Example 3: Z0 production; must set mMin.
129 Pythia6Interface::pygive("msel = 11");
130 Pythia6Interface::pygive("ckin(1) = 50.");
132 // Speed up initialization: multiple interactions only in C++ code.
133 Pythia6Interface::pygive("mstp(81)=0");
135 // Initialize for 14 TeV pp collider.
136 Pythia6Interface::pyinit("cms","p","p",14000.);
138 // Fill initialization information in HEPRUP.
139 Pythia6Interface::pyupin();
146 //==========================================================================
148 // Implement event generation fillHepEup method for Pythia 6 example.
149 // This code section is generic.
151 bool LHAupFortran::fillHepEup() {
153 // Generate and fill the next Pythia6 event in HEPEUP.
154 Pythia6Interface::pyupev();
161 //==========================================================================
164 // This code section is specific to the physics study you want to do.
168 // Generator. Shorthand for the event and for settings.
170 Event& event = pythia.event;
171 Settings& settings = pythia.settings;
173 // Set Pythia8 generation aspects.
174 pythia.readString("BeamRemnants:primordialKThard = 2.");
175 pythia.readString("MultipleInteractions:bProfile = 3");
177 // Initialize to access Pythia6 generator by Les Houches interface.
178 LHAupFortran pythia6;
179 pythia.init(&pythia6);
181 // Set some generation values.
186 // List changed settings data.
187 settings.listChanged();
191 double epTol = 1e-7 * eCM;
192 Hist epCons("deviation from energy-momentum conservation",100,0.,epTol);
193 Hist nFinal("final particle multiplicity",100,-0.5,1599.5);
194 Hist nChg("final charged multiplicity",100,-0.5,799.5);
198 for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
200 // Generate events. Quit if too many failures.
201 if (!pythia.next()) {
202 if (++iAbort < nAbort) continue;
203 cout << " Event generation aborted prematurely, owing to error!\n";
207 // List first few events, both hard process and complete events.
208 if (iEvent < nList) {
210 // This call to Pythia6 is superfluous, but shows it can be done.
211 Pythia6Interface::pylist(1);
212 pythia.process.list();
216 // Reset quantities to be summed over event.
219 Vec4 pSum = - (event[1].p() + event[2].p());
221 // Loop over final particles in the event.
222 for (int i = 0; i < event.size(); ++i)
223 if (event[i].isFinal()) {
225 if (event[i].isCharged()) ++nch;
226 pSum += event[i].p();
229 // Fill summed quantities.
230 double epDev = abs(pSum.e()) + abs(pSum.px()) + abs(pSum.py())
236 // End of event loop.
239 // Final statistics. Must do call to Pythia6 explicitly.
241 Pythia6Interface::pystat(1);
244 cout << epCons << nFinal<< nChg;