StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ShowerMEs.cc
1 // ShowerMEs.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Peter Skands, Stefan Prestel, Philip Ilten, Torbjorn
3 // Sjostrand.
4 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
5 // Please respect the MCnet Guidelines, see GUIDELINES for details.
6 
7 // Virtual interface for external matrix element plugins for parton showers.
8 
9 #include "Pythia8/ShowerMEs.h"
10 
11 namespace Pythia8 {
12 
13 //==========================================================================
14 
15 // The parton shower matrix-element interface.
16 
17 //--------------------------------------------------------------------------
18 
19 // Set pointers to required PYTHIA 8 objects.
20 
21 void ShowerMEs::initPtrVincia(Info* infoPtrIn,
22  SusyLesHouches* slhaPtrIn, VinciaCommon* vinComPtrIn) {
23  infoPtr = infoPtrIn;
24  coupSMPtr = infoPtr->coupSMPtr;
25  particleDataPtr = infoPtr->particleDataPtr;
26  settingsPtr = infoPtr->settingsPtr;
27  rndmPtr = infoPtr->rndmPtr;
28  slhaPtr = slhaPtrIn;
29  vinComPtr = vinComPtrIn;
30  isInitPtr = true;
31 }
32 
33 //--------------------------------------------------------------------------
34 
35 // Set helicities for a particle state.
36 
37 bool ShowerMEs::selectHelicitiesVincia(vector<Particle>& state, int nIn) {
38 
39  // Get the matrix element (automatically sums over any h=9 particles).
40  double me2sum = me2Vincia(state, nIn);
41  if (verbose >= superdebug)
42  cout << " ShowerMEs::selectHelicities(): "
43  << scientific << me2sum << endl;
44 
45  // Did we find the ME, (me2() returns -1 if no ME found).
46  if (me2sum <= 0.) return false;
47 
48  // Check how many helicity configurations we summed over.
49  int nHelConf = me2hel.size();
50  if (nHelConf <= 0) return false;
51 
52  // Random number between zero and me2sum (trivial if only one helConf).
53  double ranHelConf = 0.0;
54  vector<int> hSelected;
55  if (nHelConf >= 2) ranHelConf = rndmPtr->flat() * me2sum;
56  for (map< vector<int>, double>::iterator it=me2hel.begin();
57  it != me2hel.end(); ++it) {
58  // Progressively subtract each me2hel and check when we cross zero.
59  ranHelConf -= it->second;
60  if (ranHelConf <= 0.0) {
61  hSelected = it->first;
62  break;
63  }
64  }
65  if (ranHelConf > 0.) return false;
66 
67  // Set helicity configuration.
68  for (int i = 0; i < (int)state.size(); ++i) state[i].pol(hSelected[i]);
69  if (verbose >= superdebug)
70  cout << " ShowerMEs::selectHelicities(): selected " <<
71  makeLabelVincia(hSelected, nIn, false) << endl;
72  return true;
73 
74 }
75 
76 //--------------------------------------------------------------------------
77 
78 // Convert process id codes (or helicity values) to string.
79 
80 string ShowerMEs::makeLabelVincia(vector<int>& id, int nIn, bool useNames)
81  const {
82  string label = "{";
83  for (int i = 0; i < (int)id.size(); ++i) {
84  string idName;
85  if (useNames && id[i] != 0) idName = particleDataPtr->name(id[i]);
86  else idName = num2str(id[i]);
87  if (i == nIn-1) idName += " ->";
88  label += idName+" ";
89  }
90  label += "}";
91  return label;
92 }
93 
94 //--------------------------------------------------------------------------
95 
96 // Fill a vector of IDs.
97 
98 void ShowerMEs::fillIds(const Event& event, vector<int>& in, vector<int>& out)
99  const {
100  in.push_back(event[3].id());
101  in.push_back(event[4].id());
102  for (int i = 4; i < event.size(); ++i) {
103  if ( event[i].isFinal() ) out.push_back(event[i].id());
104  }
105 }
106 
107 //--------------------------------------------------------------------------
108 
109 // Fill a vector of momenta.
110 
111 void ShowerMEs::fillMoms(const Event& event, vector<Vec4>& p) const {
112  p.push_back(event[3].p());
113  p.push_back(event[4].p());
114  for (int i = 4; i < event.size(); ++i) {
115  if ( event[i].isFinal() ) p.push_back(event[i].p());
116  }
117 }
118 
119 //--------------------------------------------------------------------------
120 
121 // Fill a vector of colors.
122 
123 void ShowerMEs::fillCols(const Event& event, vector<int>& colors) const {
124  colors.push_back(event[3].col()); colors.push_back(event[3].acol());
125  colors.push_back(event[4].col()); colors.push_back(event[4].acol());
126  for (int i = 4; i < event.size(); ++i) {
127  if ( event[i].isFinal() ) {
128  colors.push_back(event[i].col());
129  colors.push_back(event[i].acol());
130  }
131  }
132 }
133 
134 
135 //--------------------------------------------------------------------------
136 
137 // Return the momenta.
138 
139 vector<vector<double> > ShowerMEs::fillMoms(const Event& event) const {
140  vector<Vec4> p;
141  fillMoms(event, p);
142  vector< vector<double> > ret;
143  for (int i = 0; i < int(p.size()); i++ ) {
144  vector<double> p_tmp(4, 0.);
145  p_tmp[0] = isnan(p[i].e()) ? 0.0 : p[i].e() ;
146  p_tmp[1] = isnan(p[i].px()) ? 0.0 : p[i].px();
147  p_tmp[2] = isnan(p[i].py()) ? 0.0 : p[i].py();
148  p_tmp[3] = isnan(p[i].pz()) ? 0.0 : p[i].pz();
149  ret.push_back(p_tmp);
150  }
151  return ret;
152 }
153 
154 //==========================================================================
155 
156 // Interface to external matrix elements for parton shower matrix
157 // element corrections.
158 
159 //--------------------------------------------------------------------------
160 
161 // Set pointers to required PYTHIA 8 objects.
162 
163 void ShowerMEsPlugin::initPtrVincia(Info* infoPtrIn,
164  SusyLesHouches* slhaPtrIn, VinciaCommon* vinComPtrIn) {
165  infoPtr = infoPtrIn;
166  coupSMPtr = infoPtr->coupSMPtr;
167  particleDataPtr = infoPtr->particleDataPtr;
168  settingsPtr = infoPtr->settingsPtr;
169  rndmPtr = infoPtr->rndmPtr;
170  slhaPtr = slhaPtrIn;
171  vinComPtr = vinComPtrIn;
172  isInitPtr = true;
173  if (mesPtr != nullptr)
174  mesPtr->initPtrVincia(infoPtrIn, slhaPtrIn, vinComPtrIn);
175 }
176 
177 //--------------------------------------------------------------------------
178 
179 // Initialize the matrix element.
180 
181 bool ShowerMEsPlugin::initVincia() {
182 
183  // Load the plugin library if needed.
184  if (name.size() == 0) return false;
185  if (libPtr == nullptr) {
186  if (infoPtr != nullptr) libPtr = infoPtr->plugin(name);
187  else libPtr = make_shared<Plugin>(name);
188  if (!libPtr->isLoaded()) return false;
189 
190  // Create a new ME.
191  NewShowerMEs* newShowerMEs = (NewShowerMEs*)libPtr->symbol("newShowerMEs");
192  if (!newShowerMEs) return false;
193  mesPtr = newShowerMEs();
194  mesPtr->initPtrVincia(infoPtr, slhaPtr, vinComPtr);
195  }
196 
197  // Initialize the ME if it exists.
198  if (mesPtr != nullptr) return mesPtr->initVincia();
199  else return false;
200 
201 }
202 
203 //--------------------------------------------------------------------------
204 
205 // Initialize the matrix element.
206 
207 bool ShowerMEsPlugin::initDire(Info* infoPtrIn, string card) {
208  infoPtr = infoPtrIn;
209 
210  // Load the plugin library if needed.
211  if (name.size() == 0) return false;
212  if (libPtr == nullptr) {
213  if (infoPtr != nullptr) libPtr = infoPtr->plugin(name);
214  else libPtr = make_shared<Plugin>(name);
215  if (!libPtr->isLoaded()) return false;
216 
217  // Create a new ME.
218  NewShowerMEs* newShowerMEs = (NewShowerMEs*)libPtr->symbol("newShowerMEs");
219  if (!newShowerMEs) return false;
220  mesPtr = newShowerMEs();
221  }
222 
223  // Initialize the ME if it exists.
224  if (mesPtr != nullptr) return mesPtr->initDire(infoPtr, card);
225  else return false;
226 
227 }
228 
229 //--------------------------------------------------------------------------
230 
231 // Destructor.
232 
233 ShowerMEsPlugin::~ShowerMEsPlugin() {
234 
235  // Delete the MEs pointer.
236  if (mesPtr == nullptr || libPtr == nullptr || !libPtr->isLoaded()) return;
237  DeleteShowerMEs* deleteShowerMEs =
238  (DeleteShowerMEs*)libPtr->symbol("deleteShowerMEs");
239  if (deleteShowerMEs) deleteShowerMEs(mesPtr);
240 
241 }
242 
243 //==========================================================================
244 
245 } // end namespace Pythia8
Definition: AgUStep.h:26