File indexing completed on 2025-01-30 10:22:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef ROOT_Math_Random
0018 #define ROOT_Math_Random
0019
0020
0021
0022
0023
0024 #include "Math/RandomFunctions.h"
0025
0026 #include <string>
0027 #include <vector>
0028 #include <cstdint>
0029
0030
0031 namespace ROOT {
0032 namespace Math {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 template < class Engine>
0043 class Random {
0044
0045 public:
0046
0047 typedef typename Engine::BaseType EngineBaseType;
0048 typedef RandomFunctions<Engine, EngineBaseType> RndmFunctions;
0049
0050 Random() :
0051 fEngine(),
0052 fFunctions(fEngine)
0053 {}
0054
0055 explicit Random(unsigned int seed) :
0056 fEngine(),
0057 fFunctions(fEngine)
0058 {
0059 fEngine.SetSeed(seed);
0060 }
0061
0062 double Rndm() {
0063 return fEngine();
0064 }
0065
0066
0067
0068
0069
0070
0071 void RndmArray(int n, double * array) {
0072 fEngine.RandomArray(array, array+n);
0073 }
0074
0075
0076
0077
0078 std::string Type() const {
0079 return fEngine.Name();
0080 }
0081
0082
0083
0084
0085 unsigned int EngineSize() const {
0086 return fEngine.Size();
0087 }
0088
0089
0090 double operator() (){
0091 return fEngine();
0092 }
0093
0094 uint64_t Integer() {
0095 return fEngine.IntRndm();
0096 }
0097
0098 static uint64_t MaxInt() {
0099 return Engine::Max();
0100 }
0101
0102 Engine & Rng() {
0103 return fEngine;
0104 }
0105
0106
0107 double Exp(double tau) {
0108 return fFunctions.Exp(tau);
0109 }
0110
0111 double Gaus(double mean = 0, double sigma = 1) {
0112 return fFunctions.Gaus(mean,sigma);
0113 }
0114
0115
0116 double Gamma(double a, double b) {
0117 return fFunctions.Gamma(a,b);
0118 }
0119
0120
0121 double Beta(double a, double b) {
0122 return fFunctions.Beta(a,b);
0123 }
0124
0125
0126 double LogNormal(double zeta, double sigma) {
0127 return fFunctions.LogNormal(zeta,sigma);
0128 }
0129
0130
0131 double ChiSquare(double nu) {
0132 return fFunctions.ChiSquare(nu);
0133 }
0134
0135
0136 double Rayleigh(double sigma) {
0137 return fFunctions.Rayleigh(sigma);
0138 }
0139
0140
0141 double Logistic(double a) {
0142 return fFunctions.Logistic(a);
0143 }
0144
0145
0146 double Pareto(double a, double b) {
0147 return fFunctions.Pareto(a, b);
0148 }
0149
0150
0151 double FDist(double nu1, double nu2) {
0152 return fFunctions.FDist(nu1,nu2);
0153 }
0154
0155
0156 double tDist(double nu) {
0157 return fFunctions.tDist(nu);
0158 }
0159
0160
0161 double Landau(double m = 0, double s = 1) {
0162 return fFunctions.Landau(m,s);
0163 }
0164
0165 double BreitWigner(double mean = 0., double gamma = 1) {
0166 return fFunctions.BreitWigner(mean,gamma);
0167 }
0168
0169
0170 void Circle(double &x, double &y, double r = 1) {
0171 fFunctions.Circle(x,y,r);
0172 }
0173
0174
0175 void Sphere(double &x, double &y, double &z,double r = 1) {
0176 fFunctions.Sphere(x,y,z,r);
0177 }
0178
0179
0180
0181
0182
0183 unsigned int Binomial(unsigned int ntot, double prob) {
0184 return fFunctions.Binomial(prob,ntot);
0185 }
0186
0187
0188
0189 unsigned int Poisson(double mu) {
0190 return fFunctions.Poisson(mu);
0191 }
0192
0193
0194
0195
0196 unsigned int NegativeBinomial(double n, double prob) {
0197 return fFunctions.NegativeBinomial(prob,n);
0198 }
0199
0200
0201 std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) {
0202 return fFunctions.Multinomial(ntot,p);
0203 }
0204
0205
0206
0207 double Uniform(double a, double b) {
0208 return fFunctions.Uniform(a,b);
0209 }
0210 double Uniform(double a = 1.0) {
0211 return fFunctions.Uniform(a);
0212 }
0213 double Uniform2(double a, double b) {
0214 return fFunctions.UniformBase(a,b);
0215 }
0216
0217
0218 RandomFunctions<Engine,EngineBaseType> & Functions() {
0219 return fFunctions;
0220 }
0221
0222 void SetSeed(int seed) { fEngine.SetSeed(seed);}
0223
0224 private:
0225
0226 Engine fEngine;
0227 RndmFunctions fFunctions;
0228
0229
0230 };
0231
0232
0233
0234
0235 }
0236 }
0237
0238 #include "Math/MixMaxEngine.h"
0239 #include "Math/MersenneTwisterEngine.h"
0240 #include "Math/StdEngine.h"
0241
0242 namespace ROOT {
0243 namespace Math {
0244
0245
0246
0247 typedef Random<ROOT::Math::MixMaxEngine<240,0>> RandomMixMax;
0248 typedef Random<ROOT::Math::MersenneTwisterEngine> RandomMT19937;
0249 typedef Random<ROOT::Math::StdEngine<std::mt19937_64>> RandomMT64;
0250 typedef Random<ROOT::Math::StdEngine<std::ranlux48>> RandomRanlux48;
0251
0252 }
0253 }
0254
0255
0256 #endif