Logo ROOT  
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  const char *MixMaxEngine<N, S>::Name() {
158  static const std::string name = "MixMax" + Util::ToString(N) + (S > 0 ? "_" + Util::ToString(S) : "");
159  return name.c_str();
160  }
161 
162  } // namespace Math
163 } // namespace ROOT
164 
165 #endif
ROOT::Math::MixMaxEngine::Counter
int Counter() const
Get the counter (between 0 and Size-1)
Definition: MixMaxEngine.icc:152
Util.h
n
const Int_t n
Definition: legend1.C:16
ROOT::Math::MixMaxEngine::MixMaxEngine
MixMaxEngine(uint64_t seed=1)
Definition: MixMaxEngine.icc:35
ROOT::Math::MixMaxEngine::IntRndm
Result_t IntRndm()
generate a 64 bit integer number
Definition: MixMaxEngine.icc:103
ROOT::Math::MixMaxEngine::Name
static const char * Name()
get name of the generator
Definition: MixMaxEngine.icc:157
ROOT::Math::MixMaxEngine::RndmArray
void RndmArray(int n, double *array)
generate an array of random numbers
Definition: MixMaxEngine.icc:123
ROOT::Math::MixMaxEngine::Rndm_impl
double Rndm_impl()
implementation function to generate the random number
Definition: MixMaxEngine.icc:92
ROOT::Math::SkipFunction::Apply
static void Apply(Engine *rng, int counter, int n)
Definition: MixMaxEngine.icc:75
ROOT::Math::MixMaxEngine::SetSeed
void SetSeed(Result_t seed)
set the generator seed
Definition: MixMaxEngine.icc:53
N
#define N
ROOT::Math::MixMaxEngine::GetState
void GetState(std::vector< StateInt_t > &state) const
get the state of the generator
Definition: MixMaxEngine.icc:141
ROOT::Math::MixMaxEngine::MinInt
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
Definition: MixMaxEngine.icc:117
RooFitShortHand::S
RooArgSet S(const RooAbsArg &v1)
Definition: RooGlobalFunc.cxx:348
ROOT::Math::MixMaxEngine::Size
static int Size()
Get the size of the generator.
Definition: MixMaxEngine.icc:147
ROOT::Math::MixMaxEngine::SetState
void SetState(const std::vector< StateInt_t > &state)
set the full initial generator state
Definition: MixMaxEngine.icc:130
ROOT::Math::MixMaxEngineImpl
Definition: MixMaxEngineImpl.h:51
ROOT::Math::Util::ToString
std::string ToString(const T &val)
Utility function for conversion to strings.
Definition: Util.h:50
ROOT::Math::MixMaxEngine::MaxInt
static uint64_t MaxInt()
maximum integer that can be generated. For MIXMAX is 2^61-1
Definition: MixMaxEngine.icc:111
ROOT::Math::SkipFunction
Definition: MixMaxEngine.icc:73
xmlio::Size
const char * Size
Definition: TXMLSetup.cxx:56
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::SkipFunction< 0 >::Apply
static void Apply(Engine *, int, int)
Definition: MixMaxEngine.icc:86
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Math::MixMaxEngine::~MixMaxEngine
virtual ~MixMaxEngine()
Definition: MixMaxEngine.icc:42
Math
Namespace for new Math classes and functions.