cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Derivator.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2022 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 <TF1.h>
20
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Modules/DerivatorFactory.h
"
23
#include "
CepGen/Utils/Derivator.h
"
24
#include "
CepGen/Utils/FunctionsWrappers.h
"
25
26
namespace
cepgen
{
27
class
ROOTDerivator
:
public
utils::Derivator
{
28
public
:
29
explicit
ROOTDerivator
(
const
ParametersList
& params) :
Derivator
(params), order_(
steer
<int>(
"order"
)) {}
30
31
static
ParametersDescription
description
() {
32
auto
desc = Derivator::description();
33
desc.setDescription(
"ROOT derivation algorithm (Richardson's extrapolation method)"
);
34
desc.add<
int
>(
"order"
, 1).setDescription(
"order of the derivation"
);
35
return
desc;
36
}
37
42
double
derivate
(
const
utils::Function1D
& func,
double
x,
double
h = -1.)
const override
{
43
auto
rfunc = TF1(
44
"cepgen_functional"
,
45
[&func](
double
vars[1],
double
* pars) {
return
func(vars[0],
static_cast<
void
*
>
(pars)); },
46
0.,
47
1.,
48
0);
49
const
auto
epsilon = h < 0. ?
h_
: h;
50
switch
(order_) {
51
case
1:
52
return
rfunc.Derivative(x,
nullptr
, epsilon);
53
case
2:
54
return
rfunc.Derivative2(x,
nullptr
, epsilon);
55
case
3:
56
return
rfunc.Derivative3(x,
nullptr
, epsilon);
57
default
:
58
throw
CG_FATAL
(
"ROOTDerivator"
) <<
"Invalid derivation order requested: "
<< order_ <<
"."
;
59
}
60
}
61
62
private
:
63
const
int
order_;
64
};
65
}
// namespace cepgen
66
67
REGISTER_DERIVATOR
(
"root"
, ROOTDerivator);
DerivatorFactory.h
REGISTER_DERIVATOR
#define REGISTER_DERIVATOR(name, obj)
Add a generic derivator object builder definition.
Definition
DerivatorFactory.h:25
Derivator.h
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
FunctionsWrappers.h
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::ROOTDerivator
Definition
Derivator.cpp:27
cepgen::ROOTDerivator::derivate
double derivate(const utils::Function1D &func, double x, double h=-1.) const override
Evaluate the derivative of a function at a given value.
Definition
Derivator.cpp:42
cepgen::ROOTDerivator::description
static ParametersDescription description()
Definition
Derivator.cpp:31
cepgen::ROOTDerivator::ROOTDerivator
ROOTDerivator(const ParametersList ¶ms)
Definition
Derivator.cpp:29
cepgen::Steerable::steer
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition
Steerable.h:39
cepgen::utils::Derivator
Definition
Derivator.h:27
cepgen::utils::Derivator::Derivator
Derivator(const ParametersList ¶ms)
Definition
Derivator.h:29
cepgen::utils::Derivator::h_
const double h_
Definition
Derivator.h:51
cepgen::utils::Function1D
Wrapper to a 1-dimensional function with optional parameters.
Definition
FunctionsWrappers.h:29
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
ROOTWrapper
Derivator.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7