cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
MadGraphProcessBuilder.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2020-2024 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <fstream>
20
22#include "CepGen/Event/Event.h"
23#include "CepGen/Generator.h"
25#include "CepGen/Physics/PDG.h"
28#include "CepGen/Utils/Math.h"
33
34using namespace cepgen;
35
37public:
38 explicit MadGraphProcessBuilder(const ParametersList& params, bool load_library = true)
39 : FactorisedProcess(params, {}) {
40 if (load_library)
41 loadMG5Library();
42 CG_DEBUG("MadGraphProcessBuilder") << "List of MadGraph process registered in the runtime database: "
43 << MadGraphProcessFactory::get().modules() << ".";
44 // once MadGraph process library is loaded into runtime environment, can define its wrapper object
45 mg5_proc_ = MadGraphProcessFactory::get().build(mg5amc::normalise(steer<std::string>("process")));
46 if (mg5_proc_->centralSystem().empty())
47 throw CG_FATAL("MadGraphProcessBuilder")
48 << "Failed to retrieve produced particles system from MadGraph process:\n"
49 << mg5_proc_->description().validate(mg5_proc_->parameters()) << ".";
50 psgen_->setCentral(mg5_proc_->centralSystem());
51 }
52
53 proc::ProcessPtr clone() const override { return proc::ProcessPtr(new MadGraphProcessBuilder(parameters(), false)); }
54
55 void addEventContent() override {
56 const auto mg5_proc_cent = mg5_proc_->centralSystem();
57 Process::setEventContent({{Particle::IncomingBeam1, {kinematics().incomingBeams().positive().integerPdgId()}},
61 {Particle::CentralSystem, spdgids_t(mg5_proc_cent.begin(), mg5_proc_cent.end())}});
62 }
63
65 auto desc = FactorisedProcess::description();
66 desc.setDescription("MadGraph_aMC process builder");
67 desc.add<std::string>("lib", "").setDescription("Precompiled library for this process definition");
68 desc.add<std::string>("parametersCard", "param_card.dat").setDescription("Runtime MadGraph parameters card");
70 return desc;
71 }
72
74 const auto psgen_partons = psgen_->partons();
75 if (mg5_proc_->intermediatePartons() != std::vector<int>(psgen_partons.begin(), psgen_partons.end()))
76 throw CG_FATAL("MadGraphProcessBuilder")
77 << "MadGraph unpacked process incoming state (" << mg5_proc_->intermediatePartons() << ") "
78 << "is incompatible with user-steered incoming fluxes particles (" << psgen_->partons() << ").";
79 if (const auto params_card = steer<std::string>("parametersCard"); !params_card.empty()) {
80 CG_INFO("MadGraphProcessBuilder") << "Preparing process kinematics for card at \"" << params_card << "\".";
81 const auto unsteered_pcard = MadGraphInterface::extractParamCardParameters(utils::readFile(params_card));
82 CG_DEBUG("MadGraphProcessBuilder") << "Unsteered parameters card:\n" << unsteered_pcard;
83 if (const auto mod_params = steer<ParametersList>("modelParameters"); !mod_params.empty()) {
84 const auto steered_pcard = unsteered_pcard.steer(mod_params);
85 CG_DEBUG("MadGraphProcessBuilder") << "User-steered parameters:" << mod_params << "\n"
86 << "Steered parameters card:\n"
87 << steered_pcard;
88 std::ofstream params_card_steered(params_card);
89 params_card_steered << MadGraphInterface::generateParamCard(steered_pcard);
90 params_card_steered.close();
91 }
92 mg5_proc_->initialise(params_card);
93 }
94 }
96 if (!mg5_proc_)
97 CG_FATAL("MadGraphProcessBuilder:eval") << "Process not properly linked!";
98 if (!kinematics().cuts().initial.contain(event()(Particle::Role::Parton1)) ||
99 !kinematics().cuts().initial.contain(event()(Particle::Role::Parton2)))
100 return 0.;
101 if (!kinematics().cuts().central.contain(event()(Particle::Role::CentralSystem)))
102 return 0.;
103
104 CG_DEBUG_LOOP("MadGraphProcessBuilder:eval")
105 << "Particles content:\n"
106 << "incoming: " << q1() << " (m=" << q1().mass() << "), " << q2() << " (m=" << q2().mass() << ")\n"
107 << "outgoing: " << pc(0) << " (m=" << pc(0).mass() << "), " << pc(1) << " (m=" << pc(1).mass() << ").";
108 mg5_proc_->setMomentum(0, q1()); // first incoming parton
109 mg5_proc_->setMomentum(1, q2()); // second incoming parton
110 mg5_proc_->setMomentum(2, pc(0)); // first outgoing central particle
111 mg5_proc_->setMomentum(3, pc(1)); // second outgoing central particle
112 if (const auto weight = mg5_proc_->eval(); utils::positive(weight))
113 return weight * std::pow(shat(), -2);
114 return 0.;
115 }
116
117private:
118 void loadMG5Library() {
120 try {
121 if (const auto& lib_file = steer<std::string>("lib"); !lib_file.empty())
122 loadLibrary(lib_file);
123 else {
124 const MadGraphInterface interf(params_);
125 loadLibrary(interf.run());
126 }
127 } catch (const utils::RunAbortedException&) {
128 CG_FATAL("MadGraphProcessBuilder") << "MadGraph_aMC process generation aborted.";
129 }
130 }
131
132 std::unique_ptr<MadGraphProcess> mg5_proc_;
133};
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_DEBUG_LOOP(mod)
Definition Message.h:224
#define CG_DEBUG(mod)
Definition Message.h:220
#define CG_INFO(mod)
Definition Message.h:216
#define REGISTER_PROCESS(name, obj)
Add a generic process definition to the list of handled processes.
proc::ProcessPtr clone() const override
Copy all process attributes into a new object.
void prepareFactorisedPhaseSpace() override
Prepare central part of the Jacobian after kinematics is set.
MadGraphProcessBuilder(const ParametersList &params, bool load_library=true)
static ParametersDescription description()
double computeFactorisedMatrixElement() override
Factorised matrix element (event weight)
void addEventContent() override
Set the incoming and outgoing state to be expected in the process.
spdgid_t integerPdgId() const
Beam particle PDG id Set the beam particle PDG id.
Definition Beam.h:47
const Beam & positive() const
Reference to the positive-z beam information.
const Beam & negative() const
Reference to the negative-z beam information.
IncomingBeams & incomingBeams()
Beam/primary particle kinematics.
Definition Kinematics.h:36
static ParametersDescription extractParamCardParameters(const std::string &)
Retrieve a CepGen-compatible parameters list from a MadGraph parameters card.
static ParametersDescription description()
static std::string generateParamCard(const ParametersDescription &)
Generate a MadGraph parameters card from CepGen user-steered parameters.
double mass() const
Mass (in GeV) as computed from its energy and momentum.
Definition Momentum.cpp:222
A description object for parameters collection.
@ IncomingBeam2
incoming beam particle
Definition Particle.h:53
@ OutgoingBeam1
outgoing beam state/particle
Definition Particle.h:54
@ IncomingBeam1
incoming beam particle
Definition Particle.h:52
@ OutgoingBeam2
outgoing beam state/particle
Definition Particle.h:55
@ CentralSystem
Central particles system.
Definition Particle.h:56
ParametersList params_
Module parameters.
Definition Steerable.h:50
const ParametersList & parameters() const override
Module user-defined parameters.
Generic parton emission-factorised process.
FactorisedProcess(const ParametersList &params, const spdgids_t &output)
Class constructor.
const std::unique_ptr< PhaseSpaceGenerator > psgen_
Kinematic variables generator for the phase space coverage.
const Kinematics & kinematics() const
Constant reference to the process kinematics.
Definition Process.h:50
const Momentum & q2() const
Negative-z incoming parton's 4-momentum.
Definition Process.cpp:111
double shat() const
Definition Process.cpp:127
Momentum & pc(size_t)
Central particle's 4-momentum.
Definition Process.cpp:113
double weight(const std::vector< double > &)
Compute the weight for a phase-space point.
Definition Process.cpp:234
const Event & event() const
Handled particles objects and their relationships.
Definition Process.cpp:267
const Momentum & q1() const
Positive-z incoming parton's 4-momentum.
Definition Process.cpp:107
Object handling an user-driven process abortion.
std::string normalise(const std::string &proc_name, const std::string &model)
Normalise a process name to make it computer-readable.
Definition Utils.cpp:172
std::unique_ptr< Process > ProcessPtr
Helper typedef for a Process unique pointer.
Definition Process.h:199
std::string readFile(const std::string &filename)
Read the content of a file into a string buffer.
bool positive(const T &val)
Check if a number is positive and finite.
Definition Math.cpp:26
Common namespace for this Monte Carlo generator.
bool loadLibrary(const std::string &path, bool match)
Import a shared library in RTE Launch the initialisation procedure.
std::vector< spdgid_t > spdgids_t
Exception raised when the user terminates the process.