StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LHAPowheg.h
1 // LHAPowheg.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2018 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 // Author: Philip Ilten, May 2015.
6 
7 #ifndef Pythia8_LHAPowheg_H
8 #define Pythia8_LHAPowheg_H
9 
10 #include "Pythia8Plugins/LHAFortran.h"
11 #include <sys/stat.h>
12 #include <unistd.h>
13 
14 namespace Pythia8 {
15 
16 //==========================================================================
17 
18 // Give access to the POWHEG commonblocks and subroutines.
19 
20 extern "C" {
21 
22  // The random number common block.
23  extern struct {
24  int rnd_numseeds, rnd_initialseed, rnd_iwhichseed;
25  char rnd_cwhichseed[4];
26  int rnd_i1, rnd_i2;
27  } pwhg_rnd_;
28 
29  // The RANMAR (R48 modification) common block.
30  extern struct {
31  double u[97];
32  double c;
33  int i97, j97;
34  } r48st1_;
35 
36  // Initialize Powheg.
37  void pwhginit_();
38 
39  // Reset the counters.
40  void resetcnt_(const char *string, int length);
41 
42  // Generate an event.
43  void pwhgevent_();
44 
45  // Access Powheg input data.
46  double powheginput_(const char *string, int length);
47 
48 }
49 
50 //==========================================================================
51 
52 // A derived class from LHAupFortran which allows a POWHEGBOX binary
53 // to be directly interfaced with Pythia via a plugin structure. The
54 // class PowhegProcs handles the loading of these plugin libraries.
55 
56 class LHAupPowheg : public LHAupFortran {
57 
58 public:
59 
60  // Constructor.
61  LHAupPowheg(Pythia *pythiaIn);
62 
63 protected:
64 
65  // Call pwhginit and fill the HEPRUP commonblock.
66  bool fillHepRup();
67 
68  // Call pwhgevent and fill the HEEUP commonblock.
69  bool fillHepEup();
70 
71 private:
72 
73  // The PYTHIA object.
74  Pythia *pythia;
75 
76  // The run directory.
77  string dir;
78 
79  // Flag to reset the random number generator from Pythia.
80  bool random;
81 
82  // The current working directory.
83  char cwd[FILENAME_MAX];
84 
85 };
86 
87 //--------------------------------------------------------------------------
88 
89 // Constructor.
90 
91 LHAupPowheg::LHAupPowheg(Pythia *pythiaIn) : dir("./") {
92 
93  pythia = pythiaIn;
94  if (pythia && pythia->settings.isWord("POWHEG:dir"))
95  dir = pythia->settings.word("POWHEG:dir");
96  if (pythia && pythia->settings.isFlag("POWHEG:pythiaRandom"))
97  random = pythia->settings.flag("POWHEG:pythiaRandom");
98  mkdir(dir.c_str(), 0777);
99 
100 }
101 
102 //--------------------------------------------------------------------------
103 
104 // Call pwhginit and fill the HEPRUP commonblock.
105 
106 bool LHAupPowheg::fillHepRup() {
107 
108  // Set multiple random seeds to none.
109  if (!pythia) return false;
110  getcwd(cwd, sizeof(cwd));
111  chdir(dir.c_str());
112  strcpy(pwhg_rnd_.rnd_cwhichseed, "none");
113 
114  // Initialize Powheg.
115  pwhginit_();
116 
117  // Reset all the counters.
118  resetcnt_("upper bound failure in inclusive cross section", 46);
119  resetcnt_("vetoed calls in inclusive cross section", 39);
120  resetcnt_("upper bound failures in generation of radiation", 47);
121  resetcnt_("vetoed radiation", 16);
122  chdir(cwd);
123  return fillHepEup();
124 
125 }
126 
127 //--------------------------------------------------------------------------
128 
129 // Set the random numbers, call pwhgevent, and fill the HEPEUP commonblock.
130 
131 bool LHAupPowheg::fillHepEup() {
132 
133  // Change directory.
134  if (!pythia) return false;
135  getcwd(cwd, sizeof(cwd));
136  chdir(dir.c_str());
137 
138  // Reset the random block if requested.
139  if (random) {
140  r48st1_.i97 = 97;
141  r48st1_.j97 = 33;
142  r48st1_.c = pythia->rndm.flat();
143  for (int i = 0; i < 97; ++i) r48st1_.u[i] = pythia->rndm.flat();
144  }
145 
146  // Generate the event.
147  pwhgevent_();
148  chdir(cwd);
149  return true;
150 
151 }
152 
153 //--------------------------------------------------------------------------
154 
155 // Define external handles to the plugin for dynamic loading.
156 
157 extern "C" {
158 
159  LHAupPowheg* newLHAupPowheg(Pythia *PythiaIn) {
160  return new LHAupPowheg(PythiaIn);}
161 
162  void deleteLHAupPowheg(LHAupPowheg *lhaupIn) {delete lhaupIn;}
163 
164 }
165 
166 //==========================================================================
167 
168 } // end namespace Pythia8
169 
170 #endif // Pythia8_LHAPowheg_H