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 <Math/Integrator.h>
20
#include <Math/IntegratorMultiDim.h>
21
22
#include "
CepGen/Integration/Integrand.h
"
23
#include "
CepGen/Integration/Integrator.h
"
24
#include "
CepGen/Modules/IntegratorFactory.h
"
25
#include "
CepGen/Utils/Message.h
"
26
27
namespace
cepgen
{
28
namespace
root
{
30
class
Integrator
final :
public
cepgen::Integrator
{
31
public
:
32
explicit
Integrator
(
const
ParametersList
& params)
33
:
cepgen
::
Integrator
(params),
34
type_(
steer
<std::string>(
"type"
)),
35
absTol_(
steer
<double>(
"absTol"
)),
36
relTol_(
steer
<double>(
"relTol"
)),
37
size_(
steer
<int>(
"size"
)) {
38
{
39
auto
type = ROOT::Math::IntegratorMultiDim::Type::kDEFAULT;
40
if
(type_ ==
"adaptive"
)
41
type = ROOT::Math::IntegratorMultiDim::Type::kADAPTIVE;
42
else
if
(type_ ==
"plain"
)
43
type = ROOT::Math::IntegratorMultiDim::Type::kPLAIN;
44
else
if
(type_ ==
"miser"
)
45
type = ROOT::Math::IntegratorMultiDim::Type::kMISER;
46
else
if
(type_ ==
"vegas"
)
47
type = ROOT::Math::IntegratorMultiDim::Type::kVEGAS;
48
integr_.reset(
new
ROOT::Math::IntegratorMultiDim(type, absTol_, relTol_, size_));
49
}
50
{
51
auto
type = ROOT::Math::IntegratorOneDim::Type::kDEFAULT;
52
if
(type_ ==
"gauss"
)
53
type = ROOT::Math::IntegratorOneDim::Type::kGAUSS;
54
else
if
(type_ ==
"legendre"
)
55
type = ROOT::Math::IntegratorOneDim::Type::kLEGENDRE;
56
else
if
(type_ ==
"adaptive"
)
57
type = ROOT::Math::IntegratorOneDim::Type::kADAPTIVE;
58
else
if
(type_ ==
"adaptiveSingular"
)
59
type = ROOT::Math::IntegratorOneDim::Type::kADAPTIVESINGULAR;
60
else
if
(type_ ==
"nonAdaptive"
)
61
type = ROOT::Math::IntegratorOneDim::Type::kNONADAPTIVE;
62
integr_1d_.reset(
new
ROOT::Math::IntegratorOneDim(type, absTol_, relTol_, size_));
63
}
64
//--- a bit of printout for debugging
65
CG_DEBUG
(
"Integrator:build"
) <<
"ROOT generic integrator built\n\t"
66
<<
"N-dimensional type: "
<< integr_->Name() <<
",\n\t"
67
<<
"1-dimensional type: "
<< integr_1d_->Name() <<
",\n\t"
68
<<
"Absolute tolerance: "
<< absTol_ <<
",\n\t"
69
<<
"Relative tolerance: "
<< relTol_ <<
",\n\t"
70
<<
"Number of sub-intervals: "
<< size_ <<
"."
;
71
}
72
73
static
ParametersDescription
description
() {
74
auto
desc =
cepgen::Integrator::description
();
75
desc.setDescription(
"ROOT general purpose MC integrator"
);
76
desc.add<std::string>(
"type"
,
"default"
);
77
desc.add<
double
>(
"absTol"
, -1.);
78
desc.add<
double
>(
"relTol"
, -1.);
79
desc.add<
int
>(
"size"
, 0);
80
return
desc;
81
}
82
83
void
setLimits
(
const
std::vector<Limits>& lims)
override
{
84
cepgen::Integrator::setLimits
(lims);
85
xlow_.clear();
86
xhigh_.clear();
87
for
(
const
auto
& lim :
limits_
) {
88
xlow_.emplace_back(lim.min());
89
xhigh_.emplace_back(lim.max());
90
}
91
}
92
Value
integrate
(
Integrand
& integrand)
override
{
93
checkLimits
(integrand);
94
95
if
(integrand.
size
() == 1) {
96
auto
funct = [&](
double
x) ->
double
{
return
integrand.
eval
(std::vector<double>{x}); };
97
integr_1d_->SetFunction(funct);
98
return
Value
{integr_1d_->Integral(
limits_
.at(0).min(),
limits_
.at(0).max()), integr_1d_->Error()};
99
}
100
auto
funct = [&](
const
double
* x) ->
double
{
101
return
integrand.
eval
(std::vector<double>(x, x + integrand.
size
()));
102
};
103
integr_->SetFunction(funct, integrand.
size
());
104
return
Value
{integr_->Integral(xlow_.data(), xhigh_.data()), integr_->Error()};
105
}
106
107
private
:
108
const
std::string type_;
109
const
double
absTol_;
110
const
double
relTol_;
111
const
unsigned
int
size_;
112
113
std::vector<double> xlow_, xhigh_;
114
std::unique_ptr<ROOT::Math::IntegratorMultiDim> integr_;
115
std::unique_ptr<ROOT::Math::IntegratorOneDim> integr_1d_;
116
};
117
}
// namespace root
118
}
// namespace cepgen
119
using
ROOTIntegrator
=
cepgen::root::Integrator
;
120
REGISTER_INTEGRATOR
(
"root"
,
ROOTIntegrator
);
Integrand.h
Integrator.h
IntegratorFactory.h
REGISTER_INTEGRATOR
#define REGISTER_INTEGRATOR(name, obj)
Add a generic process definition to the list of handled processes.
Definition
IntegratorFactory.h:25
Message.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
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
Monte-Carlo integration algorithm.
Definition
Integrator.h:28
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::limits_
std::vector< Limits > limits_
List of per-variable integration limits.
Definition
Integrator.h:58
cepgen::Integrator::description
static ParametersDescription description()
Definition
Integrator.cpp:71
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::Steerable::steer
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition
Steerable.h:39
cepgen::Value
A scalar value with its uncertainty.
Definition
Value.h:26
cepgen::root::Integrator
ROOT general-purpose integration algorithm.
Definition
Integrator.cpp:30
cepgen::root::Integrator::Integrator
Integrator(const ParametersList ¶ms)
Definition
Integrator.cpp:32
cepgen::root::Integrator::integrate
Value integrate(Integrand &integrand) override
Perform the multidimensional Monte Carlo integration.
Definition
Integrator.cpp:92
cepgen::root::Integrator::description
static ParametersDescription description()
Definition
Integrator.cpp:73
cepgen::root::Integrator::setLimits
void setLimits(const std::vector< Limits > &lims) override
Specify the variables limits on integration.
Definition
Integrator.cpp:83
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
python_modules.Integrators.root_cfi.root
root
Definition
root_cfi.py:3
CepGenAddOns
ROOTWrapper
Integrator.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7