Logo ROOT   6.12/07
Reference Guide
MixMaxEngine.icc
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: L. Moneta 8/2015
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2015 , ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // implementation file of MixMax engine
12 //
13 //
14 // Created by: Lorenzo Moneta : Tue 4 Aug 2015
15 //
16 //
17 #ifndef ROOT_Math_MixMaxEngine_icc
18 #define ROOT_Math_MixMaxEngine_icc
19 
20 #ifndef ROOT_Math_MixMaxEngine
21 #error "Do not use MixMaxEngine.icc directly. #include \"MixMaxEngine.h\" instead."
22 #endif // ROOT_Math_MixMaxEngine
23 
24 //#include "Math/mixmax/mixmax.h"
25 #include <cassert>
26 #include "Math/Util.h"
27 
28 
29 namespace ROOT {
30 namespace Math {
31 
32 
33 
34  template<int N, int S>
36  // fRng = new mixmax::mixmax_engine<N>();
37  // fRng->seed(seed);
38  fRng = new MixMaxEngineImpl<N>(seed);
39  }
40 
41  template<int N, int S>
43  if (fRng) delete fRng;
44  }
45 
46 
47  // void template<int N, int S>
48  //MixMaxEngine<N,S>::SeedUniqueStream(unsigned int clusterID, unsigned int machineID, unsigned int runID, unsigned int streamID) {
49  // seed_uniquestream(fRngState, clusterID, machineID, runID, streamID);
50  // }
51 
52  template<int N, int S>
53  void MixMaxEngine<N,S>::SetSeed(uint64_t seed) {
54  //fRng->seed(seed);
55  fRng->SetSeed(seed);
56  }
57 
58  // void template<int N, int S>
59  // MixMaxEngine<N,S>::SetSeed64(uint64_t seed) {
60  // seed_spbox(fRngState, seed);
61  // iterate(fRngState);
62  // }
63 
64  // unsigned int template<int N, int S>
65  // MixMaxEngine<N,S>::GetSeed() const {
66  // return get_next(fRngState);
67  // }
68 
69  // generate one random number in interval ]0,1]
70  // apply skipping when needed
71 
72  template<int SkipNumber>
73  struct SkipFunction {
74  template<class Engine>
75  static void Apply (Engine * rng, int counter, int n) {
76  // apply skipping
77  if (counter < n) return;
78  for (int iskip = 0; iskip < SkipNumber; ++iskip)
79  rng->Iterate();
80  }
81  };
82  // specialization for SkipNumber = 0
83  template<>
84  struct SkipFunction<0> {
85  template<class Engine>
86  static void Apply (Engine *, int , int ) {
87  // no operation
88  }
89  };
90 
91  template<int N, int S>
93  int counter = fRng->Counter();
94  SkipFunction<S>::Apply(fRng, counter, N);
95  //reset counter to original value
96  // otherwise we would skip -1 time
97  fRng->SetCounter(counter);
98  return fRng->Rndm();
99  }
100 
101  // generate one integer number
102  template<int N, int S>
104  int counter = fRng->Counter();
105  SkipFunction<S>::Apply(fRng, counter,N);
106  fRng->SetCounter(counter);
107  return fRng->IntRndm();
108  }
109 
110  template<int N, int S>
112  //return mixmax::mixmax_engine<N>::max();
113  return 2305843009213693951ULL;
114  }
115 
116  template<int N, int S>
118  //return mixmax::mixmax_engine<N>::min();
119  return 0;
120  }
121 
122  template<int N, int S>
123  void MixMaxEngine<N,S>::RndmArray(int n, double *array){
124  // Return an array of n random numbers uniformly distributed in ]0,1]
125  for (int i = 0; i < n; ++i)
126  array[i] = Rndm_impl();
127  }
128 
129  template<int N, int S>
130  void MixMaxEngine<N,S>::SetState(const std::vector<StateInt_t> & state) {
131  assert(state.size() >= N);
132  // for (int i = 0; i < N; ++i)
133  // fRng->S.V[i] = state[i];
134  // //set counter to fore iteration afterwards
135  // fRng->S.counter = N;
136  fRng->SetState(state);
137  fRng->SetCounter(N);
138  }
139 
140  template<int N, int S>
141  void MixMaxEngine<N,S>::GetState(std::vector<StateInt_t> & state) const {
142  state.resize(N);
143  fRng->GetState(state);
144  }
145 
146  template<int N, int S>
148  return MixMaxEngineImpl<N>::Size();
149  }
150 
151  template<int N, int S>
153  return fRng->Counter();
154  }
155 
156  template<int N, int S>
157  std::string MixMaxEngine<N,S>::Name() {
158  std::string name = "MixMax";
159  name += Util::ToString(N);
160  if (S > 0) name += std::string("_") + Util::ToString(S);
161  return name;
162  }
163 
164  } // namespace Math
165 } // namespace ROOT
166 
167 #endif
static uint64_t MaxInt()
maximum integer that can be generated. For MIXMAX is 2^61-1
static std::string Name()
get name of the generator
void SetState(const std::vector< StateInt_t > &state)
set the full initial generator state
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
const char * Size
Definition: TXMLSetup.cxx:55
#define N
static void Apply(Engine *rng, int counter, int n)
static void Apply(Engine *, int, int)
MixMaxEngine(uint64_t seed=1)
double Rndm_impl()
implementation function to generate the random number
void SetSeed(Result_t seed)
set the generator seed
void RndmArray(int n, double *array)
generate an array of random numbers
RooArgSet S(const RooAbsArg &v1)
int Counter() const
Get the counter (between 0 and Size-1)
static int Size()
Get the size of the generator.
Result_t IntRndm()
generate a 64 bit integer number
void GetState(std::vector< StateInt_t > &state) const
get the state of the generator
Namespace for new Math classes and functions.
std::string ToString(const T &val)
Utility function for conversion to strings.
Definition: Util.h:42
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109