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
25
26namespace cepgen {
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
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
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_DEBUG(mod)
Definition Message.h:220
Wrapper to the function to be integrated.
An integrand wrapper placeholder.
Definition Integrand.h:27
virtual double eval(const std::vector< double > &)=0
Compute the integrand for a given coordinates set.
virtual size_t size() const =0
Phase space dimension.
void checkLimits(const Integrand &)
Ensure the integration bounds are properly set.
virtual void setLimits(const std::vector< Limits > &limits)
Specify the variables limits on integration.
Definition Integrator.h:38
Integrator(const ParametersList &params)
Integrator algorithm constructor.
virtual double uniform(const Limits &={0., 1.}) const
Generate a uniformly distributed (between 0 and 1) random number.
virtual double eval(Integrand &, const std::vector< double > &) const
Compute the function value at the given phase space point.
std::vector< Limits > limits_
List of per-variable integration limits.
Definition Integrator.h:58
const std::unique_ptr< utils::RandomGenerator > rnd_gen_
Definition Integrator.h:56
static ParametersDescription description()
virtual Value integrate(Integrand &result)=0
Perform the multidimensional Monte Carlo integration.
Validity interval for a variable.
Definition Limits.h:28
double min() const
Lower limit to apply on the variable.
Definition Limits.h:52
double max() const
Upper limit to apply on the variable.
Definition Limits.h:54
Base runtime module object.
Definition NamedModule.h:28
A description object for parameters collection.
A scalar value with its uncertainty.
Definition Value.h:26
Common namespace for this Monte Carlo generator.