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_RandomFunctions
0018 #define ROOT_Math_RandomFunctions
0019
0020
0021 #include <type_traits>
0022 #include <cmath>
0023 #include "RtypesCore.h"
0024 #include "TMath.h"
0025 #include <cassert>
0026 #include <vector>
0027
0028 #include "TRandomEngine.h"
0029
0030
0031 namespace ROOT {
0032 namespace Math {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 typedef TRandomEngine DefaultEngineType;
0049
0050
0051
0052
0053
0054
0055
0056
0057 template <class EngineBaseType>
0058 class RandomFunctionsImpl {
0059 public:
0060 void SetEngine(void *) {}
0061 };
0062
0063
0064
0065
0066
0067
0068
0069 template<>
0070 class RandomFunctionsImpl<TRandomEngine> {
0071
0072 public:
0073
0074
0075 RandomFunctionsImpl() : fBaseEngine(nullptr) {}
0076
0077 void SetEngine(void *r) {
0078 fBaseEngine = static_cast<TRandomEngine*>(r);
0079 assert(fBaseEngine);
0080 }
0081
0082
0083
0084 int Binomial(int ntot, double prob);
0085
0086
0087 double BreitWigner(double mean, double gamma);
0088
0089
0090
0091
0092 void Circle(double &x, double &y, double r);
0093
0094
0095
0096 double Exp(double tau);
0097
0098
0099 double GausBM( double mean, double sigma);
0100
0101
0102 double GausACR( double mean, double sigma);
0103
0104
0105
0106
0107 double Landau(double mu, double sigma);
0108
0109
0110
0111 int Poisson(double mean);
0112 double PoissonD(double mean);
0113
0114
0115
0116 void Rannor(double &a, double &b);
0117
0118
0119
0120 void Sphere(double &x, double &y, double &z, double r);
0121
0122
0123 double Uniform(double a, double b);
0124 double Uniform(double a);
0125
0126 protected:
0127 TRandomEngine* fBaseEngine;
0128
0129 private:
0130
0131 double Rndm() { return fBaseEngine->Rndm(); }
0132
0133 double Gaus(double mean, double sigma) { return GausACR(mean,sigma); }
0134
0135
0136 };
0137
0138
0139 template < class Engine, class EngineBaseType>
0140 class RandomFunctions {
0141
0142
0143 public:
0144
0145
0146
0147 RandomFunctions(Engine & rng) : fEngine(&rng) {
0148 fImpl.SetEngine(&rng);
0149 }
0150
0151
0152 ~RandomFunctions() {}
0153
0154
0155
0156 inline double operator() () { return (*fEngine)(); }
0157
0158
0159
0160 int Binomial(int ntot, double prob) {
0161 return fImpl.Binomial(ntot,prob);
0162 }
0163
0164
0165 double BreitWigner(double mean, double gamma) {
0166 return fImpl.BreitWigner(mean,gamma);
0167 }
0168
0169
0170
0171
0172 void Circle(double &x, double &y, double r) {
0173 return fImpl.Circle(x,y,r);
0174 }
0175
0176
0177
0178 double Exp(double tau) {
0179 return fImpl.Exp(tau);
0180 }
0181
0182
0183 double GausBM( double mean, double sigma) {
0184 return fImpl.GausBM(mean,sigma);
0185 }
0186
0187
0188 double GausACR( double mean, double sigma) {
0189 return fImpl.GausACR(mean, sigma);
0190 }
0191
0192
0193
0194
0195 double Landau(double mu, double sigma) {
0196 return fImpl.Landau(mu,sigma);
0197 }
0198
0199
0200
0201 int Poisson(double mean) { return fImpl.Poisson(mean); }
0202 double PoissonD(double mean) { return fImpl.PoissonD(mean); }
0203
0204
0205
0206 void Rannor(double &a, double &b) {
0207 return fImpl.Rannor(a,b);
0208 }
0209
0210
0211
0212 void Sphere(double &x, double &y, double &z, double r) {
0213 return fImpl.Sphere(x,y,z,r);
0214 }
0215
0216
0217 double Uniform(double a, double b) {
0218 return (b-a) * Rndm_impl() + a;
0219 }
0220
0221
0222 double Uniform(double a) {
0223 return a * Rndm_impl() ;
0224 }
0225
0226
0227
0228 inline double Gaus( double mean, double sigma) {
0229 return fImpl.GausACR(mean,sigma);
0230 }
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248 double Gamma( double , double ) {
0249
0250 static_assert(std::is_fundamental<Engine>::value,"Error: Gamma() requires a GSL Engine type");
0251 return 0;
0252 }
0253 double Beta( double , double ) {
0254 static_assert(std::is_fundamental<Engine>::value,"Error: Beta() requires a GSL Engine type");
0255 return 0;
0256 }
0257 double LogNormal(double, double) {
0258 static_assert(std::is_fundamental<Engine>::value,"Error: LogNormal() requires a GSL Engine type");
0259 return 0;
0260 }
0261 double ChiSquare(double) {
0262 static_assert(std::is_fundamental<Engine>::value,"Error: ChiSquare() requires a GSL Engine type");
0263 return 0;
0264 }
0265 double Rayleigh( double ) {
0266 static_assert(std::is_fundamental<Engine>::value,"Error: Rayleigh() requires a GSL Engine type");
0267 return 0;
0268 }
0269 double Logistic( double ) {
0270 static_assert(std::is_fundamental<Engine>::value,"Error: Logistic() requires a GSL Engine type");
0271 return 0;
0272 }
0273 double Pareto( double , double ) {
0274 static_assert(std::is_fundamental<Engine>::value,"Error: Pareto() requires a GSL Engine type");
0275 return 0;
0276 }
0277 double FDist(double, double) {
0278 static_assert(std::is_fundamental<Engine>::value,"Error: FDist() requires a GSL Engine type");
0279 return 0;
0280 }
0281 double tDist(double) {
0282 static_assert(std::is_fundamental<Engine>::value,"Error: tDist() requires a GSL Engine type");
0283 return 0;
0284 }
0285 unsigned int NegativeBinomial(double , double ) {
0286 static_assert(std::is_fundamental<Engine>::value,"Error: NegativeBinomial() requires a GSL Engine type");
0287 return 0;
0288 }
0289 std::vector<unsigned int> MultiNomial(unsigned int, const std::vector<double> &){
0290 static_assert(std::is_fundamental<Engine>::value,"Error: MultiNomial() requires a GSL Engine type");
0291 return std::vector<unsigned int>();
0292 }
0293
0294
0295 protected:
0296
0297 Engine & Rng() { assert(fEngine); return *fEngine; }
0298
0299
0300
0301 inline double Rndm_impl() { return (*fEngine)(); }
0302
0303
0304 private:
0305
0306 Engine * fEngine;
0307 RandomFunctionsImpl<EngineBaseType> fImpl;
0308
0309
0310 };
0311
0312
0313
0314
0315 }
0316 }
0317
0318 #endif