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
24
25namespace cepgen {
26 namespace utils {
27 class FunctionalMuParser final : public Functional {
28 public:
29 explicit FunctionalMuParser(const ParametersList&);
30 double eval() const override;
31
33
34 private:
35 mu::Parser parser_;
36 };
37
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
61 auto desc = Functional::description();
62 desc.setDescription("MuParser functional evaluator");
63 return desc;
64 }
65 } // namespace utils
66} // namespace cepgen
#define CG_ERROR(mod)
Definition Exception.h:60
#define REGISTER_FUNCTIONAL(name, obj)
Add a generic functional object builder definition.
cepgen::utils::FunctionalMuParser MuParserFunctional
#define CG_WARNING(mod)
Definition Message.h:228
A description object for parameters collection.
double eval() const override
Compute the functional for a given value of the variables.
FunctionalMuParser(const ParametersList &)
static ParametersDescription description()
A string-to-functional parser.
Definition Functional.h:32
std::vector< std::string > vars_
Computer-readable variable to be reached.
Definition Functional.h:62
std::string expression_
Computer-readable expression.
Definition Functional.h:63
static ParametersDescription description()
std::vector< double > values_
Last arguments list fed to the functional.
Definition Functional.h:64
Common namespace for this Monte Carlo generator.