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) 2020 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 = nullptr);
62 
63  // Call pwhginit and fill the HEPRUP commonblock.
64  bool fillHepRup();
65 
66  // Call pwhgevent and fill the HEEUP commonblock.
67  bool fillHepEup();
68 
69 private:
70 
71  // The external random number generator.
72  Rndm* rndm;
73 
74  // The run directory.
75  string dir;
76 
77  // The current working directory.
78  char cwd[FILENAME_MAX];
79 
80 };
81 
82 //--------------------------------------------------------------------------
83 
84 // Constructor.
85 
86 LHAupPowheg::LHAupPowheg(Pythia *pythia) : dir("./") {
87 
88  if (pythia && pythia->settings.isWord("POWHEG:dir"))
89  dir = pythia->settings.word("POWHEG:dir");
90  if (pythia && pythia->settings.flag("POWHEG:pythiaRandom"))
91  rndm = &pythia->rndm;
92  mkdir(dir.c_str(), 0777);
93 
94 }
95 
96 //--------------------------------------------------------------------------
97 
98 // Call pwhginit and fill the HEPRUP commonblock.
99 
100 bool LHAupPowheg::fillHepRup() {
101 
102  // Set multiple random seeds to none.
103  getcwd(cwd, sizeof(cwd));
104  chdir(dir.c_str());
105  strcpy(pwhg_rnd_.rnd_cwhichseed, "none");
106 
107  // Initialize Powheg.
108  pwhginit_();
109 
110  // Reset all the counters.
111  resetcnt_("upper bound failure in inclusive cross section", 46);
112  resetcnt_("vetoed calls in inclusive cross section", 39);
113  resetcnt_("upper bound failures in generation of radiation", 47);
114  resetcnt_("vetoed radiation", 16);
115  chdir(cwd);
116  return fillHepEup();
117 
118 }
119 
120 //--------------------------------------------------------------------------
121 
122 // Set the random numbers, call pwhgevent, and fill the HEPEUP commonblock.
123 
124 bool LHAupPowheg::fillHepEup() {
125 
126  // Change directory.
127  getcwd(cwd, sizeof(cwd));
128  chdir(dir.c_str());
129 
130  // Reset the random block if requested.
131  if (rndm != nullptr) {
132  r48st1_.i97 = 97;
133  r48st1_.j97 = 33;
134  r48st1_.c = rndm->flat();
135  for (int i = 0; i < 97; ++i) r48st1_.u[i] = rndm->flat();
136  }
137 
138  // Generate the event.
139  pwhgevent_();
140  chdir(cwd);
141  return true;
142 
143 }
144 
145 //--------------------------------------------------------------------------
146 
147 // Define external handles to the plugin for dynamic loading.
148 
149 extern "C" {
150 
151  LHAupPowheg* newLHAup(Pythia *pythia) {return new LHAupPowheg(pythia);}
152 
153  void deleteLHAup(LHAupPowheg* lha) {delete lha;}
154 
155 }
156 
157 //==========================================================================
158 
159 } // end namespace Pythia8
160 
161 #endif // Pythia8_LHAPowheg_H