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
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Event/Event.h
"
23
#include "
CepGen/Generator.h
"
24
#include "
CepGen/Modules/ProcessFactory.h
"
25
#include "
CepGen/Physics/PDG.h
"
26
#include "
CepGen/Process/FactorisedProcess.h
"
27
#include "
CepGen/Utils/AbortHandler.h
"
28
#include "
CepGen/Utils/Math.h
"
29
#include "
CepGenAddOns/MadGraphWrapper/MadGraphInterface.h
"
30
#include "
CepGenAddOns/MadGraphWrapper/MadGraphProcess.h
"
31
#include "
CepGenAddOns/MadGraphWrapper/MadGraphProcessFactory.h
"
32
#include "
CepGenAddOns/MadGraphWrapper/Utils.h
"
33
34
using namespace
cepgen
;
35
36
class
MadGraphProcessBuilder
:
public
proc::FactorisedProcess
{
37
public
:
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
()}},
58
{
Particle::IncomingBeam2
, {
kinematics
().
incomingBeams
().
negative
().
integerPdgId
()}},
59
{
Particle::OutgoingBeam1
, {
kinematics
().
incomingBeams
().
positive
().
integerPdgId
()}},
60
{
Particle::OutgoingBeam2
, {
kinematics
().
incomingBeams
().
negative
().
integerPdgId
()}},
61
{
Particle::CentralSystem
,
spdgids_t
(mg5_proc_cent.begin(), mg5_proc_cent.end())}});
62
}
63
64
static
ParametersDescription
description
() {
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"
);
69
desc +=
MadGraphInterface::description
();
70
return
desc;
71
}
72
73
void
prepareFactorisedPhaseSpace
()
override
{
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
}
95
double
computeFactorisedMatrixElement
()
override
{
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
117
private
:
118
void
loadMG5Library() {
119
utils::AbortHandler
();
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
};
134
REGISTER_PROCESS
(
"mg5_aMC"
,
MadGraphProcessBuilder
);
AbortHandler.h
Event.h
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
FactorisedProcess.h
Generator.h
MadGraphInterface.h
MadGraphProcessFactory.h
MadGraphProcess.h
Math.h
CG_DEBUG_LOOP
#define CG_DEBUG_LOOP(mod)
Definition
Message.h:224
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
PDG.h
ProcessFactory.h
REGISTER_PROCESS
#define REGISTER_PROCESS(name, obj)
Add a generic process definition to the list of handled processes.
Definition
ProcessFactory.h:25
MadGraphProcessBuilder
Definition
MadGraphProcessBuilder.cpp:36
MadGraphProcessBuilder::clone
proc::ProcessPtr clone() const override
Copy all process attributes into a new object.
Definition
MadGraphProcessBuilder.cpp:53
MadGraphProcessBuilder::prepareFactorisedPhaseSpace
void prepareFactorisedPhaseSpace() override
Prepare central part of the Jacobian after kinematics is set.
Definition
MadGraphProcessBuilder.cpp:73
MadGraphProcessBuilder::MadGraphProcessBuilder
MadGraphProcessBuilder(const ParametersList ¶ms, bool load_library=true)
Definition
MadGraphProcessBuilder.cpp:38
MadGraphProcessBuilder::description
static ParametersDescription description()
Definition
MadGraphProcessBuilder.cpp:64
MadGraphProcessBuilder::computeFactorisedMatrixElement
double computeFactorisedMatrixElement() override
Factorised matrix element (event weight)
Definition
MadGraphProcessBuilder.cpp:95
MadGraphProcessBuilder::addEventContent
void addEventContent() override
Set the incoming and outgoing state to be expected in the process.
Definition
MadGraphProcessBuilder.cpp:55
cepgen::Beam::integerPdgId
spdgid_t integerPdgId() const
Beam particle PDG id Set the beam particle PDG id.
Definition
Beam.h:47
cepgen::IncomingBeams::positive
const Beam & positive() const
Reference to the positive-z beam information.
Definition
IncomingBeams.h:38
cepgen::IncomingBeams::negative
const Beam & negative() const
Reference to the negative-z beam information.
Definition
IncomingBeams.h:40
cepgen::Kinematics::incomingBeams
IncomingBeams & incomingBeams()
Beam/primary particle kinematics.
Definition
Kinematics.h:36
cepgen::MadGraphInterface
Definition
MadGraphInterface.h:26
cepgen::MadGraphInterface::extractParamCardParameters
static ParametersDescription extractParamCardParameters(const std::string &)
Retrieve a CepGen-compatible parameters list from a MadGraph parameters card.
Definition
MadGraphInterface.cpp:247
cepgen::MadGraphInterface::description
static ParametersDescription description()
Definition
MadGraphInterface.cpp:303
cepgen::MadGraphInterface::generateParamCard
static std::string generateParamCard(const ParametersDescription &)
Generate a MadGraph parameters card from CepGen user-steered parameters.
Definition
MadGraphInterface.cpp:285
cepgen::Momentum::mass
double mass() const
Mass (in GeV) as computed from its energy and momentum.
Definition
Momentum.cpp:222
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Particle::IncomingBeam2
@ IncomingBeam2
incoming beam particle
Definition
Particle.h:53
cepgen::Particle::OutgoingBeam1
@ OutgoingBeam1
outgoing beam state/particle
Definition
Particle.h:54
cepgen::Particle::IncomingBeam1
@ IncomingBeam1
incoming beam particle
Definition
Particle.h:52
cepgen::Particle::OutgoingBeam2
@ OutgoingBeam2
outgoing beam state/particle
Definition
Particle.h:55
cepgen::Particle::CentralSystem
@ CentralSystem
Central particles system.
Definition
Particle.h:56
cepgen::Steerable::params_
ParametersList params_
Module parameters.
Definition
Steerable.h:50
cepgen::SteeredObject::parameters
const ParametersList & parameters() const override
Module user-defined parameters.
Definition
SteeredObject.h:54
cepgen::proc::FactorisedProcess
Generic parton emission-factorised process.
Definition
FactorisedProcess.h:33
cepgen::proc::FactorisedProcess::FactorisedProcess
FactorisedProcess(const ParametersList ¶ms, const spdgids_t &output)
Class constructor.
Definition
FactorisedProcess.cpp:31
cepgen::proc::FactorisedProcess::psgen_
const std::unique_ptr< PhaseSpaceGenerator > psgen_
Kinematic variables generator for the phase space coverage.
Definition
FactorisedProcess.h:58
cepgen::proc::Process::kinematics
const Kinematics & kinematics() const
Constant reference to the process kinematics.
Definition
Process.h:50
cepgen::proc::Process::q2
const Momentum & q2() const
Negative-z incoming parton's 4-momentum.
Definition
Process.cpp:111
cepgen::proc::Process::shat
double shat() const
Definition
Process.cpp:127
cepgen::proc::Process::pc
Momentum & pc(size_t)
Central particle's 4-momentum.
Definition
Process.cpp:113
cepgen::proc::Process::weight
double weight(const std::vector< double > &)
Compute the weight for a phase-space point.
Definition
Process.cpp:234
cepgen::proc::Process::event
const Event & event() const
Handled particles objects and their relationships.
Definition
Process.cpp:267
cepgen::proc::Process::q1
const Momentum & q1() const
Positive-z incoming parton's 4-momentum.
Definition
Process.cpp:107
cepgen::utils::AbortHandler
Object handling an user-driven process abortion.
Definition
AbortHandler.h:39
Utils.h
cepgen::mg5amc::normalise
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
cepgen::proc::ProcessPtr
std::unique_ptr< Process > ProcessPtr
Helper typedef for a Process unique pointer.
Definition
Process.h:199
cepgen::utils::readFile
std::string readFile(const std::string &filename)
Read the content of a file into a string buffer.
Definition
Filesystem.cpp:31
cepgen::utils::positive
bool positive(const T &val)
Check if a number is positive and finite.
Definition
Math.cpp:26
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::loadLibrary
bool loadLibrary(const std::string &path, bool match)
Import a shared library in RTE Launch the initialisation procedure.
Definition
GlobalFunctions.cpp:42
cepgen::spdgids_t
std::vector< spdgid_t > spdgids_t
Definition
ParticleProperties.h:29
cepgen::utils::RunAbortedException
Exception raised when the user terminates the process.
Definition
AbortHandler.h:31
CepGenAddOns
MadGraphWrapper
MadGraphProcessBuilder.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7