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
29
30namespace cepgen {
31 namespace root {
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
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
#define CG_FATAL(mod)
Definition Exception.h:61
#define REGISTER_RANDOM_GENERATOR(name, obj)
Add a generic random number generator definition to the list of handled modules.
A description object for parameters collection.
double normal(double mean, double rms) override
RandomGenerator(const ParametersList &params)
int poisson(double mean) override
static ParametersDescription description()
int uniformInt(int min, int max) override
double uniform(double min, double max) override
double exponential(double exponent) override
double breitWigner(double mean, double scale) override
double landau(double location, double width) override
A random number generator.
static ParametersDescription description()
Common namespace for this Monte Carlo generator.