cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
cepgenScanPhaseSpace.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
21#include "CepGen/Generator.h"
25#include "CepGen/Utils/Drawer.h"
26#include "CepGen/Utils/Graph.h"
27#include "CepGen/Utils/String.h"
28
29using namespace std;
30
31int main(int argc, char* argv[]) {
32 string input_card, plotter;
33 int npoints;
34 vector<int> dim;
35 double def;
36 bool draw_grid, log;
37
38 cepgen::ArgumentsParser(argc, argv)
39 .addArgument("input,i", "input card", &input_card)
40 .addOptionalArgument("default,D", "default value for non-varying coordinates", &def, 0.5)
41 .addOptionalArgument("dim,s", "dimensions to probe", &dim, vector<int>{0, 1})
42 .addOptionalArgument("num-points,n", "number of points to probe", &npoints, 100)
43 .addOptionalArgument("draw-grid,g", "draw the x/y grid", &draw_grid, false)
44 .addOptionalArgument("log,l", "logarithmic axis", &log, false)
45 .addOptionalArgument("plotter,p", "type of plotter to user", &plotter, "")
46 .parse();
47
48 cepgen::utils::Graph1D gr_scan_1d("test_scan");
49 cepgen::utils::Graph2D gr_scan_2d("test_scan");
50 if (dim.size() > 3)
51 throw CG_FATAL("main") << "Number of dimensions to probe (" << dim.size() << ") is too high";
52
54 gen.parseRunParameters(input_card);
55 CG_LOG << gen.runParameters();
56 const size_t ndim = gen.runParameters().process().ndim();
57
58 vector<double> coord(ndim, def);
59
60 for (int i = 0; i < npoints; ++i) {
61 const double x = i * 1. / npoints;
62 switch (dim.size()) {
63 case 0:
64 gr_scan_1d.addPoint(x, gen.computePoint(vector<double>(ndim, x)));
65 break;
66 case 1:
67 coord[dim.at(0)] = x;
68 gr_scan_1d.addPoint(x, gen.computePoint(coord));
69 break;
70 case 2:
71 coord[dim.at(0)] = x;
72 for (int j = 0; j < npoints; ++j) {
73 const double y = j * 1. / npoints;
74 coord[dim.at(1)] = y;
75 gr_scan_2d.addPoint(x, y, gen.computePoint(coord));
76 }
77 break;
78 }
79 }
80 if (!plotter.empty()) {
81 auto plt = cepgen::DrawerFactory::get().build(plotter);
83 if (draw_grid)
85 switch (dim.size()) {
86 case 0:
87 case 1: {
88 if (log)
90 string xlabel;
91 if (dim.empty())
92 xlabel = cepgen::utils::format("x_{i = 0, ..., %ld}", ndim - 1);
93 else
94 xlabel = cepgen::utils::format("x_{%d}", dim.at(0));
95 gr_scan_1d.setTitle(cepgen::utils::format("%s variation, all others x_{i} at %g", xlabel.c_str(), def));
96 gr_scan_1d.xAxis().setLabel(xlabel);
97 gr_scan_2d.yAxis().setLabel(cepgen::utils::format("d^{%ld}#sigma/d#bf{x}^{%ld}", ndim, ndim));
98 plt->draw(gr_scan_1d, dm);
99 } break;
100 case 2: {
101 if (log)
103 string xlabel = cepgen::utils::format("x_{%d}", dim.at(0)), ylabel = cepgen::utils::format("x_{%d}", dim.at(1));
104 gr_scan_2d.setTitle(
105 cepgen::utils::format("(%s, %s) variation, all others x_{i} at %g", xlabel.c_str(), ylabel.c_str(), def));
106 gr_scan_2d.xAxis().setLabel(xlabel);
107 gr_scan_2d.yAxis().setLabel(ylabel);
108 gr_scan_2d.zAxis().setLabel(cepgen::utils::format("d^{%ld}#sigma/d#bf{x}^{%ld}", ndim, ndim));
109 plt->draw(gr_scan_2d, dm);
110 }
111 }
112 }
113
114 return 0;
115}
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_LOG
Definition Message.h:212
A generic command line arguments parser.
ArgumentsParser & addArgument(Args &&... args)
Add a parameter required for the parser.
ArgumentsParser & parse()
Associate command-line arguments to parameters.
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Core generator object allowing for process definition, cross section computation, and event generatio...
Definition Generator.h:48
double computePoint(const std::vector< double > &x)
Compute one single point from the total phase space.
Definition Generator.cpp:90
void parseRunParameters(const std::string &)
Read a steering card to populate the run parameters block.
Definition Generator.cpp:72
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition Generator.cpp:76
proc::Process & process()
Process object for cross-section computation/events generation.
size_t ndim() const
Number of dimensions on which the integration is performed.
Definition Process.h:60
AxisInfo & setLabel(const std::string &label)
Set the axis title.
Definition Drawable.h:50
AxisInfo & yAxis()
Definition Drawable.h:81
AxisInfo & zAxis()
Definition Drawable.h:83
AxisInfo & xAxis()
Definition Drawable.h:79
void setTitle(const std::string &title)
Set the drawable title.
Definition Drawable.h:44
A one-dimensional graph object.
Definition Graph.h:29
Graph1D & addPoint(double x, double y)
Add one value to the graph.
Definition Graph.cpp:30
A two-dimensional graph object.
Definition Graph.h:58
Graph2D & addPoint(double x, double y, double z)
Add one value to the graph.
Definition Graph.cpp:82
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition String.h:61
int main()