cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
FunctionalMuParser.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 <muParser.h>
20
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Modules/FunctionalFactory.h
"
23
#include "
CepGen/Utils/Functional.h
"
24
25
namespace
cepgen
{
26
namespace
utils {
27
class
FunctionalMuParser
final :
public
Functional
{
28
public
:
29
explicit
FunctionalMuParser
(
const
ParametersList
&);
30
double
eval
()
const override
;
31
32
static
ParametersDescription
description
();
33
34
private
:
35
mu::Parser parser_;
36
};
37
38
FunctionalMuParser::FunctionalMuParser
(
const
ParametersList
& params) :
Functional
(params) {
39
try
{
40
for
(
size_t
i = 0; i <
vars_
.size(); ++i)
41
parser_.DefineVar(
vars_
[i], &
values_
[i]);
42
parser_.SetExpr(
expression_
);
43
}
catch
(
const
mu::Parser::exception_type& e) {
44
throw
CG_ERROR
(
"FunctionalMuParser"
)
45
<<
"Failed to define the function\n\t"
<<
expression_
<<
"\n\t"
<< std::string(e.GetPos(),
'-'
) +
"^"
46
<<
"\n\t"
<< e.GetMsg();
47
}
48
}
49
50
double
FunctionalMuParser::eval
()
const
{
51
try
{
52
return
parser_.Eval();
53
}
catch
(
const
mu::Parser::exception_type& e) {
54
throw
CG_WARNING
(
"FunctionalMuParser"
)
55
<<
"Failed to evaluate the function\n\t"
<<
expression_
<<
"\n\t"
<< std::string(e.GetPos(),
'-'
) +
"^"
56
<<
"\n\t"
<< e.GetMsg();
57
}
58
}
59
60
ParametersDescription
FunctionalMuParser::description
() {
61
auto
desc =
Functional::description
();
62
desc.setDescription(
"MuParser functional evaluator"
);
63
return
desc;
64
}
65
}
// namespace utils
66
}
// namespace cepgen
67
typedef
cepgen::utils::FunctionalMuParser
MuParserFunctional
;
68
REGISTER_FUNCTIONAL
(
"MuParser"
,
MuParserFunctional
);
Exception.h
CG_ERROR
#define CG_ERROR(mod)
Definition
Exception.h:60
FunctionalFactory.h
REGISTER_FUNCTIONAL
#define REGISTER_FUNCTIONAL(name, obj)
Add a generic functional object builder definition.
Definition
FunctionalFactory.h:25
MuParserFunctional
cepgen::utils::FunctionalMuParser MuParserFunctional
Definition
FunctionalMuParser.cpp:67
Functional.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::utils::FunctionalMuParser
Definition
FunctionalMuParser.cpp:27
cepgen::utils::FunctionalMuParser::eval
double eval() const override
Compute the functional for a given value of the variables.
Definition
FunctionalMuParser.cpp:50
cepgen::utils::FunctionalMuParser::FunctionalMuParser
FunctionalMuParser(const ParametersList &)
Definition
FunctionalMuParser.cpp:38
cepgen::utils::FunctionalMuParser::description
static ParametersDescription description()
Definition
FunctionalMuParser.cpp:60
cepgen::utils::Functional
A string-to-functional parser.
Definition
Functional.h:32
cepgen::utils::Functional::vars_
std::vector< std::string > vars_
Computer-readable variable to be reached.
Definition
Functional.h:62
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::values_
std::vector< double > values_
Last arguments list fed to the functional.
Definition
Functional.h:64
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
Functionals
FunctionalMuParser.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7