11 #ifndef Pythia8_ShowerMEsMadgraph_H
12 #define Pythia8_ShowerMEsMadgraph_H
15 #include "Pythia8/ShowerMEs.h"
32 libPtr =
nullptr; modelPtr =
nullptr;}
36 if (modelPtr !=
nullptr)
delete modelPtr;}
40 bool initVincia()
override;
42 double me2Vincia(vector<Particle> state,
int nIn)
override;
44 bool hasProcessVincia(vector<int> idIn, vector<int> idOut,
45 set<int> sChan)
override;
48 bool initDire(
Info*,
string card)
override;
49 bool isAvailableMEDire(vector <int> in, vector<int> out)
override;
56 PY8MEs_namespace::PY8ME* getProcess(vector<int> idIn, vector<int> idOut,
61 PY8MEs_namespace::PY8MEs* libPtr;
70 bool ShowerMEsMadgraph::initVincia() {
73 verbose = settingsPtr->mode(
"Vincia:verbose");
74 if (verbose > normal) printOut(
"ShowerMEsMadgraph::init",
"...");
76 printOut(
"ShowerMEsMadgraph::init",
77 "Cannot initialize, pointers not set.");
86 if (verbose >= quiteloud) printOut(
"ShowerMEsMadgraph::init",
87 " setting MG C++ masses, widths, couplings...");
88 if (modelPtr !=
nullptr)
delete modelPtr;
89 modelPtr =
new PARS();
90 modelPtr->setIndependentParameters(particleDataPtr,coupSMPtr,slhaPtr);
91 modelPtr->setIndependentCouplings();
92 if (verbose >= quiteloud) {
93 modelPtr->printIndependentParameters();
94 modelPtr->printIndependentCouplings();
109 double alpS = 1.0 / ( 4 * M_PI );
110 modelPtr->setDependentParameters(particleDataPtr, coupSMPtr, slhaPtr,
112 modelPtr->setDependentCouplings();
115 if (verbose >= superdebug) printOut(
"ShowerMEsMadgraph::init()",
116 " attempting to construct lib");
117 if (libPtr !=
nullptr)
delete libPtr;
118 libPtr =
new PY8MEs_namespace::PY8MEs(modelPtr);
127 bool ShowerMEsMadgraph::hasProcessVincia(vector<int> idIn, vector<int> idOut,
128 set<int> sChan) {
return getProcess(idIn, idOut, sChan) !=
nullptr;}
135 PY8MEs_namespace::PY8ME* ShowerMEsMadgraph::getProcess(
136 vector<int> idIn, vector<int> idOut, set<int> sChan) {
137 if (verbose >= superdebug) {
138 cout <<
" ShowerMEsMadgraph::getProcess(): checking for process";
139 for (
int i = 0; i < (int)idIn.size(); ++i) cout <<
" " << idIn[i];
141 for (
int i = 0; i < (int)idOut.size(); ++i) cout <<
" " << idOut[i];
144 if (libPtr !=
nullptr && libPtr != 0)
145 return libPtr->getProcess(idIn, idOut, sChan);
146 cout <<
" returning NULL" << endl;
154 double ShowerMEsMadgraph::me2Vincia(vector<Particle> state,
int nIn) {
157 if (nIn <= 0)
return -1;
158 else if (state.size() - nIn < 1)
return -1;
159 vector<int> idIn, helOrg, col, acol;
160 vector<Vec4> momenta;
161 idIn.push_back(state[0].
id());
162 momenta.push_back(state[0].p());
163 helOrg.push_back(state[0].pol());
164 col.push_back(state[0].col());
165 acol.push_back(state[0].acol());
167 idIn.push_back(state[1].
id());
168 momenta.push_back(state[1].p());
169 helOrg.push_back(state[1].pol());
170 col.push_back(state[1].col());
171 acol.push_back(state[1].acol());
175 for (
int i=nIn; i<(int)state.size(); ++i) {
176 idOut.push_back(state[i].
id());
177 momenta.push_back(state[i].p());
178 helOrg.push_back(state[i].pol());
179 col.push_back(state[i].col());
180 acol.push_back(state[i].acol());
186 PY8MEs_namespace::process_specifier proc_spec =
187 libPtr->getProcessSpecifier(idIn, idOut, sChannels);
188 PY8MEs_namespace::process_accessor proc_handle =
189 libPtr->getProcess(proc_spec);
192 if (proc_handle.second.second < 0)
return -1;
195 vector< vector<double> > momentaMG5;
196 vector< int > colacolMG5;
197 for (
int i = 0; i < (int)momenta.size(); ++i) {
199 pNow.push_back(momenta[i].e());
200 pNow.push_back(momenta[i].px());
201 pNow.push_back(momenta[i].py());
202 pNow.push_back(momenta[i].pz());
203 momentaMG5.push_back(pNow);
204 colacolMG5.push_back(col[i]);
205 colacolMG5.push_back(acol[i]);
210 for (
int i = 0; i < (int)helOrg.size(); ++i) {
212 if (helOrg[i] == 9) i9.push_back(i);
216 vector< vector<int> > helConf;
217 helConf.push_back(helOrg);
218 while (i9.size() > 0) {
220 int id = (i < nIn) ? idIn[i] : idOut[i-nIn];
222 int nS = particleDataPtr->spinType(
id);
224 if (particleDataPtr->m0(
id) == 0.0) nS=min(nS,2);
226 int helConfSizeNow = helConf.size();
227 for (
int iCopy = 1; iCopy <= nS; ++iCopy) {
232 else if (iCopy == 2) h = 1;
233 else if (iCopy == 3) h = 0;
234 else if (iCopy == 4) h = -2;
235 else if (iCopy == 5) h = 2;
236 for (
int iHelConf=0; iHelConf<helConfSizeNow; ++iHelConf) {
237 vector<int> helNow = helConf[iHelConf];
240 if (iCopy == 1) helConf[iHelConf] = helNow;
242 else helConf.push_back(helNow);
248 if (verbose >= superdebug) {
250 for (
int i = 0; i < (int)idIn.size(); ++i) cout << idIn[i] <<
" ";
252 for (
int i = 0; i < (int)idOut.size(); ++i) cout << idOut[i] <<
" ";
254 cout <<
" number of helicity configurations = " << helConf.size() << endl;
255 for (
int i = 0; i < (int)helConf.size(); ++i) {
256 cout <<
" helConf " << i;
257 for (
int j = 0; j < (int)helConf[i].size(); ++j)
258 cout <<
" " << helConf[i][j];
264 PY8MEs_namespace::PY8ME* proc_ptr = proc_handle.first;
265 vector<int> perms = proc_handle.second.first;
266 int proc_ID = proc_handle.second.second;
267 proc_ptr->setMomenta(momentaMG5);
268 proc_ptr->setProcID(proc_ID);
269 proc_ptr->setPermutation(perms);
270 proc_ptr->setColors(colacolMG5);
275 for (
int iHC=0; iHC<(int)helConf.size(); ++iHC) {
279 proc_ptr->setHelicities(helConf[iHC]);
280 double me2now = proc_ptr->sigmaKin();
282 if ( !isnan(me2now) && !isinf(me2now) ) {
284 me2hel[helConf[iHC]] = me2now;
289 me2 *= double(proc_ptr->getSymmetryFactor());
296 bool ShowerMEsMadgraph::initDire(Info*,
string card) {
299 std::streambuf *old = cout.rdbuf();
301 cout.rdbuf (ss.rdbuf());
302 if (libPtr !=
nullptr)
delete libPtr;
303 libPtr =
new PY8MEs_namespace::PY8MEs(card);
304 libPtr->seProcessesIncludeSymmetryFactors(
false);
305 libPtr->seProcessesIncludeHelicityAveragingFactors(
false);
306 libPtr->seProcessesIncludeColorAveragingFactors(
false);
307 libPtr->setProcessesExternalMassesMode(1);
319 bool ShowerMEsMadgraph::isAvailableMEDire(vector <int> in, vector<int> out) {
320 set<int> req_s_channels;
321 PY8MEs_namespace::PY8ME * query
322 = libPtr->getProcess(in, out, req_s_channels);
330 bool ShowerMEsMadgraph::isAvailableMEDire(
const Pythia8::Event& event) {
332 vector <int> in, out;
333 fillIds(event, in, out);
334 set<int> req_s_channels;
336 PY8MEs_namespace::PY8ME* query
337 = libPtr->getProcess(in, out, req_s_channels);
345 double ShowerMEsMadgraph::calcMEDire(
const Pythia8::Event& event) {
347 vector <int> in, out;
348 fillIds(event, in, out);
350 fillCols(event, cols);
351 vector< vector<double> > pvec = fillMoms(event);
352 set<int> req_s_channels;
353 vector<int> helicities;
356 pair < double, bool > res;
358 res = libPtr->calculateME(in, out, pvec, req_s_channels, cols,
360 }
catch (
const std::exception& e) {
363 if (!success)
return 0.0;
365 double me = res.first;
366 PY8MEs_namespace::PY8ME* query
367 = libPtr->getProcess(in, out, req_s_channels);
368 me *= 1./query->getHelicityAveragingFactor();
369 me *= 1./query->getColorAveragingFactor();
383 ShowerMEsMadgraph* newShowerMEs() {
return new ShowerMEsMadgraph();}
385 void deleteShowerMEs(ShowerMEsMadgraph* mes) {
delete mes;}
393 #endif // end Pythia8_ShowerMEsMadgraph_H