cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
cepgenPlotKTFluxes.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2023 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 <fstream>
20
21#include "CepGen/Generator.h"
26#include "CepGen/Utils/Drawer.h"
27#include "CepGen/Utils/Graph.h"
29#include "CepGen/Utils/String.h"
30
31using namespace std;
32using namespace std::string_literals;
33
34int main(int argc, char* argv[]) {
35 vector<string> fluxes_names;
36 int num_points;
37 double kt2, mx, q2;
38 string output_file, plotter;
39 bool logx, logy, draw_grid, normalised, ratio_plot;
40 cepgen::Limits x_range, y_range;
41
43
44 cepgen::ArgumentsParser(argc, argv)
46 "fluxes,f", "parton fluxes modellings", &fluxes_names, cepgen::KTFluxFactory::get().modules())
47 .addOptionalArgument("mx,M", "diffractive mass (GeV)", &mx, 1.5)
48 .addOptionalArgument("q2,q", "parton virtuality (GeV^2)", &q2, -1.)
49 .addOptionalArgument("xrange,x", "fractional loss range", &x_range, cepgen::Limits{0., 1.})
50 .addOptionalArgument("yrange,y", "y range", &y_range)
51 .addOptionalArgument("kt2,k", "parton transverse virtuality (GeV^2)", &kt2, 10.)
52 .addOptionalArgument("npoints,n", "number of x-points to scan", &num_points, 100)
53 .addOptionalArgument("output,o", "output file name", &output_file, "flux.scan.output.txt")
54 .addOptionalArgument("plotter,p", "type of plotter to user", &plotter, "")
55 .addOptionalArgument("logx", "logarithmic x-scale", &logx, false)
56 .addOptionalArgument("logy,l", "logarithmic y-scale", &logy, false)
57 .addOptionalArgument("draw-grid,g", "draw the x/y grid", &draw_grid, false)
58 .addOptionalArgument("ratio,r", "draw the ratio plot", &ratio_plot, false)
59 .addOptionalArgument("normalised", "plot xf(x) instead of f(x)", &normalised, false)
60 .parse();
61
62 const bool plot_vs_q2 = (q2 >= 0.);
63 if (logx && x_range.min() == 0.)
64 x_range.min() = 1.e-3;
65 if (x_range.max() == 1.)
66 x_range.max() -= 1.e-15;
67
68 vector<std::unique_ptr<cepgen::KTFlux> > fluxes;
69 vector<cepgen::utils::Graph1D> graph_flux;
70 for (const auto& flux : fluxes_names) {
71 fluxes.emplace_back(cepgen::KTFluxFactory::get().build(flux));
72 graph_flux.emplace_back(flux, cepgen::KTFluxFactory::get().describe(flux));
73 }
74
75 ofstream out(output_file);
76 out << "# parton fluxes: " << cepgen::utils::merge(fluxes_names, ";") << "\n";
77 out << "# transverse virtuality: " << kt2 << " GeV^2\n";
78 if (plot_vs_q2)
79 out << "# virtuality: " << q2 << " GeV^2\n";
80 else
81 out << "# diffractive mass: " << mx << " GeV/c^2\n";
82 out << "# fractional momentum loss: " << x_range;
83
84 for (const auto& x : x_range.generate(num_points)) {
85 out << "\n" << x;
86 for (size_t i = 0; i < fluxes.size(); ++i) {
87 auto flux = plot_vs_q2 ? fluxes.at(i)->fluxQ2(x, kt2, q2) : fluxes.at(i)->fluxMX2(x, kt2, mx * mx);
88 flux *= (normalised ? x : 1.);
89 out << "\t" << flux;
90 graph_flux.at(i).addPoint(x, flux);
91 }
92 }
93 out.close();
94 CG_LOG << "Scan written in \"" << output_file << "\".";
95
96 if (!plotter.empty()) {
97 auto plt = cepgen::DrawerFactory::get().build(plotter);
99 if (logx)
101 if (logy)
103 if (draw_grid)
105 if (ratio_plot)
108
109 for (auto& gr : graph_flux) {
110 gr.xAxis().setLabel("$\\xi$");
111 gr.yAxis().setLabel("$"s + (normalised ? "\\xi\\varphi" : "\\varphi") + "(\\xi, " +
112 (plot_vs_q2 ? "Q^{2}" : "M_{X}") + ", k_{T}^{2})$");
113 if (y_range.valid())
114 gr.yAxis().setRange(y_range);
115 coll.emplace_back(&gr);
116 }
117 plt->draw(coll,
118 "comp_partonflux",
119 (plot_vs_q2 ? cepgen::utils::format("$Q^{2}$ = %g GeV$^{2}$", q2)
120 : cepgen::utils::format("$M_{X}$ = %g GeV", mx)) +
121 ", " + cepgen::utils::format("$k_{T}^{2}$ = %g GeV$^{2}$", kt2),
122 dm);
123 }
124
125 return 0;
126}
#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 valid() const
Is there a lower and upper limit?
Definition Limits.cpp:85
std::vector< double > generate(size_t num_bins, bool log_scale=false) const
Generate a collection of values from a number of bins.
Definition Limits.cpp:113
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::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition String.h:61
std::vector< const Drawable * > DrawableColl
A collection of drawable objects.
Definition Drawer.h:34
std::string merge(const std::vector< T > &vec, const std::string &delim)
Merge a collection of a printable type in a single string.
Definition String.cpp:248
void initialise(bool safe_mode)
int main()