cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
FoamGeneratorWorker.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2023 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 <TFoam.h>
20#include <TFoamIntegrand.h>
21#include <TRandom1.h>
22#include <TRandom2.h>
23#include <TRandom3.h>
24
29
30namespace cepgen {
33 class FoamGeneratorWorker final : public GeneratorWorker, public TFoamIntegrand {
34 public:
35 explicit FoamGeneratorWorker(const ParametersList& params) : GeneratorWorker(params) {
36 const auto& rnd_mode = steer<std::string>("rngEngine");
37 if (rnd_mode == "Ranlux")
38 rnd_.reset(new TRandom1);
39 else if (rnd_mode == "generic")
40 rnd_.reset(new TRandom2);
41 else if (rnd_mode == "MersenneTwister")
42 rnd_.reset(new TRandom3);
43 else
44 throw CG_FATAL("FoamGeneratorWorker") << "Unrecognised random generator: \"" << rnd_mode << "\".";
45 rnd_->SetSeed(steer<unsigned long long>("seed"));
46
47 //--- a bit of printout for debugging
48 CG_WARNING("FoamGeneratorWorker") << "This wrapping of the Foam generation algorithm implemented in ROOT "
49 "libraries is still experimental! Please use with care...";
50 }
51
53 auto desc = GeneratorWorker::description();
54 desc.setDescription("Foam generator worker");
55 desc.add<std::string>("rngEngine", "MersenneTwister")
56 .setDescription(
57 "Set random number generator engine (currently handled: 'Ranlux', 'generic', 'MersenneTwister')");
58 desc.add<int>("nCalls", 100'000).setDescription("number of calls for the cell evaluation");
59 desc.add<int>("nCells", 1000);
60 desc.add<int>("nSampl", 200);
61 desc.add<int>("nBin", 8);
62 desc.add<int>("EvPerBin", 25);
63 desc.add<int>("verbose", 0).setDescription("Verbosity level");
64 desc.add<unsigned long long>("seed", 42ull);
65 return desc;
66 }
67
68 void initialise() override {
69 foam_.reset(new TFoam("Foam"));
70 foam_->SetPseRan(rnd_.get());
71 foam_->SetnCells(steer<int>("nCells"));
72 foam_->SetnSampl(steer<int>("nSampl"));
73 foam_->SetnBin(steer<int>("nBin"));
74 foam_->SetEvPerBin(steer<int>("EvPerBin"));
75 foam_->SetChat(std::max(steer<int>("verbose"), 0));
76 foam_->SetRho(this);
77 foam_->SetkDim(integrand_->size());
78 foam_->Initialize();
79 CG_DEBUG("FoamGeneratorWorker:build") << "FOAM integrator built\n\t"
80 << "Version: " << foam_->GetVersion() << ".";
81 }
82 bool next() override {
83 foam_->MakeEvent();
84 return storeEvent();
85 }
86
88 inline double Density(int ndim, double* x) override {
89 if (integrand_)
90 return integrand_->eval(std::vector<double>(x, x + ndim));
91 throw CG_FATAL("FoamGeneratorWorker:density") << "Integrand object was not initialised!";
92 }
93
94 private:
95 std::unique_ptr<TFoam> foam_;
96 std::unique_ptr<TRandom> rnd_;
97 std::vector<double> coord_;
98 };
99} // namespace cepgen
100
101REGISTER_GENERATOR_WORKER("Foam", FoamGeneratorWorker);
#define CG_FATAL(mod)
Definition Exception.h:61
#define REGISTER_GENERATOR_WORKER(name, obj)
Add a generator worker to the list of handled modules.
#define CG_WARNING(mod)
Definition Message.h:228
#define CG_DEBUG(mod)
Definition Message.h:220
Foam generator worker algorithm as developed by S. Jadach (Institute of Nuclear Physics,...
static ParametersDescription description()
FoamGeneratorWorker(const ParametersList &params)
void initialise() override
Initialise the generation parameters.
double Density(int ndim, double *x) override
Compute the weight for a given phase space point.
bool next() override
Generate a single event.
Event generator worker instance.
std::unique_ptr< ProcessIntegrand > integrand_
Local event weight evaluator.
bool storeEvent()
Store the event in the output file.
static ParametersDescription description()
A description object for parameters collection.
Common namespace for this Monte Carlo generator.