cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
cepgenPlotFormFactors.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2013-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
22#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;
32
33int main(int argc, char* argv[]) {
34 int num_points;
35 string output_file, plotter;
36 bool logx, logy, draw_grid, ratio_plot;
37 cepgen::Limits q2range, yrange;
38 vector<string> modules;
39
40 cepgen::ArgumentsParser(argc, argv)
41 .addOptionalArgument("modules,m", "types of form factors", &modules, cepgen::FormFactorsFactory::get().modules())
42 .addOptionalArgument("q2range,q", "parton virtuality range (GeV^2)", &q2range, cepgen::Limits{1., 2.5})
43 .addOptionalArgument("yrange,y", "y range", &yrange)
44 .addOptionalArgument("npoints,n", "number of x-points to scan", &num_points, 500)
45 .addOptionalArgument("output,o", "output file name", &output_file, "formfacs.scan.output.txt")
46 .addOptionalArgument("plotter,p", "type of plotter to user", &plotter, "")
47 .addOptionalArgument("logx", "logarithmic x-scale", &logx, false)
48 .addOptionalArgument("logy,l", "logarithmic y-scale", &logy, false)
49 .addOptionalArgument("draw-grid,g", "draw the x/y grid", &draw_grid, false)
50 .addOptionalArgument("ratio,r", "draw the ratio plot", &ratio_plot, false)
51 .parse();
52
54
55 ofstream out(output_file);
56 out << "# form factors: " << cepgen::utils::merge(modules, ",");
57
58 out << "\n"
59 << "# q2 range: " << q2range << " GeV^2\n";
60
61 vector<unique_ptr<cepgen::formfac::Parameterisation> > form_factors;
62 vector<cepgen::utils::Graph1D> g_form_factors_fe, g_form_factors_fm;
63 for (const auto& ff_type : modules) {
64 form_factors.emplace_back(cepgen::FormFactorsFactory::get().build(ff_type));
65 const auto ff_desc = cepgen::FormFactorsFactory::get().describe(ff_type);
66 g_form_factors_fe.emplace_back("fe_" + ff_type, ff_desc);
67 g_form_factors_fm.emplace_back("fm_" + ff_type, ff_desc);
68 }
69 for (const auto& q2 : q2range.generate(num_points, logx)) {
70 out << q2 << "\t";
71 size_t j = 0;
72 for (const auto& ff : form_factors) {
73 const auto form_factor = (*ff)(q2);
74 out << "\t" << form_factor.FE << "\t" << form_factor.FM;
75 g_form_factors_fe.at(j).addPoint(q2, form_factor.FE);
76 g_form_factors_fm.at(j).addPoint(q2, form_factor.FM);
77 ++j;
78 }
79 out << "\n";
80 }
81 out.close();
82 CG_LOG << "Scan written in \"" << output_file << "\".";
83
84 if (!plotter.empty()) {
85 auto plt = cepgen::DrawerFactory::get().build(plotter);
87 if (logx)
89 if (logy)
91 if (draw_grid)
93 if (ratio_plot)
95
96 for (auto& canv : map<pair<string, string>, vector<cepgen::utils::Graph1D> >{
97 {{"fe", "$F_{E}$"}, g_form_factors_fe}, {{"fm", "$F_{M}$"}, g_form_factors_fm}}) {
99 for (auto& gr : canv.second) {
100 gr.xAxis().setLabel("$Q^{2}$ (GeV$^{2}$)");
101 gr.yAxis().setLabel(canv.first.second);
102 if (q2range.valid())
103 gr.xAxis().setRange(q2range);
104 if (yrange.valid())
105 gr.yAxis().setRange(yrange);
106 coll.emplace_back(&gr);
107 }
108 plt->draw(coll, "comp_" + canv.first.first, "", dm);
109 }
110 }
111
112 return 0;
113}
#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
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()