Logo ROOT  
Reference Guide
StdEngine.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Tue Aug 4 2015
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2015 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // random engines based on ROOT
12 
13 #ifndef ROOT_Math_StdEngine
14 #define ROOT_Math_StdEngine
15 
16 #include <random>
17 
18 namespace ROOT {
19 
20  namespace Math {
21 
22 
23  class StdRandomEngine {};
24 
25  template<class Generator>
26  struct StdEngineType {
27  static const char * Name() { return "std_random_eng";}
28  };
29  template<>
30  struct StdEngineType<std::minstd_rand> {
31  static const char * Name() { return "std_minstd_rand";}
32  };
33  template<>
34  struct StdEngineType<std::mt19937> {
35  static const char * Name() { return "std_mt19937";}
36  };
37  template<>
38  struct StdEngineType<std::mt19937_64> {
39  static const char * Name() { return "std_mt19937_64";}
40  };
41  template<>
42  struct StdEngineType<std::ranlux24> {
43  static const char * Name() { return "std_ranlux24";}
44  };
45  template<>
46  struct StdEngineType<std::ranlux48> {
47  static const char * Name() { return "std_ranlux48";}
48  };
49  template<>
50  struct StdEngineType<std::knuth_b> {
51  static const char * Name() { return "std_knuth_b";}
52  };
53  template<>
54  struct StdEngineType<std::random_device> {
55  static const char * Name() { return "std_random_device";}
56  };
57 
58 
59  /**
60  @ingroup Random
61  Class to wrap engines fron the C++ standard random library in
62  the ROOT Random interface.
63  This casess is then by used by the generic TRandoGen class
64  to provide TRandom interrace generators for the C++ random generators.
65 
66  See for examples the TRandomMT64 and TRandomRanlux48 generators
67  which are typede's to TRandomGen instaniated with some
68  random engine from the C++ standard library.
69 
70  */
71 
72  template <class Generator>
73  class StdEngine {
74 
75 
76  public:
77 
79  typedef typename Generator::result_type Result_t;
80 
81  StdEngine() : fGen() {
82  fCONS = 1./fGen.max();
83  }
84 
85 
86  void SetSeed(Result_t seed) { fGen.seed(seed);}
87 
88  double Rndm() {
89  Result_t rndm = fGen(); // generate integer number according to the type
90  if (rndm != 0) return fCONS*rndm;
91  return Rndm();
92  }
93 
95  return fGen();
96  }
97 
98  double operator() () {
99  return Rndm();
100  }
101 
102  static const char * Name() {
104  }
105 
106  static uint64_t MaxInt() { return Generator::max(); }
107 
108 
109  private:
110  Generator fGen;
111  double fCONS; //! cached value of maximum integer value generated
112  };
113 
114 
115  extern template class StdEngine<std::mt19937_64>;
116  extern template class StdEngine<std::ranlux48>;
117 
118  } // end namespace Math
119 
120 } // end namespace ROOT
121 
122 
123 #endif /* ROOT_Math_StdEngine */
ROOT::Math::StdEngine::fGen
Generator fGen
Definition: StdEngine.h:110
ROOT::Math::StdEngine::IntRndm
Result_t IntRndm()
Definition: StdEngine.h:94
ROOT::Math::StdEngine::MaxInt
static uint64_t MaxInt()
Definition: StdEngine.h:106
ROOT::Math::StdEngine
Class to wrap engines fron the C++ standard random library in the ROOT Random interface.
Definition: StdEngine.h:73
ROOT::Math::StdEngine::SetSeed
void SetSeed(Result_t seed)
Definition: StdEngine.h:86
ROOT::Math::StdEngine::Name
static const char * Name()
Definition: StdEngine.h:102
ROOT::Math::StdEngine::BaseType
StdRandomEngine BaseType
Definition: StdEngine.h:78
ROOT::Math::StdRandomEngine
Definition: StdEngine.h:23
ROOT::Math::StdEngine::StdEngine
StdEngine()
Definition: StdEngine.h:81
ROOT::Math::StdEngine::Result_t
Generator::result_type Result_t
Definition: StdEngine.h:79
ROOT::Math::StdEngine::Rndm
double Rndm()
Definition: StdEngine.h:88
ROOT::Math::StdEngine::fCONS
double fCONS
Definition: StdEngine.h:111
ROOT::Math::StdEngineType::Name
static const char * Name()
Definition: StdEngine.h:27
ROOT::Math::StdEngine::operator()
double operator()()
Definition: StdEngine.h:98
ROOT::Math::StdEngineType
Definition: StdEngine.h:26
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
Math
Namespace for new Math classes and functions.