cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
cepgenPlotStrFunctions.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 <fstream>
20
22#include "CepGen/Generator.h"
25#include "CepGen/Physics/PDG.h"
29#include "CepGen/Utils/Drawer.h"
30#include "CepGen/Utils/Graph.h"
31#include "CepGen/Utils/String.h"
32
33using namespace std;
34
35int main(int argc, char* argv[]) {
36 int var, num_points;
37 double q2;
38 string output_file, plotter;
39 vector<string> strfun_types;
40 bool logx, logy, draw_grid, ratio_plot;
41 cepgen::Limits xrange, yrange;
42
44
45 cepgen::ArgumentsParser(argc, argv)
47 "sf,s", "structure functions modelling", &strfun_types, cepgen::StructureFunctionsFactory::get().modules())
48 .addOptionalArgument("q2,q", "parton virtuality (GeV^2)", &q2, 10.)
49 .addOptionalArgument("var,t", "variable to study (0=xBj, 1=w)", &var, 0)
50 .addOptionalArgument("xrange,x", "Bjorken x range", &xrange, cepgen::Limits{1.e-7, 1.})
51 .addOptionalArgument("yrange", "plotting range for y", &yrange, cepgen::Limits())
52 .addOptionalArgument("npoints,n", "number of x-points to scan", &num_points, 500)
53 .addOptionalArgument("output,o", "output file name", &output_file, "strfuns.scan.output.txt")
54 .addOptionalArgument("plotter,p", "type of plotter to user", &plotter, "")
55 .addOptionalArgument("logx", "logarithmic x-axis", &logx, false)
56 .addOptionalArgument("logy,l", "logarithmic y-axis", &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 .parse();
60
61 string var_name, var_unit;
62 switch (var) {
63 case 0:
64 var_name = "$x_{Bj}$";
65 break;
66 case 1:
67 var_name = "w";
68 var_unit = "GeV";
69 break;
70 case 2:
71 var_name = "w$^{2}$";
72 var_unit = "GeV$^{2}$";
73 break;
74 default:
75 throw CG_FATAL("main") << "Unsupported variable to be plotted!";
76 }
77
78 ofstream out(output_file);
79 out << "# structure functions: ";
80 string sep;
81 for (const auto& sf_type : strfun_types)
82 out << sep << sf_type, sep = ", ";
83 out << "\n"
84 << "# x in [" << xrange << "]\n";
85
86 const float mp = cepgen::PDG::get().mass(2212), mp2 = mp * mp;
87
88 vector<unique_ptr<cepgen::strfun::Parameterisation> > strfuns;
89 vector<cepgen::utils::Graph1D> g_strfuns_f2, g_strfuns_fl, g_strfuns_fe, g_strfuns_fm, g_strfuns_w1, g_strfuns_w2;
90 for (const auto& sf_type : strfun_types) {
91 auto sf = cepgen::StructureFunctionsFactory::get().build(sf_type);
92 const auto sf_name = cepgen::StructureFunctionsFactory::get().describe(sf_type);
93 g_strfuns_f2.emplace_back("f2_" + sf_type, sf_name);
94 g_strfuns_fl.emplace_back("fl_" + sf_type, sf_name);
95 g_strfuns_fe.emplace_back("fe_" + sf_type, sf_name);
96 g_strfuns_fm.emplace_back("fm_" + sf_type, sf_name);
97 g_strfuns_w1.emplace_back("w1_" + sf_type, sf_name);
98 g_strfuns_w2.emplace_back("w2_" + sf_type, sf_name);
99 strfuns.emplace_back(move(sf));
100 }
101 const auto xvals = xrange.generate(num_points, logx);
102 for (int i = 0; i < num_points; ++i) {
103 const auto& x = xvals.at(i);
104 out << x << "\t";
105 size_t j = 0;
106 for (auto& sf : strfuns) {
107 double xbj;
108 switch (var) {
109 case 0:
110 xbj = x;
111 break;
112 case 1:
113 xbj = cepgen::utils::xBj(q2, mp2, x * x);
114 break;
115 case 2:
116 xbj = cepgen::utils::xBj(q2, mp2, x);
117 break;
118 default:
119 xbj = 0.;
120 break;
121 }
122 out << "\t" << sf->F2(xbj, q2) << "\t" << sf->FL(xbj, q2);
123 g_strfuns_f2.at(j).addPoint(x, sf->F2(xbj, q2));
124 g_strfuns_fl.at(j).addPoint(x, sf->FL(xbj, q2));
125 g_strfuns_fe.at(j).addPoint(x, sf->FE(xbj, q2));
126 g_strfuns_fm.at(j).addPoint(x, sf->FM(xbj, q2));
127 g_strfuns_w1.at(j).addPoint(x, sf->W1(xbj, q2));
128 g_strfuns_w2.at(j).addPoint(x, sf->W2(xbj, q2));
129 ++j;
130 }
131 out << "\n";
132 }
133 CG_LOG << "Scan written in \"" << output_file << "\".";
134 out.close();
135
136 if (!plotter.empty()) {
137 auto plt = cepgen::DrawerFactory::get().build(plotter);
139 if (logx)
141 if (logy)
143 if (draw_grid)
145 if (ratio_plot)
147
148 for (auto& canv : map<pair<string, string>, vector<cepgen::utils::Graph1D> >{{{"f2", "$F_{2}$"}, g_strfuns_f2},
149 {{"fl", "$F_{L}$"}, g_strfuns_fl},
150 {{"fe", "$F_{E}$"}, g_strfuns_fe},
151 {{"fm", "$F_{M}$"}, g_strfuns_fm},
152 {{"w1", "$W_{1}$"}, g_strfuns_w1},
153 {{"w2", "$W_{2}$"}, g_strfuns_w2}}) {
155 for (auto& p : canv.second) {
156 p.xAxis().setLabel(var_name + (!var_unit.empty() ? " (" + var_unit + ")" : ""));
157 p.yAxis().setLabel(canv.first.second + (!var_name.empty() ? "(" + var_name + ", $Q^{2}$)" : ""));
158 if (yrange.valid())
159 p.yAxis().setRange(yrange);
160 plots.emplace_back(&p);
161 }
162 plt->draw(plots, "sfcomp_" + canv.first.first, cepgen::utils::format("$Q^{2}$ = %g GeV$^{2}$", q2), dm);
163 }
164 }
165
166 return 0;
167}
#define CG_FATAL(mod)
Definition Exception.h:61
#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 mass(spdgid_t) const
Particle mass (in GeV)
Definition PDG.cpp:90
static PDG & get()
Retrieve a unique instance of this particles info collection.
Definition PDG.cpp:41
double xBj(double q2, double mp2, double mx2)
Compute Bjorken x from virtuality/diffractive mass.
Definition Utils.cpp:41
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
void initialise(bool safe_mode)
int main()