cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
cepgenScan.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2016-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
25#include "CepGen/Generator.h"
29#include "CepGen/Physics/PDG.h"
33#include "CepGen/Utils/Drawer.h"
34#include "CepGen/Utils/Graph.h"
35#include "CepGen/Utils/Logger.h"
36#include "CepGen/Utils/String.h"
37
38using namespace std;
39
40int main(int argc, char* argv[]) {
41 string input_config, output_file, scan, plotter, integrator;
42 int npoints;
43 cepgen::Limits range, yrange;
44 vector<double> points;
45 bool draw_grid, logx, logy;
46
47 cepgen::ArgumentsParser parser(argc, argv);
48 parser.addArgument("config,i", "base configuration", &input_config)
49 .addOptionalArgument("scan,s", "type of scan to perform", &scan, "ptmin")
50 .addOptionalArgument("range,r", "minimum value of scan", &range, cepgen::Limits{1., 11.})
51 .addOptionalArgument("num-points,n", "number of points to consider", &npoints, 10)
52 .addOptionalArgument("points", "list of points to consider", &points, vector<double>{})
53 .addOptionalArgument("output,o", "output file", &output_file, "xsect.dat")
54 .addOptionalArgument("logx", "logarithmic x-scale", &logx, false)
55 .addOptionalArgument("logy,l", "logarithmic y-scale", &logy, false)
56 .addOptionalArgument("yrange,y", "y range", &yrange)
57 .addOptionalArgument("draw-grid,g", "draw the x/y grid", &draw_grid, false)
58 .addOptionalArgument("plotter,p", "type of plotter to user", &plotter, "")
59 .addOptionalArgument("integrator,I", "type of integrator used", &integrator, "")
60 .parse();
61
63 gen.parseRunParameters(input_config);
64
65 if (!parser.extra_config().empty()) {
66 auto args_handler = cepgen::CardsHandlerFactory::get().build(".cmd");
67 args_handler->setRunParameters(&gen.runParameters());
68 args_handler->parseCommands(parser.extra_config());
69 gen.setRunParameters(args_handler->runParameters());
70 }
71 if (!integrator.empty())
72 gen.runParameters().integrator() = cepgen::IntegratorFactory::get().describeParameters(integrator).parameters();
73
74 CG_LOG << gen.runParameters();
75
76 ofstream xsect_file(output_file);
77 if (!xsect_file.is_open())
78 throw CG_FATAL("main") << "Output file \"" << output_file << "\" cannot be opened!";
79 xsect_file << "# " << scan << "\txsect (pb)\td(xsect) (pb)\n";
80
81 auto& par = gen.runParameters();
82 //--- ensure nothing is written in the output sequence
83 par.eventExportersSequence().clear();
84
85 if (points.empty())
86 points = range.generate(npoints, logx);
87
89
90 cepgen::utils::Graph1D graph("comp_sigma_gen");
91 auto& kin = par.process().kinematics();
92 string scan_str = scan;
93 for (const auto& value : points) {
94 try {
95 if (scan == "sqrtS") {
96 kin.incomingBeams().setSqrtS(value);
97 scan_str = "$\\sqrt{s}$ (GeV)";
98 } else if (scan == "abseta") {
99 kin.cuts().central.eta_single.min() = -value;
100 kin.cuts().central.eta_single.max() = +value;
101 scan_str = "$|\\eta|$";
102 } else if (scan == "absrap") {
103 kin.cuts().central.rapidity_single.min() = -value;
104 kin.cuts().central.rapidity_single.max() = +value;
105 scan_str = "$|y|$";
106 } else if (cepgen::utils::startsWith(scan, "m:")) {
107 const auto tok = cepgen::utils::split(scan, ':');
108 if (tok.size() > 2)
109 throw CG_FATAL("main") << "Invalid mass scan defined: should follow the \"m:<pdgid int>\" convention!";
110 const cepgen::pdgid_t pdg = abs(stoi(tok.at(1)));
111 cepgen::PDG::get()[pdg].mass = value;
112 scan_str = "$m_{" + cepgen::PDG::get()(pdg).name + "}$ (GeV)";
113 } else {
114 auto modif = cepgen::ParametersList().set<double>(scan, value);
115 kin.setParameters(modif);
116 }
117 CG_LOG << "Scan of \"" << scan << "\". Value = " << value << ".";
118 const auto cross_section = gen.computeXsection();
119 string out_line = cepgen::utils::format("%.2f\t%.8e\t%.8e\n", value, cross_section, cross_section.uncertainty());
120 graph.addPoint(value, cross_section, 0., cross_section.uncertainty());
121 xsect_file << out_line;
122 CG_LOG << out_line;
123 xsect_file.flush();
124 } catch (const cepgen::utils::RunAbortedException&) {
125 CG_LOG << "Run aborted!";
126 break;
127 }
128 }
129
130 if (!plotter.empty()) {
132 if (logx)
134 if (logy)
136 if (draw_grid)
138 graph.xAxis().setLabel(scan_str);
139 graph.yAxis().setLabel("$\\sigma_{gen}$ (pb)");
140 if (yrange.valid())
141 graph.yAxis().setRange(yrange);
142 auto plt = cepgen::DrawerFactory::get().build(plotter);
143 plt->draw(graph, dm);
144 }
145
146 return 0;
147}
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_LOG
Definition Message.h:212
A generic command line arguments parser.
const std::vector< std::string > & extra_config() const
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
void parseRunParameters(const std::string &)
Read a steering card to populate the run parameters block.
Definition Generator.cpp:72
void setRunParameters(std::unique_ptr< RunParameters > &)
Feed the generator with a RunParameters object.
Definition Generator.cpp:88
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition Generator.cpp:76
Value computeXsection()
Compute the cross section and uncertainty, in pb, for the run parameters Compute the cross section fo...
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
ParametersList & set(const std::string &, const T &)
Set a parameter value Set a recast parameter value.
EventExportersSequence & eventExportersSequence()
List of output modules.
ParametersList & integrator()
Integrator specific user-defined parameters.
Object handling an user-driven process abortion.
AxisInfo & setLabel(const std::string &label)
Set the axis title.
Definition Drawable.h:50
AxisInfo & setRange(const Limits &lim)
Set the full axis range.
Definition Drawable.h:67
AxisInfo & yAxis()
Definition Drawable.h:81
AxisInfo & xAxis()
Definition Drawable.h:79
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
std::string format(const std::string &fmt, Args... args)
Format a string using a printf style format descriptor.
Definition String.h:61
bool startsWith(const std::string &str, const std::string &beg)
Check if a string starts with a given token.
Definition String.cpp:365
std::vector< std::string > split(const std::string &str, char delim, bool trim)
Split a string according to a separation character.
Definition String.cpp:233
unsigned long long pdgid_t
Alias for the integer-like particle PDG id.
int main()
static CardsHandlerFactory & get()
Exception raised when the user terminates the process.