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.
3#include "CepGen/Generator.h"
9#include "CepGen/Utils/Test.h"
10
11using namespace std;
12
13int 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
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
69}
#define CG_TEST_SUMMARY
Definition Test.h:127
#define CG_TEST_EQUAL(var1, var2, name)
Definition Test.h:45
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.
static Event minimal(size_t num_out_particles=1)
Build a trivial event with the minimal information.
Definition Event.cpp:52
std::string trim(const std::string &str)
Trim leading and trailing spaces.
Definition String.h:174
std::string readFile(const std::string &filename)
Read the content of a file into a string buffer.
bool fileExists(const std::string &path)
Check if the file exists.
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
void initialise(bool safe_mode)
int main()