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
25
#include "
CepGen/Core/Exception.h
"
26
#include "
CepGen/Core/GeneratorWorker.h
"
27
#include "
CepGen/Integration/ProcessIntegrand.h
"
28
#include "
CepGen/Modules/GeneratorWorkerFactory.h
"
29
30
namespace
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
52
static
ParametersDescription
description
() {
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
101
REGISTER_GENERATOR_WORKER
(
"Foam"
, FoamGeneratorWorker);
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
GeneratorWorkerFactory.h
REGISTER_GENERATOR_WORKER
#define REGISTER_GENERATOR_WORKER(name, obj)
Add a generator worker to the list of handled modules.
Definition
GeneratorWorkerFactory.h:25
GeneratorWorker.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
ProcessIntegrand.h
cepgen::FoamGeneratorWorker
Foam generator worker algorithm as developed by S. Jadach (Institute of Nuclear Physics,...
Definition
FoamGeneratorWorker.cpp:33
cepgen::FoamGeneratorWorker::description
static ParametersDescription description()
Definition
FoamGeneratorWorker.cpp:52
cepgen::FoamGeneratorWorker::FoamGeneratorWorker
FoamGeneratorWorker(const ParametersList ¶ms)
Definition
FoamGeneratorWorker.cpp:35
cepgen::FoamGeneratorWorker::initialise
void initialise() override
Initialise the generation parameters.
Definition
FoamGeneratorWorker.cpp:68
cepgen::FoamGeneratorWorker::Density
double Density(int ndim, double *x) override
Compute the weight for a given phase space point.
Definition
FoamGeneratorWorker.cpp:88
cepgen::FoamGeneratorWorker::next
bool next() override
Generate a single event.
Definition
FoamGeneratorWorker.cpp:82
cepgen::GeneratorWorker
Event generator worker instance.
Definition
GeneratorWorker.h:32
cepgen::GeneratorWorker::integrand_
std::unique_ptr< ProcessIntegrand > integrand_
Local event weight evaluator.
Definition
GeneratorWorker.h:61
cepgen::GeneratorWorker::storeEvent
bool storeEvent()
Store the event in the output file.
Definition
GeneratorWorker.cpp:58
cepgen::GeneratorWorker::description
static ParametersDescription description()
Definition
GeneratorWorker.cpp:76
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
ROOTWrapper
FoamGeneratorWorker.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7