11 #ifndef Pythia8_ExternalMEsMadgraph_H 12 #define Pythia8_ExternalMEsMadgraph_H 15 #include "Pythia8/ExternalMEs.h" 16 #include "Pythia8/Plugins.h" 34 isInitPtr =
false; isInit =
false; libPtr =
nullptr; modelPtr =
nullptr;}
38 if (modelPtr !=
nullptr)
delete modelPtr;}
46 bool isAvailable(vector<int> idIn, vector<int> idOut)
override;
49 bool isAvailable(
const vector<Particle>& state)
override;
52 double calcME2(
const vector<Particle>& state)
override;
53 double calcME2(
const Event& event,
const int iBeg = 3)
override;
58 void fillLists(
const vector<Particle>& state, vector<int>& idsIn,
59 vector<int>& idsOut, vector<int>& hels, vector<int>& cols,
60 vector<vector<double>>& pn)
const;
63 double calcME2(vector<int>& idIn, vector<int>& idOut,
64 vector< vector<double> >& pn, vector<int>& hels, vector<int>& cols,
65 set<int> sChannels = {});
67 PY8MEs_namespace::PY8MEs* libPtr;
82 int verbose = settingsPtr->mode(
"Vincia:verbose");
84 cout <<
" (ExternalMEsMadgraph::init()) begin -------" << endl;
86 loggerPtr->ERROR_MSG(
"cannot initialize, pointers not set");
92 if (verbose >= 2) cout <<
" (ExternalMEsMadgraph::init())" 93 <<
"setting MG5 C++ masses, widths, couplings..." << endl;
94 if (modelPtr !=
nullptr)
delete modelPtr;
95 modelPtr =
new PARS();
96 modelPtr->setIndependentParameters(particleDataPtr,coupSMPtr,slhaPtr);
97 modelPtr->setIndependentCouplings();
99 modelPtr->printIndependentParameters();
100 modelPtr->printIndependentCouplings();
115 double alpS = 1.0 / ( 4 * M_PI );
116 modelPtr->setDependentParameters(particleDataPtr, coupSMPtr, slhaPtr,
118 modelPtr->setDependentCouplings();
121 if (verbose >= 3) cout <<
" (ExternalMEsMadgraph::init())" 122 <<
" attempting to construct lib" << endl;
123 if (libPtr !=
nullptr)
delete libPtr;
124 libPtr =
new PY8MEs_namespace::PY8MEs(modelPtr);
126 libPtr->seProcessesIncludeSymmetryFactors(
false);
127 libPtr->seProcessesIncludeHelicityAveragingFactors(
false);
128 libPtr->seProcessesIncludeColorAveragingFactors(
false);
131 inclHelAvgFac =
true;
132 inclColAvgFac =
true;
149 std::streambuf *old = cout.rdbuf();
151 cout.rdbuf (ss.rdbuf());
152 if (libPtr !=
nullptr)
delete libPtr;
153 libPtr =
new PY8MEs_namespace::PY8MEs(card);
155 libPtr->seProcessesIncludeSymmetryFactors(
false);
156 libPtr->seProcessesIncludeHelicityAveragingFactors(
false);
157 libPtr->seProcessesIncludeColorAveragingFactors(
false);
158 libPtr->setProcessesExternalMassesMode(1);
161 inclHelAvgFac =
true;
162 inclColAvgFac =
true;
179 set<int> req_s_channels;
180 PY8MEs_namespace::PY8ME * query
181 = libPtr->getProcess(idIn, idOut, req_s_channels);
182 return (query !=
nullptr);
187 vector <int> in, out;
189 set<int> req_s_channels;
191 PY8MEs_namespace::PY8ME* query
192 = libPtr->getProcess(in, out, req_s_channels);
193 return (query !=
nullptr);
198 vector <int> in, out;
200 set<int> req_s_channels;
202 PY8MEs_namespace::PY8ME* query
203 = libPtr->getProcess(in, out, req_s_channels);
204 return (query !=
nullptr);
209 vector <int> idIn, idOut;
210 for (
const Particle& ptcl : state) {
211 if (ptcl.isFinal()) idOut.push_back(ptcl.id());
212 else idIn.push_back(ptcl.id());
214 set<int> req_s_channels;
216 PY8MEs_namespace::PY8ME* query
217 = libPtr->getProcess(idIn, idOut, req_s_channels);
218 return (query !=
nullptr);
228 vector<int> idIn, idOut, hels, cols;
229 vector<vector<double>> pn;
230 fillLists(state, idIn, idOut, hels, cols, pn);
231 int nIn = idIn.size();
232 if (nIn <= 0 || state.size() - nIn < 1)
return -1.;
234 return calcME2(idIn, idOut, pn, hels, cols);
246 vector< vector<double> > pvec =
fillMoms(event, iBeg);
247 vector<int> helicities;
249 return calcME2(in, out, pvec, helicities, cols);
254 vector< vector<double> >& pn, vector<int>& hels, vector<int>& cols,
255 set<int> sChannels) {
258 PY8MEs_namespace::process_specifier proc_spec =
259 libPtr->getProcessSpecifier(idIn, idOut, sChannels);
260 PY8MEs_namespace::process_accessor proc_handle =
261 libPtr->getProcess(proc_spec);
263 if (proc_handle.second.second < 0)
return 0.0;
264 PY8MEs_namespace::PY8ME* proc_ptr = proc_handle.first;
265 proc_ptr->setPermutation(proc_handle.second.first);
266 int procID = proc_handle.second.second;
267 proc_ptr->setProcID(procID);
268 int nIn = idIn.size();
271 vector< vector<int> > helConf;
272 helConf.push_back(hels);
277 for (
int i(0); i<(int)hels.size(); ++i)
278 if (hels[i] == 9) i9.push_back(i);
281 double helAvgNorm = i9.size()>0 ? 1:proc_ptr->getHelicityAveragingFactor();
282 while (i9.size() > 0) {
284 int id = (i < nIn) ? idIn[i] : idOut[i-nIn];
286 int nS = particleDataPtr->spinType(
id);
288 if (particleDataPtr->m0(
id) == 0.0) nS=min(nS,2);
289 if (i < nIn) helAvgNorm *= (double)nS;
291 int helConfSizeNow = helConf.size();
292 for (
int iCopy = 1; iCopy <= nS; ++iCopy) {
297 else if (iCopy == 2) h = 1;
298 else if (iCopy == 3) h = 0;
299 else if (iCopy == 4) h = -2;
300 else if (iCopy == 5) h = 2;
301 for (
int iHelConf=0; iHelConf<helConfSizeNow; ++iHelConf) {
302 vector<int> helNow = helConf[iHelConf];
305 if (iCopy == 1) helConf[iHelConf] = helNow;
307 else helConf.push_back(helNow);
315 vector<vector<int>> colConf;
319 colConf.push_back(cols);
322 vector<vector<int>> colorConfigs = proc_ptr->getColorConfigs(procID);
323 for (
const auto& cc : colorConfigs) {
324 int colID = proc_ptr->getColorIDForConfig(cc);
325 if (proc_ptr->getColorFlowRelativeNCPower(colID) == 0)
326 colConf.push_back(cc);
328 }
else colConf.push_back(cols);
334 proc_ptr->setMomenta(pn);
335 for (
const auto& cc : colConf) {
336 proc_ptr->setColors(cc);
337 for (
int iHC(0); iHC<(int)helConf.size(); ++iHC) {
338 proc_ptr->setHelicities(helConf[iHC]);
339 double me2now = proc_ptr->sigmaKin();
341 if (!isnan(me2now) && !isinf(me2now)) {
343 me2hel[helConf[iHC]] = me2now;
350 if (
inclSymFac) me2 /= proc_ptr->getSymmetryFactor();
351 if (inclHelAvgFac) me2 /= helAvgNorm;
352 if (inclColAvgFac) me2 /= proc_ptr->getColorAveragingFactor();
361 void ExternalMEsMadgraph::fillLists(
const vector<Particle>& state,
362 vector<int>& idsIn, vector<int>& idsOut, vector<int>& hels,
363 vector<int>& cols, vector<vector<double>>& pn)
const {
364 for (
const Particle& ptcl : state) {
365 if (ptcl.isFinal()) idsOut.push_back(ptcl.id());
366 else idsIn.push_back(ptcl.id());
367 vector<double> pNow = {ptcl.e(), ptcl.px(), ptcl.py(), ptcl.pz()};
369 hels.push_back(ptcl.pol());
370 cols.push_back(ptcl.col());
371 cols.push_back(ptcl.acol());
380 PYTHIA8_PLUGIN_VERSIONS(PYTHIA_VERSION_INTEGER)
double calcME2(const vector< Particle > &state) override
Get the matrix element squared for a particle state.
Definition: ExternalMEsMadgraph.h:225
int colMode
Colour mode (0: strict LC, 1: LC, 2: LC sum, 3: FC).
Definition: ExternalMEs.h:95
virtual void initPtrs(Info *infoPtrIn)
Initialisers for pointers.
Definition: ExternalMEs.cc:22
int helMode
Helicity mode (0: explicit helicity sum, 1: implicit helicity sum).
Definition: ExternalMEs.h:101
The Event class holds all info on the generated event.
Definition: Event.h:453
void fillCols(const Event &event, vector< int > &colors, int iBeg=3) const
Fill a vector of colors, from an event, starting from entry i = iBeg.
Definition: ExternalMEs.cc:60
void fillMoms(const Event &event, vector< Vec4 > &p, int iBeg=3) const
Fill a vector of momenta, from an event, starting from entry i = iBeg.
Definition: ExternalMEs.cc:50
External matrix element class specifically for MadGraph.
Definition: ExternalMEsMadgraph.h:28
bool isAvailable(vector< int > idIn, vector< int > idOut) override
Methods to check availability of matrix elements.
Definition: ExternalMEsMadgraph.h:178
bool inclSymFac
Symmetry and averaging factors.
Definition: ExternalMEs.h:104
map< vector< int >, double > me2hel
Saved list of helicity components for last ME evaluated.
Definition: ExternalMEs.h:98
~ExternalMEsMadgraph()
Destructor.
Definition: ExternalMEsMadgraph.h:37
Base class for external matrix-element interfaces.
Definition: ExternalMEs.h:30
bool init() override
Initialisers.
Definition: ExternalMEsMadgraph.h:76
bool initDire(Info *, string card) override
Initialise the Madgraph model, parameters, and couplings for use in Dire.
Definition: ExternalMEsMadgraph.h:146
bool initVincia(Info *infoPtrIn) override
Definition: ExternalMEsMadgraph.h:78
void fillIds(const Event &event, vector< int > &in, vector< int > &out, int iBeg=3) const
Fill a vector of IDs, from an event, starting from entry i = iBeg.
Definition: ExternalMEs.cc:37
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
The Pythia class contains the top-level routines to generate an event.
Definition: Pythia.h:71
bool isInitPtr
Is initialized.
Definition: ExternalMEs.h:116
Definition: Settings.h:195
ExternalMEsMadgraph(Pythia *, Settings *, Logger *)
Constructor.
Definition: ExternalMEsMadgraph.h:33