cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
cepgenPlotFunction.cc
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-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 "
CepGen/Core/Exception.h
"
20
#include "
CepGen/Generator.h
"
21
#include "
CepGen/Modules/DrawerFactory.h
"
22
#include "
CepGen/Modules/FunctionalFactory.h
"
23
#include "
CepGen/Utils/ArgumentsParser.h
"
24
#include "
CepGen/Utils/Drawer.h
"
25
#include "
CepGen/Utils/Functional.h
"
26
#include "
CepGen/Utils/Graph.h
"
27
28
using namespace
std;
29
30
int
main
(
int
argc,
char
* argv[]) {
31
string
function, plotter;
32
vector<string> functionals;
33
int
num_points;
34
cepgen::Limits
xrange, yrange;
35
bool
log, draw_grid, func_2d, ratio_plot;
36
37
cepgen::ArgumentsParser
(argc, argv)
38
.
addOptionalArgument
(
"function,f"
,
"function to parse"
, &function,
"min(1.,exp(-x/10))"
)
39
.
addOptionalArgument
(
"functional-eval,F"
,
"functional evaluators"
, &functionals, vector<string>{})
40
.addOptionalArgument(
"num-points,n"
,
"number of points to consider"
, &num_points, 100)
41
.
addOptionalArgument
(
"x-range,x"
,
"horizontal axis range"
, &xrange,
cepgen::Limits
{-5., +5.})
42
.addOptionalArgument(
"y-range,y"
,
"vertical axis range"
, &yrange,
cepgen::Limits
{})
43
.addOptionalArgument(
"draw-grid,g"
,
"draw the x/y grid"
, &draw_grid,
false
)
44
.
addOptionalArgument
(
"log,l"
,
"logarithmic y-axis"
, &log,
false
)
45
.
addOptionalArgument
(
"plotter,p"
,
"type of plotter to user"
, &plotter,
""
)
46
.
addOptionalArgument
(
"ratio,r"
,
"draw the ratio plot"
, &ratio_plot,
false
)
47
.
addOptionalArgument
(
"2d,t"
,
"two-dimensional function"
, &func_2d,
false
)
48
.
parse
();
49
50
cepgen::initialise
();
51
52
if
(functionals.empty())
53
functionals = cepgen::FunctionalFactory::get().modules();
54
CG_LOG
<<
"Function to be plotted: "
<< function <<
", functional evaluators: "
<< functionals <<
"."
;
55
56
// maps functional evaluators -> graphs
57
map<string, cepgen::utils::Graph1D> m_gr_fb;
58
map<string, cepgen::utils::Graph2D> m_gr2d_fb;
59
for
(
const
auto
& func : functionals) {
60
CG_LOG
<<
"Building \""
<< func <<
"\" functional."
;
61
try
{
62
vector<string> vars{
"x"
};
63
if
(func_2d)
64
vars.emplace_back(
"y"
);
65
auto
test = cepgen::FunctionalFactory::get().build(
66
func,
cepgen::ParametersList
().set<string>(
"expression"
, function).set<vector<string> >(
"variables"
, vars));
67
if
(func_2d) {
68
if
(!yrange.
hasMin
())
69
yrange.
min
() = xrange.
min
();
70
if
(!yrange.
hasMax
())
71
yrange.
max
() = xrange.
max
();
72
for
(
int
i = 0; i < num_points; ++i) {
73
const
double
x = xrange.
min
() + (xrange.
max
() - xrange.
min
()) / (num_points - 1) * i;
74
for
(
int
j = 0; j < num_points; ++j) {
75
const
double
y = yrange.
min
() + (yrange.
max
() - yrange.
min
()) / (num_points - 1) * j;
76
m_gr2d_fb[func].addPoint(x, y, (*test)({x, y}));
77
}
78
}
79
}
else
80
for
(
int
i = 0; i < num_points; ++i) {
81
const
double
x = xrange.
min
() + (xrange.
max
() - xrange.
min
()) / (num_points - 1) * i;
82
m_gr_fb[func].addPoint(x, (*test)(x));
83
}
84
}
catch
(
const
cepgen::Exception
&) {
85
CG_WARNING
(
"main"
) <<
"Exception encountered in \""
<< func <<
"\" functional builder."
;
86
continue
;
87
}
88
}
89
90
if
(!plotter.empty()) {
91
auto
plt = cepgen::DrawerFactory::get().build(plotter);
92
cepgen::utils::Drawer::Mode
dm;
93
if
(draw_grid)
94
dm |=
cepgen::utils::Drawer::Mode::grid
;
95
if
(ratio_plot)
96
dm |=
cepgen::utils::Drawer::Mode::ratio
;
97
98
if
(func_2d) {
99
if
(log)
100
dm |=
cepgen::utils::Drawer::Mode::logz
;
101
for
(
auto
& gr_fb : m_gr2d_fb) {
102
gr_fb.second.setName(
"graph2d_"
+ gr_fb.first);
103
gr_fb.second.setTitle(gr_fb.first);
104
plt->draw(gr_fb.second, dm);
105
}
106
}
else
{
107
if
(log)
108
dm |=
cepgen::utils::Drawer::Mode::logy
;
109
cepgen::utils::DrawableColl
mg;
110
for
(
auto
& gr_fb : m_gr_fb) {
111
gr_fb.second.setTitle(gr_fb.first);
112
mg.emplace_back(&gr_fb.second);
113
}
114
plt->draw(mg,
"comp_functionals"
,
""
, dm);
115
}
116
}
117
118
return
0;
119
}
ArgumentsParser.h
DrawerFactory.h
Drawer.h
Exception.h
FunctionalFactory.h
Functional.h
Generator.h
Graph.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
CG_LOG
#define CG_LOG
Definition
Message.h:212
cepgen::ArgumentsParser
A generic command line arguments parser.
Definition
ArgumentsParser.h:31
cepgen::ArgumentsParser::parse
ArgumentsParser & parse()
Associate command-line arguments to parameters.
Definition
ArgumentsParser.cpp:106
cepgen::ArgumentsParser::addOptionalArgument
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Definition
ArgumentsParser.h:46
cepgen::Exception
Definition
Exception.h:25
cepgen::Limits
Validity interval for a variable.
Definition
Limits.h:28
cepgen::Limits::hasMin
bool hasMin() const
Have a lower limit?
Definition
Limits.cpp:73
cepgen::Limits::hasMax
bool hasMax() const
Have an upper limit?
Definition
Limits.cpp:75
cepgen::Limits::min
double min() const
Lower limit to apply on the variable.
Definition
Limits.h:52
cepgen::Limits::max
double max() const
Upper limit to apply on the variable.
Definition
Limits.h:54
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::utils::Drawer::Mode
Definition
Drawer.h:41
cepgen::utils::Drawer::Mode::logz
@ logz
Definition
Drawer.h:47
cepgen::utils::Drawer::Mode::grid
@ grid
Definition
Drawer.h:49
cepgen::utils::Drawer::Mode::ratio
@ ratio
Definition
Drawer.h:52
cepgen::utils::Drawer::Mode::logy
@ logy
Definition
Drawer.h:46
cepgen::utils::DrawableColl
std::vector< const Drawable * > DrawableColl
A collection of drawable objects.
Definition
Drawer.h:34
cepgen::initialise
void initialise(bool safe_mode)
Definition
GlobalFunctions.cpp:91
main
int main()
Definition
pythia6_decay.cc:9
src
utils
cepgenPlotFunction.cc
Generated on Mon Jul 29 2024 for CepGen by
1.9.7