cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
RandomGenerator.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2023-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 <TRandom1.h>
20
#include <TRandom2.h>
21
#include <TRandom3.h>
22
#include <TRandomGen.h>
23
24
#include <memory>
25
26
#include "
CepGen/Core/Exception.h
"
27
#include "
CepGen/Modules/RandomGeneratorFactory.h
"
28
#include "
CepGen/Utils/RandomGenerator.h
"
29
30
namespace
cepgen
{
31
namespace
root
{
32
class
RandomGenerator
:
public
utils::RandomGenerator
{
33
public
:
34
explicit
RandomGenerator
(
const
ParametersList
& params) : utils::
RandomGenerator
(params) {
35
const
auto
& type = steer<std::string>(
"type"
);
36
if
(type ==
"Ranlux"
)
37
rng_.reset(
new
TRandom1);
38
else
if
(type ==
"Tausworthe"
)
39
rng_.reset(
new
TRandom2);
40
else
if
(type ==
"MersenneTwister"
)
41
rng_.reset(
new
TRandom3);
42
else
if
(type ==
"Ranluxpp"
)
43
rng_.reset(
new
TRandomRanluxpp);
44
else
if
(type ==
"MixMax"
)
45
rng_.reset(
new
TRandomMixMax);
46
else
if
(type ==
"MixMax17"
)
47
rng_.reset(
new
TRandomMixMax17);
48
else
if
(type ==
"MixMax256"
)
49
rng_.reset(
new
TRandomMixMax256);
50
else
51
throw
CG_FATAL
(
"root:RandomGenerator"
) <<
"Random number generator engine invalid: '"
<< type <<
"'."
;
52
53
rng_->SetSeed(
seed_
);
54
}
55
56
static
ParametersDescription
description
() {
57
auto
desc =
utils::RandomGenerator::description
();
58
desc.setDescription(
"ROOT random number generator engine"
);
59
desc.add<std::string>(
"type"
,
"Ranlux"
)
60
.setDescription(
"random number engine"
)
61
.allow(
"Ranlux"
)
62
.allow(
"Tausworthe"
)
63
.allow(
"MersenneTwister"
)
64
.allow(
"Ranluxpp"
)
65
.allow(
"MixMax"
)
66
.allow(
"MixMax17"
)
67
.allow(
"MixMax256"
);
68
return
desc;
69
}
70
71
int
uniformInt
(
int
min,
int
max)
override
{
return
min + rng_->Integer(max - min + 1); }
72
double
uniform
(
double
min,
double
max)
override
{
return
rng_->Uniform(min, max); }
73
double
normal
(
double
mean,
double
rms)
override
{
return
rng_->Gaus(mean, rms); }
74
double
exponential
(
double
exponent)
override
{
return
rng_->Exp(exponent); }
75
double
breitWigner
(
double
mean,
double
scale)
override
{
return
rng_->BreitWigner(mean, scale); }
76
double
landau
(
double
location,
double
width)
override
{
return
rng_->Landau(location, width); }
77
int
poisson
(
double
mean)
override
{
return
rng_->Poisson(mean); }
78
79
private
:
80
void
* enginePtr()
override
{
return
rng_.get(); }
81
std::unique_ptr<TRandom> rng_;
82
};
83
}
// namespace root
84
}
// namespace cepgen
85
using
ROOTRandomGenerator
=
cepgen::root::RandomGenerator
;
86
REGISTER_RANDOM_GENERATOR
(
"root"
,
ROOTRandomGenerator
);
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
RandomGeneratorFactory.h
REGISTER_RANDOM_GENERATOR
#define REGISTER_RANDOM_GENERATOR(name, obj)
Add a generic random number generator definition to the list of handled modules.
Definition
RandomGeneratorFactory.h:25
RandomGenerator.h
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::root::RandomGenerator
Definition
RandomGenerator.cpp:32
cepgen::root::RandomGenerator::normal
double normal(double mean, double rms) override
Definition
RandomGenerator.cpp:73
cepgen::root::RandomGenerator::RandomGenerator
RandomGenerator(const ParametersList ¶ms)
Definition
RandomGenerator.cpp:34
cepgen::root::RandomGenerator::poisson
int poisson(double mean) override
Definition
RandomGenerator.cpp:77
cepgen::root::RandomGenerator::description
static ParametersDescription description()
Definition
RandomGenerator.cpp:56
cepgen::root::RandomGenerator::uniformInt
int uniformInt(int min, int max) override
Definition
RandomGenerator.cpp:71
cepgen::root::RandomGenerator::uniform
double uniform(double min, double max) override
Definition
RandomGenerator.cpp:72
cepgen::root::RandomGenerator::exponential
double exponential(double exponent) override
Definition
RandomGenerator.cpp:74
cepgen::root::RandomGenerator::breitWigner
double breitWigner(double mean, double scale) override
Definition
RandomGenerator.cpp:75
cepgen::root::RandomGenerator::landau
double landau(double location, double width) override
Definition
RandomGenerator.cpp:76
cepgen::utils::RandomGenerator
A random number generator.
Definition
RandomGenerator.h:31
cepgen::utils::RandomGenerator::description
static ParametersDescription description()
Definition
RandomGenerator.cpp:53
cepgen::utils::RandomGenerator::seed_
unsigned long long seed_
Definition
RandomGenerator.h:56
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
python_modules.Integrators.root_cfi.root
root
Definition
root_cfi.py:3
CepGenAddOns
ROOTWrapper
RandomGenerator.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7