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
20#include "CepGen/Generator.h"
24#include "CepGen/Utils/Drawer.h"
26#include "CepGen/Utils/Graph.h"
27
28using namespace std;
29
30int 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
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);
93 if (draw_grid)
95 if (ratio_plot)
97
98 if (func_2d) {
99 if (log)
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)
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}
#define CG_WARNING(mod)
Definition Message.h:228
#define CG_LOG
Definition Message.h:212
A generic command line arguments parser.
ArgumentsParser & parse()
Associate command-line arguments to parameters.
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Validity interval for a variable.
Definition Limits.h:28
bool hasMin() const
Have a lower limit?
Definition Limits.cpp:73
bool hasMax() const
Have an upper limit?
Definition Limits.cpp:75
double min() const
Lower limit to apply on the variable.
Definition Limits.h:52
double max() const
Upper limit to apply on the variable.
Definition Limits.h:54
std::vector< const Drawable * > DrawableColl
A collection of drawable objects.
Definition Drawer.h:34
void initialise(bool safe_mode)
int main()