cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
lhe_writer.cc
Go to the documentation of this file.
1
#include "
CepGen/Event/Event.h
"
2
#include "
CepGen/EventFilter/EventExporter.h
"
3
#include "
CepGen/Generator.h
"
4
#include "
CepGen/Modules/EventExporterFactory.h
"
5
#include "
CepGen/Modules/RandomGeneratorFactory.h
"
6
#include "
CepGen/Utils/ArgumentsParser.h
"
7
#include "
CepGen/Utils/Filesystem.h
"
8
#include "
CepGen/Utils/RandomGenerator.h
"
9
#include "
CepGen/Utils/Test.h
"
10
11
using namespace
std;
12
13
int
main
(
int
argc,
char
* argv[]) {
14
string
output_file;
15
16
cepgen::ArgumentsParser
(argc, argv)
17
.
addOptionalArgument
(
"output,o"
,
"path to the output LHEF file"
, &output_file,
"test.lhe"
)
18
.
parse
();
19
20
cepgen::initialise
();
21
22
// initialise the LHEF writer
23
auto
lhef_mod = cepgen::EventExporterFactory::get().build(
24
"lhef"
,
cepgen::ParametersList
().set<std::string>(
"filename"
, output_file));
25
26
// randomise the number of events to be written in the output file
27
auto
rng = cepgen::RandomGeneratorFactory::get().build(
"stl"
);
28
const
size_t
num_events = rng->uniformInt(1, 10);
29
30
// generate one simple event
31
auto
evt =
cepgen::Event::minimal
();
32
{
// write a few events
33
for
(
size_t
i = 0; i < num_events; ++i)
34
(*lhef_mod) << evt;
35
}
36
37
// start of tests on output file
38
CG_TEST_EQUAL
(
cepgen::utils::fileExists
(output_file),
true
,
"Output file exists"
);
39
40
size_t
num_stored_events = 0, num_events_invalid_multiplicity_hdr = 0, num_events_invalid_multiplicity_cnt = 0;
41
42
bool
in_event =
false
;
43
size_t
num_lines_in_event = 999, num_particles_in_event_hdr = 999;
44
for
(
const
auto
& buf :
cepgen::utils::split
(
cepgen::utils::readFile
(output_file),
'\n'
)) {
45
if
(buf ==
"<event>"
) {
46
in_event =
true
;
47
num_lines_in_event = 0;
48
}
else
if
(in_event && buf ==
"</event>"
) {
49
if
(num_lines_in_event - 2 != num_particles_in_event_hdr)
// skip incoming beam particles
50
++num_events_invalid_multiplicity_cnt;
51
num_stored_events++;
52
in_event =
false
;
53
}
54
if
(num_lines_in_event == 1) {
55
num_particles_in_event_hdr = stoul(
cepgen::utils::split
(
cepgen::utils::trim
(buf),
' '
,
true
).at(0));
56
if
(num_particles_in_event_hdr - 2 == evt.size())
// remove </event> and header line
57
++num_events_invalid_multiplicity_hdr;
58
}
59
++num_lines_in_event;
60
}
61
62
CG_TEST_EQUAL
(num_stored_events, num_events,
"Number of <event> + </event> tags in LHEF"
);
63
CG_TEST_EQUAL
(num_events_invalid_multiplicity_hdr,
64
0,
65
"No events with invalid header-registered particles multiplicity in LHEF"
);
66
CG_TEST_EQUAL
(num_events_invalid_multiplicity_cnt, 0,
"No events with invalid particles multiplicity in LHEF"
);
67
68
CG_TEST_SUMMARY
;
69
}
ArgumentsParser.h
EventExporterFactory.h
EventExporter.h
Event.h
Filesystem.h
Generator.h
RandomGeneratorFactory.h
RandomGenerator.h
Test.h
CG_TEST_SUMMARY
#define CG_TEST_SUMMARY
Definition
Test.h:127
CG_TEST_EQUAL
#define CG_TEST_EQUAL(var1, var2, name)
Definition
Test.h:45
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::Event::minimal
static Event minimal(size_t num_out_particles=1)
Build a trivial event with the minimal information.
Definition
Event.cpp:52
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::utils::trim
std::string trim(const std::string &str)
Trim leading and trailing spaces.
Definition
String.h:174
cepgen::utils::readFile
std::string readFile(const std::string &filename)
Read the content of a file into a string buffer.
Definition
Filesystem.cpp:31
cepgen::utils::fileExists
bool fileExists(const std::string &path)
Check if the file exists.
Definition
Filesystem.cpp:27
cepgen::utils::split
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
cepgen::initialise
void initialise(bool safe_mode)
Definition
GlobalFunctions.cpp:91
main
int main()
Definition
pythia6_decay.cc:9
CepGenAddOns
Pythia8Wrapper
test
lhe_writer.cc
Generated on Mon Jul 29 2024 for CepGen by
1.9.7