cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
cepgen.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
19
#include "
CepGen/Cards/Handler.h
"
20
#include "
CepGen/Core/Exception.h
"
21
#include "
CepGen/Core/RunParameters.h
"
22
#include "
CepGen/EventFilter/EventExporter.h
"
23
#include "
CepGen/Generator.h
"
24
#include "
CepGen/Modules/CardsHandlerFactory.h
"
25
#include "
CepGen/Modules/DocumentationGeneratorFactory.h
"
26
#include "
CepGen/Modules/EventExporterFactory.h
"
27
#include "
CepGen/Utils/AbortHandler.h
"
28
#include "
CepGen/Utils/ArgumentsParser.h
"
29
#include "
CepGen/Utils/DocumentationGenerator.h
"
30
31
using namespace
std;
32
38
int
main
(
int
argc,
char
* argv[]) {
39
string
input_card;
40
int
num_events;
41
bool
list_mods, safe_mode;
42
vector<string> addons, outputs;
43
44
cepgen::ArgumentsParser
parser(argc, argv);
45
parser.
addOptionalArgument
(
"config,i"
,
"path to the configuration file"
, &input_card)
46
.
addOptionalArgument
(
"num-events,n"
,
"number of events to generate"
, &num_events, -1)
47
.
addOptionalArgument
(
"list-modules,l"
,
"list all runtime modules"
, &list_mods,
false
)
48
.
addOptionalArgument
(
"add-ons,a"
,
"external runtime plugin"
, &addons)
49
.
addOptionalArgument
(
"output,o"
,
"additional output module(s)"
, &outputs)
50
.
addOptionalArgument
(
"safe-mode,s"
,
"safe mode"
, &safe_mode,
false
)
51
.
parse
();
52
53
cepgen::Generator
gen(safe_mode);
// first start by defining the generator object
54
for
(
const
auto
& lib : addons)
// loading of additional plugins into the runtime environment manager
55
try
{
56
cepgen::loadLibrary
(lib);
57
}
catch
(
const
cepgen::Exception
& e) {
58
e.
dump
();
59
}
60
61
if
(list_mods) {
// modules listing is requested ; dump and exit
62
auto
doc_dump =
63
cepgen::DocumentationGeneratorFactory::get().build(
"text"
,
cepgen::ParametersList
().set(
"light"
,
true
));
64
CG_LOG
<< doc_dump->describe();
65
return
0;
66
}
67
68
if
(input_card.empty() && parser.
extra_config
().empty()) {
// no steering card nor additional flags found
69
CG_WARNING
(
"main"
) <<
"Neither input card nor configuration word provided!\n\n "
<< parser.
help_message
();
70
return
0;
71
}
72
if
(!input_card.empty())
73
gen.
parseRunParameters
(input_card);
// parse the steering card
74
if
(!parser.
extra_config
().empty()) {
// parse any additional flags
75
auto
args_handler =
cepgen::CardsHandlerFactory::get
().build(
".cmd"
);
76
args_handler->setRunParameters(&gen.
runParameters
());
77
args_handler->parseCommands(parser.
extra_config
());
78
gen.
setRunParameters
(args_handler->runParameters());
79
}
80
81
cepgen::utils::AbortHandler
();
// allow C-c to be triggered during a run
82
83
try
{
84
auto
& params = gen.
runParameters
();
85
if
(num_events >= 0)
// user specified a number of events to generate
86
params.
generation
().
setMaxGen
(num_events);
87
88
if
(params.generation().enabled() && !outputs.empty())
89
for
(
const
auto
&
output
: outputs)
90
gen.
runParameters
().
addEventExporter
(cepgen::EventExporterFactory::get().build(
output
));
91
92
CG_LOG
<< gen.
runParameters
();
// user-friendly printout of all run parameters
93
94
gen.
computeXsection
();
//--- let there be a cross-section...
95
96
if
(params.generation().enabled())
97
// events generation happens here
98
// (one may use a callback function)
99
gen.
generate
(0);
100
}
catch
(
const
cepgen::utils::RunAbortedException
&) {
101
CG_DEBUG
(
"main"
) <<
"Run aborted!"
;
102
}
catch
(
const
cepgen::Exception
& e) {
103
CG_DEBUG
(
"main"
) <<
"CepGen exception encountered: "
<< e.
what
();
104
e.
dump
();
105
}
catch
(
const
exception& e) {
106
CG_FATAL
(
"main"
) <<
"Other exception caught!\n\t"
<< e.
what
();
107
}
108
109
return
0;
110
}
AbortHandler.h
ArgumentsParser.h
CardsHandlerFactory.h
DocumentationGeneratorFactory.h
DocumentationGenerator.h
EventExporterFactory.h
EventExporter.h
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
Generator.h
Handler.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
CG_LOG
#define CG_LOG
Definition
Message.h:212
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
RunParameters.h
cepgen::ArgumentsParser
A generic command line arguments parser.
Definition
ArgumentsParser.h:31
cepgen::ArgumentsParser::extra_config
const std::vector< std::string > & extra_config() const
Definition
ArgumentsParser.h:59
cepgen::ArgumentsParser::parse
ArgumentsParser & parse()
Associate command-line arguments to parameters.
Definition
ArgumentsParser.cpp:106
cepgen::ArgumentsParser::help_message
std::string help_message() const
Usage message.
Definition
ArgumentsParser.cpp:170
cepgen::ArgumentsParser::addOptionalArgument
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Definition
ArgumentsParser.h:46
cepgen::Exception
Definition
Exception.h:25
cepgen::Exception::what
const char * what() const noexcept override
Definition
Exception.cpp:36
cepgen::Exception::dump
void dump(std::ostream *os=nullptr) const noexcept override
Human-readable dump of the exception.
Definition
Exception.cpp:41
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::parseRunParameters
void parseRunParameters(const std::string &)
Read a steering card to populate the run parameters block.
Definition
Generator.cpp:72
cepgen::Generator::setRunParameters
void setRunParameters(std::unique_ptr< RunParameters > &)
Feed the generator with a RunParameters object.
Definition
Generator.cpp:88
cepgen::Generator::runParameters
const RunParameters & runParameters() const
Pointer to the parameters block.
Definition
Generator.cpp:76
cepgen::Generator::computeXsection
Value computeXsection()
Compute the cross section and uncertainty, in pb, for the run parameters Compute the cross section fo...
Definition
Generator.cpp:110
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::RunParameters::Generation::setMaxGen
void setMaxGen(size_t max_gen)
Set the maximal number of events to generate.
Definition
RunParameters.h:90
cepgen::RunParameters::addEventExporter
void addEventExporter(std::unique_ptr< EventExporter >)
Set a new output module definition.
Definition
RunParameters.cpp:145
cepgen::RunParameters::generation
Generation & generation()
Event generation parameters.
Definition
RunParameters.h:108
cepgen::utils::AbortHandler
Object handling an user-driven process abortion.
Definition
AbortHandler.h:39
cepgen::loadLibrary
bool loadLibrary(const std::string &path, bool match)
Import a shared library in RTE Launch the initialisation procedure.
Definition
GlobalFunctions.cpp:42
output
Definition
output.py:1
main
int main()
Definition
pythia6_decay.cc:9
cepgen::CardsHandlerFactory::get
static CardsHandlerFactory & get()
Definition
CardsHandlerFactory.cpp:25
cepgen::utils::RunAbortedException
Exception raised when the user terminates the process.
Definition
AbortHandler.h:31
src
cepgen.cc
Generated on Mon Jul 29 2024 for CepGen by
1.9.7