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
25
26namespace cepgen {
28 public:
29 explicit ROOTDerivator(const ParametersList& params) : Derivator(params), order_(steer<int>("order")) {}
30
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
67REGISTER_DERIVATOR("root", ROOTDerivator);
#define REGISTER_DERIVATOR(name, obj)
Add a generic derivator object builder definition.
#define CG_FATAL(mod)
Definition Exception.h:61
A description object for parameters collection.
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
static ParametersDescription description()
Definition Derivator.cpp:31
ROOTDerivator(const ParametersList &params)
Definition Derivator.cpp:29
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition Steerable.h:39
Derivator(const ParametersList &params)
Definition Derivator.h:29
Wrapper to a 1-dimensional function with optional parameters.
Common namespace for this Monte Carlo generator.