cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
MISERIntegrator.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 <gsl/gsl_monte_miser.h>
20
24
25namespace cepgen {
27 class MISERIntegrator final : public GSLIntegrator {
28 public:
29 explicit MISERIntegrator(const ParametersList& params)
30 : GSLIntegrator(params), ncvg_(steer<int>("numFunctionCalls")) {}
31
33 auto desc = GSLIntegrator::description();
34 desc.setDescription("MISER adaptive importance sampling integrator");
35 desc.add<int>("numFunctionCalls", 50'000)
36 .setDescription("Number of function calls per phase space point evaluation");
37 desc.add<double>("estimateFraction", 0.1);
38 desc.add<int>("minCalls", 16 * 10);
39 desc.add<int>("minCallsPerBisection", 32 * 16 * 10);
40 desc.add<double>("alpha", 2.);
41 desc.add<double>("dither", 0.1);
42 return desc;
43 }
44
45 Value integrate(Integrand& integrand) override {
46 setIntegrand(integrand);
47 std::unique_ptr<gsl_monte_miser_state, decltype(&gsl_monte_miser_free)> miser_state(
48 gsl_monte_miser_alloc(function_->dim), gsl_monte_miser_free);
49 miser_state->verbose = verbosity_;
50 gsl_monte_miser_params_get(miser_state.get(), &miser_params_);
51 miser_params_.estimate_frac = steer<double>("estimateFraction");
52 miser_params_.min_calls = steer<int>("minCalls");
53 miser_params_.min_calls_per_bisection = steer<int>("minCallsPerBisection");
54 miser_params_.alpha = steer<double>("alpha");
55 miser_params_.dither = steer<double>("dither");
56 gsl_monte_miser_params_set(miser_state.get(), &miser_params_);
57
58 CG_DEBUG("Integrator:build") << "MISER parameters:\n\t"
59 << "Number of calls: " << miser_params_.min_calls << ", "
60 << "per bisection: " << miser_params_.min_calls_per_bisection << ",\n\t"
61 << "Estimate fraction: " << miser_params_.estimate_frac << ",\n\t"
62 << "α-value: " << miser_params_.alpha << ",\n\t"
63 << "Dither: " << miser_params_.dither << ".";
64
65 // launch the full integration
66 double result, abserr;
67 int res = gsl_monte_miser_integrate(function_.get(),
68 &xlow_[0],
69 &xhigh_[0],
70 function_->dim,
71 ncvg_,
72 rnd_gen_->engine<gsl_rng>(),
73 miser_state.get(),
74 &result,
75 &abserr);
76
77 if (res != GSL_SUCCESS)
78 throw CG_FATAL("Integrator:integrate") << "Error while performing the integration!\n\t"
79 << "GSL error: " << gsl_strerror(res) << ".";
80
81 return Value{result, abserr};
82 }
83
84 private:
85 const int ncvg_;
86 gsl_monte_miser_params miser_params_{};
87 };
88
89} // namespace cepgen
90REGISTER_INTEGRATOR("MISER", MISERIntegrator);
#define CG_FATAL(mod)
Definition Exception.h:61
#define REGISTER_INTEGRATOR(name, obj)
Add a generic process definition to the list of handled processes.
#define CG_DEBUG(mod)
Definition Message.h:220
std::vector< double > xhigh_
std::vector< double > xlow_
void setIntegrand(Integrand &)
std::unique_ptr< gsl_monte_function > function_
GSL structure storing the function to be integrated by this integrator instance (along with its param...
static ParametersDescription description()
An integrand wrapper placeholder.
Definition Integrand.h:27
int verbosity_
Integrator verbosity.
Definition Integrator.h:57
const std::unique_ptr< utils::RandomGenerator > rnd_gen_
Definition Integrator.h:56
MISER integration algorithm developed by W.H. Press and G.R. Farrar, as documented in .
MISERIntegrator(const ParametersList &params)
Value integrate(Integrand &integrand) override
Perform the multidimensional Monte Carlo integration.
static ParametersDescription description()
A description object for parameters collection.
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition Steerable.h:39
A scalar value with its uncertainty.
Definition Value.h:26
Common namespace for this Monte Carlo generator.