Logo ROOT   6.07/09
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 #include "Math/MixMaxEngine.h"
21 
22 //#include "Math/mixmax/mixmax.h"
23 #include <cassert>
24 #include "Math/Util.h"
25 
26 
27 namespace ROOT {
28 namespace Math {
29 
30 
31 
32  template<int N, int S>
34  // fRng = new mixmax::mixmax_engine<N>();
35  // fRng->seed(seed);
36  fRng = new MixMaxEngineImpl<N>(seed);
37  }
38 
39  template<int N, int S>
41  if (fRng) delete fRng;
42  }
43 
44 
45  // void template<int N, int S>
46  //MixMaxEngine<N,S>::SeedUniqueStream(unsigned int clusterID, unsigned int machineID, unsigned int runID, unsigned int streamID) {
47  // seed_uniquestream(fRngState, clusterID, machineID, runID, streamID);
48  // }
49 
50  template<int N, int S>
51  void MixMaxEngine<N,S>::SetSeed(uint64_t seed) {
52  //fRng->seed(seed);
53  fRng->SetSeed(seed);
54  }
55 
56  // void template<int N, int S>
57  // MixMaxEngine<N,S>::SetSeed64(uint64_t seed) {
58  // seed_spbox(fRngState, seed);
59  // iterate(fRngState);
60  // }
61 
62  // unsigned int template<int N, int S>
63  // MixMaxEngine<N,S>::GetSeed() const {
64  // return get_next(fRngState);
65  // }
66 
67  // generate one random number in interval ]0,1]
68  // apply skipping when needed
69 
70  template<int SkipNumber>
71  struct SkipFunction {
72  template<class Engine>
73  static void Apply (Engine * rng, int counter, int n) {
74  // apply skipping
75  if (counter < n) return;
76  for (int iskip = 0; iskip < SkipNumber; ++iskip)
77  rng->Iterate();
78  }
79  };
80  // specialization for SkipNumber = 0
81  template<>
82  struct SkipFunction<0> {
83  template<class Engine>
84  static void Apply (Engine *, int , int ) {
85  // no operation
86  }
87  };
88 
89  template<int N, int S>
91  int counter = fRng->Counter();
92  SkipFunction<S>::Apply(fRng, counter, N);
93  //reset counter to original value
94  // otherwise we would skip -1 time
95  fRng->SetCounter(counter);
96  return fRng->Rndm();
97  }
98 
99  // generate one integer number
100  template<int N, int S>
102  int counter = fRng->Counter();
103  SkipFunction<S>::Apply(fRng, counter,N);
104  fRng->SetCounter(counter);
105  return fRng->IntRndm();
106  }
107 
108  template<int N, int S>
110  //return mixmax::mixmax_engine<N>::max();
111  return 2305843009213693951ULL;
112  }
113 
114  template<int N, int S>
116  //return mixmax::mixmax_engine<N>::min();
117  return 0;
118  }
119 
120  template<int N, int S>
121  void MixMaxEngine<N,S>::RndmArray(int n, double *array){
122  // Return an array of n random numbers uniformly distributed in ]0,1]
123  for (int i = 0; i < n; ++i)
124  array[i] = Rndm_impl();
125  }
126 
127  template<int N, int S>
128  void MixMaxEngine<N,S>::SetState(const std::vector<StateInt_t> & state) {
129  assert(state.size() >= N);
130  // for (int i = 0; i < N; ++i)
131  // fRng->S.V[i] = state[i];
132  // //set counter to fore iteration afterwards
133  // fRng->S.counter = N;
134  fRng->SetState(state);
135  fRng->SetCounter(N);
136  }
137 
138  template<int N, int S>
139  void MixMaxEngine<N,S>::GetState(std::vector<StateInt_t> & state) const {
140  state.resize(N);
141  fRng->GetState(state);
142  }
143 
144  template<int N, int S>
146  return MixMaxEngineImpl<N>::Size();
147  }
148 
149  template<int N, int S>
151  return fRng->Counter();
152  }
153 
154  template<int N, int S>
155  std::string MixMaxEngine<N,S>::Name() {
156  std::string name = "MixMax";
157  name += Util::ToString(N);
158  if (S > 0) name += std::string("_") + Util::ToString(S);
159  return name;
160  }
161 
162  } // namespace Math
163 } // namespace ROOT
164 
165 #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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
const char * Size
Definition: TXMLSetup.cxx:56
#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 GetState(std::vector< StateInt_t > &state) const
get the state of the generator
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)
static int Size()
Get the size of the generator.
Result_t IntRndm()
generate a 64 bit integer number
Namespace for new Math classes and functions.
std::string ToString(const T &val)
Utility function for conversion to strings.
Definition: Util.h:42
int Counter() const
Get the counter (between 0 and Size-1)
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109