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
19
#include "
CepGen/Core/RunParameters.h
"
20
#include "
CepGen/EventFilter/EventExporter.h
"
21
#include "
CepGen/Generator.h
"
22
#include "
CepGen/Modules/EventExporterFactory.h
"
23
#include "
CepGen/Modules/ProcessFactory.h
"
24
#include "
CepGen/Process/Process.h
"
25
#include "
CepGen/Utils/ArgumentsParser.h
"
26
#include "
CepGen/Utils/Filesystem.h
"
27
#include "
CepGen/Utils/Message.h
"
28
#include "
CepGen/Utils/Test.h
"
29
#include "
CepGenAddOns/ROOTWrapper/ROOTTreeInfo.h
"
30
31
using namespace
std;
32
33
int
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
46
cepgen::Generator
gen;
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
80
CG_TEST_SUMMARY
;
81
}
ArgumentsParser.h
EventExporterFactory.h
EventExporter.h
Filesystem.h
Generator.h
Message.h
CG_LOG
#define CG_LOG
Definition
Message.h:212
ProcessFactory.h
Process.h
ROOTTreeInfo.h
RunParameters.h
Test.h
CG_TEST_EQUIV
#define CG_TEST_EQUIV(var1, var2, name)
Definition
Test.h:61
CG_TEST_SUMMARY
#define CG_TEST_SUMMARY
Definition
Test.h:127
CG_TEST
#define CG_TEST(test_cond, name)
Definition
Test.h:30
ROOT::CepGenEvent
All useful information about a generated event.
Definition
ROOTTreeInfo.h:60
ROOT::CepGenEvent::tree
TTree * tree()
Retrieve the ROOT tree.
Definition
ROOTTreeInfo.h:91
ROOT::CepGenEvent::attach
void attach()
Attach the event tree reader to a tree.
Definition
ROOTTreeInfo.cpp:135
ROOT::CepGenRun
All useful information about a generation run.
Definition
ROOTTreeInfo.h:29
ROOT::CepGenRun::xsect
double xsect
Process cross section, in pb.
Definition
ROOTTreeInfo.h:37
ROOT::CepGenRun::errxsect
double errxsect
Uncertainty on process cross section, in pb.
Definition
ROOTTreeInfo.h:38
ROOT::CepGenRun::attach
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.
Definition
ROOTTreeInfo.cpp:64
cepgen::ArgumentsParser
A generic command line arguments parser.
Definition
ArgumentsParser.h:31
cepgen::ArgumentsParser::parse
ArgumentsParser & parse()
Associate command-line arguments to parameters.
Definition
ArgumentsParser.cpp:106
cepgen::ArgumentsParser::addOptionalArgument
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Definition
ArgumentsParser.h:46
cepgen::Generator
Core generator object allowing for process definition, cross section computation, and event generatio...
Definition
Generator.h:48
cepgen::Generator::generate
void generate(size_t num_events, const std::function< void(const Event &, size_t)> &)
Generate events.
Definition
Generator.cpp:235
cepgen::Generator::crossSectionError
double crossSectionError() const
Last error on the cross section computed.
Definition
Generator.h:70
cepgen::Generator::crossSection
double crossSection() const
Last cross section computed by the generator.
Definition
Generator.h:69
cepgen::Generator::runParameters
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition
Generator.cpp:76
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::RunParameters::setProcess
void setProcess(std::unique_ptr< proc::Process >)
Set a process configuration.
Definition
RunParameters.cpp:117
main
int main()
Definition
pythia6_decay.cc:9
CepGenAddOns
ROOTWrapper
test
root_ttree_process.cc
Generated on Mon Jul 29 2024 for CepGen by
1.9.7