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-2024 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 <TFormula.h>
20
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Modules/FunctionalFactory.h
"
23
#include "
CepGen/Utils/Functional.h
"
24
#include "
CepGen/Utils/String.h
"
25
26
namespace
cepgen
{
27
namespace
root
{
29
class
Functional
final :
public
cepgen::utils::Functional
{
30
public
:
31
explicit
Functional
(
const
ParametersList
& params) :
cepgen
::utils::
Functional
(params) {
32
for
(
auto
& var :
vars_
)
33
func_.AddVariable(var, 0.);
34
auto
expr =
expression_
;
35
expr =
utils::replaceAll
(expr, {{
"min("
,
"TMath::Min("
}, {
"max("
,
"TMath::Max("
}});
36
if
(func_.Compile(expr.c_str()) != 0)
37
throw
CG_ERROR
(
"root:Functional"
) <<
"Failed to define the function\n\t"
<<
expression_
;
38
CG_DEBUG
(
"root:Functional"
) <<
"Successfully defined a dimension-"
<<
vars_
.size()
39
<<
" function with arguments "
<<
vars_
<<
": "
<< expr <<
"."
;
40
}
41
inline
double
eval
()
const override
{
42
if
(!func_.IsValid())
43
throw
CG_WARNING
(
"root:Functional"
) <<
"Cannot evaluate the invalid function at "
<<
values_
<<
"."
;
44
return
func_.EvalPar(
values_
.data());
45
}
46
47
inline
static
ParametersDescription
description
() {
48
auto
desc =
cepgen::utils::Functional::description
();
49
desc.setDescription(
"Plain old TFormula evaluator from ROOT"
);
50
return
desc;
51
}
52
53
private
:
54
TFormula func_;
55
};
56
}
// namespace root
57
}
// namespace cepgen
58
using
cepgen::root::Functional
;
59
REGISTER_FUNCTIONAL
(
"root"
,
Functional
);
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
Functional.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
String.h
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::root::Functional
Functional evaluator defined from a ROOT TFormula.
Definition
Functional.cpp:29
cepgen::root::Functional::eval
double eval() const override
Compute the functional for a given value of the variables.
Definition
Functional.cpp:41
cepgen::root::Functional::description
static ParametersDescription description()
Definition
Functional.cpp:47
cepgen::root::Functional::Functional
Functional(const ParametersList ¶ms)
Definition
Functional.cpp:31
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::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
python_modules.Integrators.root_cfi.root
root
Definition
root_cfi.py:3
CepGenAddOns
ROOTWrapper
Functional.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7