cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
cepgenDistributionDrawer.cc
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2013-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
20#include "CepGen/Event/Event.h"
22#include "CepGen/Generator.h"
25#include "CepGen/Utils/Drawer.h"
28#include "CepGen/Utils/String.h"
29
30using namespace std;
31
32int main(int argc, char* argv[]) {
34
35 vector<string> vars;
36 string input_card, plotter;
37 int num_events;
38 bool draw_grid, log;
39
40 cepgen::ArgumentsParser(argc, argv)
41 .addArgument("input,i", "input card", &input_card)
42 .addArgument("vars", "variables to plot", &vars)
43 .addOptionalArgument("num-events,n", "number of events to generate", &num_events, 100)
44 .addOptionalArgument("draw-grid,g", "draw the x/y grid", &draw_grid, false)
45 .addOptionalArgument("log,l", "logarithmic axis", &log, false)
46 .addOptionalArgument("plotter,p", "type of plotter to user", &plotter, "")
47 .parse();
48
49 mg.parseRunParameters(input_card);
51
52 // book all histograms
53 map<string, unique_ptr<cepgen::utils::Hist1D> > h_var_hist;
54 for (const auto& var : vars) {
55 cepgen::Limits lim{0., 250.};
56 if (var == "eta")
57 lim = {-3., 3.};
58 const auto parsed_var = cepgen::utils::replaceAll(var, ":", ",");
59 h_var_hist[parsed_var].reset(new cepgen::utils::Hist1D(100, lim, cepgen::utils::sanitise(var)));
60 h_var_hist[parsed_var]->xAxis().setLabel(parsed_var);
61 h_var_hist[parsed_var]->yAxis().setLabel("d$\\sigma$/d" + parsed_var);
62 }
63 CG_DEBUG("main") << "Variables to be plotted: " << vars << ".";
64
65 CG_LOG << "Process name: " << mg.runParameters().processName() << ".";
66
68
69 // generate the events and feed to the histogram(s)
70 mg.generate(num_events, [&browser, &h_var_hist](const cepgen::Event& ev, unsigned long) {
71 for (auto& var : h_var_hist)
72 var.second->fill(browser.get(ev, var.first));
73 });
74
75 // normalise to cross section
76 for (auto& var : h_var_hist)
77 var.second->normalise(mg.crossSection() / num_events);
78
79 // if a plotter is specified, draw histograms
80 if (!plotter.empty()) {
81 auto plt = cepgen::DrawerFactory::get().build(plotter);
83 if (log)
85 if (draw_grid)
87
88 for (const auto& var : h_var_hist)
89 plt->draw(*var.second, dm);
90 }
91
92 return 0;
93}
#define CG_LOG
Definition Message.h:212
#define CG_DEBUG(mod)
Definition Message.h:220
A generic command line arguments parser.
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.
Container for the information on the in- and outgoing particles' kinematics.
Definition Event.h:28
Core generator object allowing for process definition, cross section computation, and event generatio...
Definition Generator.h:48
void generate(size_t num_events, const std::function< void(const Event &, size_t)> &)
Generate events.
void parseRunParameters(const std::string &)
Read a steering card to populate the run parameters block.
Definition Generator.cpp:72
double crossSection() const
Last cross section computed by the generator.
Definition Generator.h:69
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition Generator.cpp:76
Validity interval for a variable.
Definition Limits.h:28
void clearEventExportersSequence()
Remove all output modules from sequence.
std::string processName() const
Name of the process considered.
A user-friendly browser for the Event content.
double get(const Event &ev, const std::string &var) const
Get/compute a variable value.
1D histogram container
Definition Histogram.h:72
std::string sanitise(const std::string &str)
Replace all unsafe characters to build a computer-readable (and filename-safe) string.
Definition String.cpp:105
size_t replaceAll(std::string &str, const std::string &from, const std::string &to)
Replace all occurrences of a text by another.
Definition String.cpp:118
int main()