cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Integrator.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-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 "
CepGen/Core/Exception.h
"
20
#include "
CepGen/Core/ParametersList.h
"
21
#include "
CepGen/Integration/FunctionIntegrand.h
"
22
#include "
CepGen/Integration/Integrator.h
"
23
#include "
CepGen/Modules/IntegratorFactory.h
"
24
#include "
CepGen/Modules/RandomGeneratorFactory.h
"
25
26
namespace
cepgen
{
27
Integrator::Integrator
(
const
ParametersList
& params)
28
:
NamedModule
(params),
29
rnd_gen_(RandomGeneratorFactory::get().build(steer<
ParametersList
>(
"randomGenerator"
))),
30
verbosity_(steer<int>(
"verbose"
)) {}
31
32
void
Integrator::checkLimits
(
const
Integrand
& integrand) {
33
const
auto
ps_size = integrand.
size
();
34
if
(ps_size == 0)
35
throw
CG_FATAL
(
"Integrator:checkLimits"
) <<
"Invalid phase space dimension for integrand: "
<< ps_size <<
"."
;
36
else
if
(
limits_
.empty())
37
setLimits
(std::vector<Limits>(ps_size,
Limits
{0., 1.}));
38
else
if
(
limits_
.size() != ps_size) {
39
CG_DEBUG
(
"Integrator:checkLimits"
) <<
"Incompatible phase space size: prepared="
<<
limits_
.size()
40
<<
", integrand="
<< ps_size <<
"."
;
41
auto
lims =
limits_
;
42
const
auto
booked_size = lims.size();
43
if
(booked_size < ps_size)
44
for
(
size_t
i = 0; i < ps_size - booked_size; ++i)
45
lims.emplace_back(0., 1.);
46
else
47
lims.resize(ps_size);
48
setLimits
(lims);
49
}
50
}
51
52
double
Integrator::eval
(
Integrand
& integrand,
const
std::vector<double>& x)
const
{
return
integrand.
eval
(x); }
53
54
double
Integrator::uniform
(
const
Limits
& lim)
const
{
return
rnd_gen_
->uniform(lim.
min
(), lim.
max
()); }
55
56
Value
Integrator::integrate
(
const
std::function<
double
(
const
std::vector<double>&)>& func,
57
const
ParametersList
& params,
58
size_t
num_vars) {
59
return
integrate
(func, params, std::vector<Limits>(num_vars,
Limits
{0., 1.}));
60
}
61
62
Value
Integrator::integrate
(
const
std::function<
double
(
const
std::vector<double>&)>& func,
63
const
ParametersList
& params,
64
const
std::vector<Limits>& limits) {
65
auto
integr = IntegratorFactory::get().build(params);
66
integr->setLimits(limits);
67
auto
integrand =
FunctionIntegrand
(limits.size(), func);
68
return
integr->integrate(integrand);
69
}
70
71
ParametersDescription
Integrator::description
() {
72
auto
desc =
ParametersDescription
();
73
desc.setDescription(
"Unnamed integrator"
);
74
desc.add<
int
>(
"verbose"
, 1).setDescription(
"Verbosity level"
);
75
desc.add<
ParametersDescription
>(
"randomGenerator"
, RandomGeneratorFactory::get().describeParameters(
"stl"
))
76
.setDescription(
"random number generator engine"
);
77
return
desc;
78
}
79
}
// namespace cepgen
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
FunctionIntegrand.h
Integrator.h
IntegratorFactory.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
ParametersList.h
RandomGeneratorFactory.h
cepgen::FunctionIntegrand
Wrapper to the function to be integrated.
Definition
FunctionIntegrand.h:28
cepgen::Integrand
An integrand wrapper placeholder.
Definition
Integrand.h:27
cepgen::Integrand::eval
virtual double eval(const std::vector< double > &)=0
Compute the integrand for a given coordinates set.
cepgen::Integrand::size
virtual size_t size() const =0
Phase space dimension.
cepgen::Integrator::checkLimits
void checkLimits(const Integrand &)
Ensure the integration bounds are properly set.
Definition
Integrator.cpp:32
cepgen::Integrator::setLimits
virtual void setLimits(const std::vector< Limits > &limits)
Specify the variables limits on integration.
Definition
Integrator.h:38
cepgen::Integrator::Integrator
Integrator(const ParametersList ¶ms)
Integrator algorithm constructor.
Definition
Integrator.cpp:27
cepgen::Integrator::uniform
virtual double uniform(const Limits &={0., 1.}) const
Generate a uniformly distributed (between 0 and 1) random number.
Definition
Integrator.cpp:54
cepgen::Integrator::eval
virtual double eval(Integrand &, const std::vector< double > &) const
Compute the function value at the given phase space point.
Definition
Integrator.cpp:52
cepgen::Integrator::limits_
std::vector< Limits > limits_
List of per-variable integration limits.
Definition
Integrator.h:58
cepgen::Integrator::rnd_gen_
const std::unique_ptr< utils::RandomGenerator > rnd_gen_
Definition
Integrator.h:56
cepgen::Integrator::description
static ParametersDescription description()
Definition
Integrator.cpp:71
cepgen::Integrator::integrate
virtual Value integrate(Integrand &result)=0
Perform the multidimensional Monte Carlo integration.
cepgen::Limits
Validity interval for a variable.
Definition
Limits.h:28
cepgen::Limits::min
double min() const
Lower limit to apply on the variable.
Definition
Limits.h:52
cepgen::Limits::max
double max() const
Upper limit to apply on the variable.
Definition
Limits.h:54
cepgen::NamedModule
Base runtime module object.
Definition
NamedModule.h:28
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Value
A scalar value with its uncertainty.
Definition
Value.h:26
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Integration
Integrator.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7