cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Functional.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-2021 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 "
CepGen/Core/Exception.h
"
20
#include "
CepGen/Core/ParametersList.h
"
21
#include "
CepGen/Utils/Functional.h
"
22
#include "
CepGen/Utils/String.h
"
23
24
namespace
cepgen
{
25
namespace
utils {
26
Functional::Functional
(
const
ParametersList
& params)
27
:
NamedModule
(params),
28
vars_orig_(steer<std::vector<std::string> >(
"variables"
)),
29
expression_orig_(steer<std::string>(
"expression"
)),
30
vars_(vars_orig_),
31
expression_(expression_orig_),
32
values_(vars_.size()) {
33
for
(
size_t
i = 0; i <
vars_
.size(); ++i) {
34
vars_
.at(i) =
sanitise
(
vars_
.at(i));
35
replaceAll
(
expression_
, vars_orig_.at(i),
vars_
.at(i));
36
}
37
}
38
39
double
Functional::operator()
(
double
x)
const
{
40
if
(vars_orig_.size() != 1)
41
throw
CG_FATAL
(
"Functional"
) <<
"This function only works with single-dimensional functions!"
;
42
return
operator()
(std::vector<double>{x});
43
}
44
45
double
Functional::operator()
(
const
std::vector<double>& x)
const
{
46
if
(
vars_
.size() != x.size())
47
throw
CG_FATAL
(
"Functional"
) <<
"Invalid number of variables fed to the evaluator! Expecting "
<<
vars_
.size()
48
<<
", got "
<< x.size() <<
"."
;
49
values_
= x;
50
return
eval
();
51
}
52
53
ParametersList
Functional::fromExpression
(
const
std::string& expr,
const
std::vector<std::string>& vars) {
54
return
ParametersList
().
set
<std::string>(
"expression"
, expr).set<std::vector<std::string> >(
"variables"
, vars);
55
}
56
57
ParametersDescription
Functional::description
() {
58
auto
desc =
ParametersDescription
();
59
desc.setDescription(
"Unnamed functional evaluator"
);
60
desc.add<std::vector<std::string> >(
"variables"
, {}).setDescription(
"List of variables to evaluate"
);
61
desc.add<std::string>(
"expression"
,
""
).setDescription(
"Functional expression"
);
62
return
desc;
63
}
64
}
// namespace utils
65
}
// namespace cepgen
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
Functional.h
ParametersList.h
String.h
cepgen::NamedModule
Base runtime module object.
Definition
NamedModule.h:28
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::ParametersList::set
ParametersList & set(const std::string &, const T &)
Set a parameter value Set a recast parameter value.
Definition
ParametersList.cpp:401
cepgen::utils::Functional::operator()
double operator()(double x) const
Compute the functional for a given value of the variable (one-dimensional case)
Definition
Functional.cpp:39
cepgen::utils::Functional::vars_
std::vector< std::string > vars_
Computer-readable variable to be reached.
Definition
Functional.h:62
cepgen::utils::Functional::Functional
Functional(const ParametersList &)
Default constructor.
Definition
Functional.cpp:26
cepgen::utils::Functional::eval
virtual double eval() const =0
Compute the functional for a given value of the variables.
cepgen::utils::Functional::expression_
std::string expression_
Computer-readable expression.
Definition
Functional.h:63
cepgen::utils::Functional::description
static ParametersDescription description()
Definition
Functional.cpp:57
cepgen::utils::Functional::fromExpression
static ParametersList fromExpression(const std::string &expr, const std::vector< std::string > &vars)
Build a collection of parameters to define a functional from its mathematical expression.
Definition
Functional.cpp:53
cepgen::utils::Functional::values_
std::vector< double > values_
Last arguments list fed to the functional.
Definition
Functional.h:64
cepgen::utils::sanitise
std::string sanitise(const std::string &str)
Replace all unsafe characters to build a computer-readable (and filename-safe) string.
Definition
String.cpp:105
cepgen::utils::replaceAll
size_t replaceAll(std::string &str, const std::string &from, const std::string &to)
Replace all occurrences of a text by another.
Definition
String.cpp:118
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Utils
Functional.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7