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
22#include "CepGen/Event/Event.h"
27#include "CepGen/Utils/String.h"
29
30namespace cepgen {
32
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
41 CG_DEBUG("GeneratorWorker") << "Generator worker destructed. Releasing the parameters at " << (void*)params_ << ".";
42 }
43
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
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.";
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
77 auto desc = ParametersDescription();
78 desc.setDescription("Unnamed generator worker");
79 return desc;
80 }
81} // namespace cepgen
#define CG_FATAL(mod)
Definition Exception.h:61
#define CG_DEBUG(mod)
Definition Message.h:220
#define CG_INFO(mod)
Definition Message.h:216
#define CG_TICKER(tmr)
Definition TimeKeeper.h:30
std::unique_ptr< ProcessIntegrand > integrand_
Local event weight evaluator.
std::function< void(const proc::Process &)> callback_proc_
Callback function for each new event.
const RunParameters * params_
Steering parameters for the event generation.
virtual bool next()=0
Generate a single event.
void setIntegrator(const Integrator *integ)
Specify the integrator instance handled by the mother generator.
void generate(size_t num_events, const std::function< void(const proc::Process &)> &)
Launch the event generation.
bool storeEvent()
Store the event in the output file.
GeneratorWorker(const ParametersList &)
Book memory slots and structures for the generator.
static ParametersDescription description()
const Integrator * integrator_
Pointer to the mother-handled integrator instance.
void setRunParameters(const RunParameters *)
Specify the runtime parameters.
Monte-Carlo integration algorithm.
Definition Integrator.h:28
const std::string & name() const
Module unique indexing name.
Definition NamedModule.h:42
A description object for parameters collection.
Wrapper to the function to be integrated.
size_t printEvery() const
Frequency at which events are displayed to the user.
List of parameters used to start and run the simulation job.
unsigned int numGeneratedEvents() const
Number of events generated in run.
EventExportersSequence & eventExportersSequence()
List of output modules.
Generation & generation()
Event generation parameters.
Base user-steerable object.
Class template to define any process to compute using this MC integrator/events generator.
Definition Process.h:34
std::string s(const std::string &word, float num, bool show_number)
Add a trailing "s" when needed.
Definition String.cpp:228
Common namespace for this Monte Carlo generator.