MCBooster  1.0.1
Tool to generate MC phase space samples in parallel.
FlagAcceptReject.h
Go to the documentation of this file.
1 /*
2  * FlagAcceptReject.h
3  *
4  * Copyright 2016 Antonio Augusto Alves Junior
5  *
6  * Created on : 29/03/2016
7  * Author: Antonio Augusto Alves Junior
8  */
9 
10 /*
11  This file is part of MCBooster.
12 
13  MCBooster is free software: you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  MCBooster is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with MCBooster. If not, see <http://www.gnu.org/licenses/>.
25 */
26 
30 #ifndef FLAGACCEPTEDREJECTED_H_
31 #define FLAGACCEPTEDREJECTED_H_
32 
33 
34 
35 #include <mcbooster/Config.h>
36 #include <thrust/random.h>
37 #include <mcbooster/GTypes.h>
38 
39 namespace MCBooster
40 {
45 {
46 
48 
52  FlagAcceptReject(const GReal_t _wmax) :
53  wmax(_wmax)
54  { }
55 
59  __host__ __device__ GUInt_t hash(GUInt_t a)
60  {
61  a = (a + 0x7ed55d16) + (a << 12);
62  a = (a ^ 0xc761c23c) ^ (a >> 19);
63  a = (a + 0x165667b1) + (a << 5);
64  a = (a + 0xd3a2646c) ^ (a << 9);
65  a = (a + 0xfd7046c5) + (a << 3);
66  a = (a ^ 0xb55a4f09) ^ (a >> 16);
67  return a;
68  }
73  __host__ __device__ GBool_t operator ()(GLong_t idx, GReal_t weight)
74  {
75  GUInt_t seed = hash(idx+68464654684);
76  thrust::default_random_engine randEng(seed);
77  thrust::uniform_real_distribution<GReal_t> uniDist(0.0, wmax);
78 
79 
80  GBool_t flag = (uniDist(randEng) < weight) ? 1 : 0;
81  return flag;
82 
83  }
84 
85 };
86 }
87 
88 
89 
90 #endif /* FLAGACCEPTEDREJECTED_H_ */
FlagAcceptReject(const GReal_t _wmax)
FlagAcceptReject constructor.
__host__ __device__ GBool_t operator()(GLong_t idx, GReal_t weight)
operator().
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
bool GBool_t
Boolean (0=false, 1=true) (bool)
Definition: GTypes.h:45
GReal_t wmax
maximum weight
Flags generated events as accepted (1) or rejected (0).
double GReal_t
Double 8 bytes or float 4 bytes.
Definition: GTypes.h:52
__host__ __device__ GUInt_t hash(GUInt_t a)
hash function.