cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
GeneratorWorker.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2020-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/Exception.h
"
20
#include "
CepGen/Core/GeneratorWorker.h
"
21
#include "
CepGen/Core/RunParameters.h
"
22
#include "
CepGen/Event/Event.h
"
23
#include "
CepGen/EventFilter/EventExporter.h
"
24
#include "
CepGen/Integration/Integrator.h
"
25
#include "
CepGen/Integration/ProcessIntegrand.h
"
26
#include "
CepGen/Process/Process.h
"
27
#include "
CepGen/Utils/String.h
"
28
#include "
CepGen/Utils/TimeKeeper.h
"
29
30
namespace
cepgen
{
31
GeneratorWorker::GeneratorWorker
(
const
ParametersList
& params) :
SteeredObject
(params) {}
32
33
void
GeneratorWorker::setRunParameters
(
const
RunParameters
* params) {
34
params_
= params;
35
integrand_
.reset(
new
ProcessIntegrand
(params));
36
CG_DEBUG
(
"GeneratorWorker"
) <<
"New generator worker initialised for integration/event generation.\n\t"
37
<<
"Run parameters at "
<< (
void
*)
params_
<<
"."
;
38
}
39
40
GeneratorWorker::~GeneratorWorker
() {
41
CG_DEBUG
(
"GeneratorWorker"
) <<
"Generator worker destructed. Releasing the parameters at "
<< (
void
*)
params_
<<
"."
;
42
}
43
44
void
GeneratorWorker::setIntegrator
(
const
Integrator
* integr) {
45
integrator_
= integr;
46
CG_DEBUG
(
"GeneratorWorker:integrator"
)
47
<<
"Dim-"
<<
integrand_
->size() <<
" "
<<
integrator_
->
name
() <<
" integrator set."
;
48
}
49
50
void
GeneratorWorker::generate
(
size_t
num_events,
const
std::function<
void
(
const
proc::Process
&)>& callback) {
51
if
(!
params_
)
52
throw
CG_FATAL
(
"GeneratorWorker:generate"
) <<
"No steering parameters specified!"
;
53
callback_proc_
= callback;
54
while
(
params_
->
numGeneratedEvents
() < num_events)
55
next
();
56
}
57
58
bool
GeneratorWorker::storeEvent
() {
59
CG_TICKER
(
const_cast<
RunParameters
*
>
(
params_
)->timeKeeper());
60
61
if
(!
integrand_
->process().hasEvent())
62
return
true
;
63
64
const
auto
&
event
=
integrand_
->process().event();
65
const
auto
ngen =
params_
->
numGeneratedEvents
();
66
if
((ngen + 1) %
params_
->
generation
().
printEvery
() == 0)
67
CG_INFO
(
"GeneratorWorker:store"
) <<
utils::s
(
"event"
, ngen + 1,
true
) <<
" generated."
;
68
if
(
callback_proc_
)
69
callback_proc_
(
integrand_
->process());
70
for
(
const
auto
& mod :
params_
->
eventExportersSequence
())
71
*mod << event;
72
const_cast<
RunParameters
*
>
(
params_
)->addGenerationTime(event.metadata(
"time:total"
));
73
return
true
;
74
}
75
76
ParametersDescription
GeneratorWorker::description
() {
77
auto
desc =
ParametersDescription
();
78
desc.setDescription(
"Unnamed generator worker"
);
79
return
desc;
80
}
81
}
// namespace cepgen
EventExporter.h
Event.h
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
GeneratorWorker.h
Integrator.h
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
CG_INFO
#define CG_INFO(mod)
Definition
Message.h:216
ProcessIntegrand.h
Process.h
RunParameters.h
String.h
TimeKeeper.h
CG_TICKER
#define CG_TICKER(tmr)
Definition
TimeKeeper.h:30
cepgen::GeneratorWorker::integrand_
std::unique_ptr< ProcessIntegrand > integrand_
Local event weight evaluator.
Definition
GeneratorWorker.h:61
cepgen::GeneratorWorker::callback_proc_
std::function< void(const proc::Process &)> callback_proc_
Callback function for each new event.
Definition
GeneratorWorker.h:62
cepgen::GeneratorWorker::params_
const RunParameters * params_
Steering parameters for the event generation.
Definition
GeneratorWorker.h:59
cepgen::GeneratorWorker::next
virtual bool next()=0
Generate a single event.
cepgen::GeneratorWorker::setIntegrator
void setIntegrator(const Integrator *integ)
Specify the integrator instance handled by the mother generator.
Definition
GeneratorWorker.cpp:44
cepgen::GeneratorWorker::generate
void generate(size_t num_events, const std::function< void(const proc::Process &)> &)
Launch the event generation.
Definition
GeneratorWorker.cpp:50
cepgen::GeneratorWorker::storeEvent
bool storeEvent()
Store the event in the output file.
Definition
GeneratorWorker.cpp:58
cepgen::GeneratorWorker::GeneratorWorker
GeneratorWorker(const ParametersList &)
Book memory slots and structures for the generator.
Definition
GeneratorWorker.cpp:31
cepgen::GeneratorWorker::description
static ParametersDescription description()
Definition
GeneratorWorker.cpp:76
cepgen::GeneratorWorker::integrator_
const Integrator * integrator_
Pointer to the mother-handled integrator instance.
Definition
GeneratorWorker.h:58
cepgen::GeneratorWorker::~GeneratorWorker
virtual ~GeneratorWorker()
Definition
GeneratorWorker.cpp:40
cepgen::GeneratorWorker::setRunParameters
void setRunParameters(const RunParameters *)
Specify the runtime parameters.
Definition
GeneratorWorker.cpp:33
cepgen::Integrator
Monte-Carlo integration algorithm.
Definition
Integrator.h:28
cepgen::NamedModule::name
const std::string & name() const
Module unique indexing name.
Definition
NamedModule.h:42
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::ProcessIntegrand
Wrapper to the function to be integrated.
Definition
ProcessIntegrand.h:36
cepgen::RunParameters::Generation::printEvery
size_t printEvery() const
Frequency at which events are displayed to the user.
Definition
RunParameters.h:94
cepgen::RunParameters
List of parameters used to start and run the simulation job.
Definition
RunParameters.h:41
cepgen::RunParameters::numGeneratedEvents
unsigned int numGeneratedEvents() const
Number of events generated in run.
Definition
RunParameters.h:144
cepgen::RunParameters::eventExportersSequence
EventExportersSequence & eventExportersSequence()
List of output modules.
Definition
RunParameters.h:124
cepgen::RunParameters::generation
Generation & generation()
Event generation parameters.
Definition
RunParameters.h:108
cepgen::SteeredObject
Base user-steerable object.
Definition
SteeredObject.h:41
cepgen::proc::Process
Class template to define any process to compute using this MC integrator/events generator.
Definition
Process.h:34
cepgen::utils::s
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition
String.cpp:228
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Core
GeneratorWorker.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7