cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
cepgenPlotSigmaRatios.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2022-2024 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, w2;
38 string output_file, plotter;
39 vector<string> sigrat_types;
40 cepgen::Limits x_range;
41 bool logx, logy, draw_grid, ratio_plot;
42
43 cepgen::ArgumentsParser(argc, argv)
44 .addOptionalArgument("sr,s",
45 "longitud./transv. cross section ratio modelling",
46 &sigrat_types,
47 cepgen::SigmaRatiosFactory::get().modules())
48 .addOptionalArgument("q2,q", "parton virtuality (GeV^2)", &q2, -1.)
49 .addOptionalArgument("w2,w", "scattered particle squared mass (GeV^2/c^4)", &w2, -1.)
50 .addOptionalArgument("var,t", "variable to study (0=xBj, 1=w)", &var, 0)
51 .addOptionalArgument("xrange,x", "Bjorken x range", &x_range, cepgen::Limits{1.e-7, 1.})
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 if (q2 < 0. && w2 < 0.)
62 throw CG_FATAL("main") << "Either a Q^2 or a w^2 must be provided!";
63
65
66 string var_name, var_unit;
67 switch (var) {
68 case 0:
69 var_name = "x_{Bj}";
70 break;
71 case 1:
72 var_name = "w";
73 var_unit = "GeV";
74 break;
75 case 2:
76 var_name = "w^{2}";
77 var_unit = "GeV$^{2}$";
78 break;
79 default:
80 throw CG_FATAL("main") << "Unsupported variable to be plotted!";
81 }
82
83 string fixed_var;
84 if (q2 > 0.)
85 fixed_var = "$Q^{2}$";
86 else if (w2 > 0.)
87 fixed_var = "$w^{2}$";
88
89 ofstream out(output_file);
90 out << "# sigma ratios: " << cepgen::utils::repr(sigrat_types) << "\n"
91 << "# x in [" << x_range << "]\n";
92
93 const float mp = cepgen::PDG::get().mass(2212), mp2 = mp * mp;
94
95 vector<unique_ptr<cepgen::sigrat::Parameterisation> > sigrats;
96 vector<cepgen::utils::Graph1D> g_sigrats;
97 for (const auto& sr_type : sigrat_types) {
98 auto sr = cepgen::SigmaRatiosFactory::get().build(sr_type);
99 const auto sr_name = cepgen::SigmaRatiosFactory::get().describe(sr_type);
100 g_sigrats.emplace_back(sr_type, sr_name);
101 sigrats.emplace_back(move(sr));
102 }
103 for (const auto& x : x_range.generate(num_points, logx)) {
104 out << x << "\t";
105 size_t j = 0;
106 for (const auto& sr : sigrats) {
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 double err;
123 const auto sigrat = (*sr)(xbj, q2, err);
124 out << "\t" << sigrat;
125 g_sigrats.at(j).addPoint(x, sigrat);
126 ++j;
127 }
128 out << "\n";
129 }
130 CG_LOG << "Scan written in \"" << output_file << "\".";
131 out.close();
132
133 if (!plotter.empty()) {
134 auto plt = cepgen::DrawerFactory::get().build(plotter);
136 if (logx)
138 if (logy)
140 if (draw_grid)
142 if (ratio_plot)
144
146 for (auto& gr : g_sigrats) {
147 gr.xAxis().setLabel("$" + var_name + "$" + (!var_unit.empty() ? " (" + var_unit + ")" : ""));
148 gr.yAxis().setLabel("$\\sigma_{L}/\\sigma_{T} = R(" + var_name + ", Q^{2})$");
149 mg.emplace_back(&gr);
150 }
151 plt->draw(mg, "comp_sigrat", fixed_var + cepgen::utils::format(" = %g GeV$^{2}$", q2 > 0. ? q2 : w2), dm);
152 }
153
154 return 0;
155}
#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
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::string repr(const std::vector< T > &vec, const std::function< std::string(const T &)> &printer, const std::string &sep=",")
Helper to print a vector.
Definition String.h:156
std::vector< const Drawable * > DrawableColl
A collection of drawable objects.
Definition Drawer.h:34
void initialise(bool safe_mode)
int main()