MCBooster  1.0.1
Tool to generate MC phase space samples in parallel.
RandGen.h
Go to the documentation of this file.
1 /*
2  * RandGen.cuh
3  *
4  * Created on : Feb 25, 2016
5  * Author: Antonio Augusto Alves Junior
6  */
7 
8 /*
9  * This file is part of MCBooster.
10  *
11  * MCBooster is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * MCBooster is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with MCBooster. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 
26 #ifndef RANDGEN_H_
27 #define RANDGEN_H_
28 
29 #include <mcbooster/Config.h>
30 #include <thrust/random.h>
31 #include <mcbooster/GTypes.h>
32 #include <mcbooster/GContainers.h>
33 
34 
35 namespace MCBooster
36 {
40 struct RandGen
41 {
44 
48  RandGen(const GInt_t _ndaughters, GReal_t *_rnd) :
49  fRndNumbers(_rnd), fNDaughters(_ndaughters)
50  {
51  }
52 
56  __host__ __device__ GUInt_t hash(GUInt_t a)
57  {
58  a = (a + 0x7ed55d16) + (a << 12);
59  a = (a ^ 0xc761c23c) ^ (a >> 19);
60  a = (a + 0x165667b1) + (a << 5);
61  a = (a + 0xd3a2646c) ^ (a << 9);
62  a = (a + 0xfd7046c5) + (a << 3);
63  a = (a ^ 0xb55a4f09) ^ (a >> 16);
64  return a;
65  }
66 
70  __host__ __device__ void operator ()(GLong_t idx)
71  {
72  GUInt_t seed = hash(idx);
73  thrust::random::default_random_engine randEng(seed);
74  thrust::uniform_real_distribution<GReal_t> uniDist(0.0, 1.0);
75 
76 
77  fRndNumbers[idx] = uniDist(randEng);
78 
79  }
80 
81 };
82 
83 struct RandGen2
84 {
94  __host__ __device__ GReal_t operator ()(GInt_t idx)
95  {
96 
97  thrust::random::default_random_engine randEng;
98  randEng.discard(idx);
99  thrust::uniform_real_distribution<GReal_t> uniDist(0.0, 1.0);
100 
101  return uniDist(randEng);
102 
103 
104  }
105 
106 };
107 
108 }
109 
110 #endif /* RANDGEN_H_ */
__host__ __device__ GUInt_t hash(GUInt_t a)
hash function.
Definition: RandGen.h:56
RandGen(const GInt_t _ndaughters, GReal_t *_rnd)
RandGen ctor.
Definition: RandGen.h:48
GInt_t fNDaughters
Number of daughter particles.
Definition: RandGen.h:42
long GLong_t
Signed long integer 4 bytes (long)
Definition: GTypes.h:39
unsigned int GUInt_t
Unsigned integer 4 bytes (unsigned int)
Definition: GTypes.h:38
Typedef for useful container classes used in MCBooster.
Fill a given vector with random numbers between 0 and 1.
Definition: RandGen.h:40
double GReal_t
Double 8 bytes or float 4 bytes.
Definition: GTypes.h:52
GReal_t * fRndNumbers
Pointer to the array of random numbers.
Definition: RandGen.h:43
int GInt_t
Signed integer 4 bytes (int)
Definition: GTypes.h:37
__host__ __device__ void operator()(GLong_t idx)
operator().
Definition: RandGen.h:70
__host__ __device__ GReal_t operator()(GInt_t idx)
RandGen2 ctor.
Definition: RandGen.h:94