cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
root_ttree_process.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
21#include "CepGen/Generator.h"
28#include "CepGen/Utils/Test.h"
30
31using namespace std;
32
33int main(int argc, char* argv[]) {
34 bool keep_file;
35 string proc_name, tmp_filename;
36 int num_gen;
37 cepgen::ArgumentsParser(argc, argv)
38 .addOptionalArgument("keep-file,k", "keep the output TTree", &keep_file, false)
39 .addOptionalArgument("process,p", "process to generate", &proc_name, "lpair")
40 .addOptionalArgument("filename,f", "temporary filename", &tmp_filename, "/tmp/cepgen_test.root")
41 .addOptionalArgument("num-gen,n", "number of events to generate", &num_gen, 10)
42 .parse();
43
44 double cross_sec, cross_sec_unc;
45 { // generation + tree building part
47 auto& pars = gen.runParameters();
48 pars.setProcess(cepgen::ProcessFactory::get().build(proc_name));
49 pars.process().kinematics().setParameters(cepgen::ParametersList()
50 .set<vector<int> >("pdgIds", {2212, 2212})
51 .set<double>("sqrtS", 13.6e3)
52 .set<int>("mode", 1)
53 .set<double>("ptmin", 25.));
54 pars.addEventExporter(cepgen::EventExporterFactory::get().build(
55 "root_tree", cepgen::ParametersList().set<string>("filename", tmp_filename)));
56 CG_LOG << &pars;
57 gen.generate(num_gen);
58 cross_sec = gen.crossSection();
59 cross_sec_unc = gen.crossSectionError();
60 }
61
62 { // tree analysis part
63 auto* file = TFile::Open(tmp_filename.c_str());
64 ROOT::CepGenRun run_info;
65 run_info.attach(file);
66
67 CG_TEST_EQUIV(run_info.xsect, cross_sec, "cross section from run tree");
68 CG_TEST_EQUIV(run_info.errxsect, cross_sec_unc, "cross section uncertainty from run tree");
69
70 ROOT::CepGenEvent evt_info;
71 evt_info.attach(file);
72 CG_TEST(evt_info.tree(), "events tree present");
73 if (evt_info.tree())
74 CG_TEST(evt_info.tree()->GetEntriesFast() == num_gen, "number of events generated");
75 }
76
77 if (!keep_file) // tree removal part
78 CG_TEST(fs::remove(tmp_filename), "removal the temporary file \"" + tmp_filename + "\".");
79
81}
#define CG_LOG
Definition Message.h:212
#define CG_TEST_EQUIV(var1, var2, name)
Definition Test.h:61
#define CG_TEST_SUMMARY
Definition Test.h:127
#define CG_TEST(test_cond, name)
Definition Test.h:30
All useful information about a generated event.
TTree * tree()
Retrieve the ROOT tree.
void attach()
Attach the event tree reader to a tree.
All useful information about a generation run.
double xsect
Process cross section, in pb.
double errxsect
Uncertainty on process cross section, in pb.
void attach(TFile *file, const std::string &run_tree=TREE_NAME)
Attach the run tree reader to a given tree Attach the run tree reader to a given file.
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.
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.
double crossSectionError() const
Last error on the cross section computed.
Definition Generator.h:70
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
void setProcess(std::unique_ptr< proc::Process >)
Set a process configuration.
int main()