Geant4  10.01.p02
G4MTRandFlat.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id:$
28 //
29 // Class G4MTRandFlat
30 //
31 // Modified version with MT extensions
32 // of corresponding CLHEP class RandFlat
33 
34 // --------------------------------------------------------------------
35 #ifndef G4MTRandFlat_hh
36 #define G4MTRandFlat_hh 1
37 
38 #include "G4MTHepRandom.hh"
39 
41 {
42 
43 public:
44 
45  inline G4MTRandFlat ( CLHEP::HepRandomEngine& anEngine );
46  inline G4MTRandFlat ( CLHEP::HepRandomEngine& anEngine, G4double width );
47  inline G4MTRandFlat ( CLHEP::HepRandomEngine& anEngine, G4double a, G4double b );
48  inline G4MTRandFlat ( CLHEP::HepRandomEngine* anEngine );
49  inline G4MTRandFlat ( CLHEP::HepRandomEngine* anEngine, G4double width );
50  inline G4MTRandFlat ( CLHEP::HepRandomEngine* anEngine, G4double a, G4double b );
51  // These constructors should be used to instantiate a RandFlat
52  // distribution object defining a local engine for it.
53  // The static generator will be skipped using the non-static methods
54  // defined below.
55  // If the engine is passed by pointer the corresponding engine object
56  // will be deleted by the RandFlat destructor.
57  // If the engine is passed by reference the corresponding engine object
58  // will not be deleted by the RandFlat destructor.
59 
60  virtual ~G4MTRandFlat();
61  // Destructor
62 
63  // Static methods to shoot random values using the static generator
64 
65  static G4double shoot();
66 
67  static inline G4double shoot( G4double width );
68 
69  static inline G4double shoot( G4double a, G4double b );
70 
71  static inline G4long shootInt( G4long n );
72 
73  static inline G4long shootInt( G4long m, G4long n );
74 
75  static inline G4int shootBit();
76 
77  static void shootArray ( const G4int size, G4double* vect );
78 
79  static void shootArray ( const G4int size, G4double* vect,
80  G4double lx, G4double dx );
81 
82  // Static methods to shoot random values using a given engine
83  // by-passing the static generator.
84 
85  static inline G4double shoot ( CLHEP::HepRandomEngine* anEngine );
86 
87  static inline G4double shoot( CLHEP::HepRandomEngine* anEngine, G4double width );
88 
89  static inline G4double shoot( CLHEP::HepRandomEngine* anEngine,
90  G4double a, G4double b );
91  static inline G4long shootInt( CLHEP::HepRandomEngine* anEngine, G4long n );
92 
93  static inline G4long shootInt( CLHEP::HepRandomEngine* anEngine, G4long m, G4long n );
94 
95  static inline G4int shootBit( CLHEP::HepRandomEngine* );
96 
97  static inline void shootArray ( CLHEP::HepRandomEngine* anEngine,
98  const G4int size, G4double* vect );
99 
100  static void shootArray ( CLHEP::HepRandomEngine* anEngine,
101  const G4int size, G4double* vect,
102  G4double lx, G4double dx );
103 
104  // Methods using the localEngine to shoot random values, by-passing
105  // the static generator.
106 
107  inline G4double fire();
108 
109  inline G4double fire( G4double width );
110 
111  inline G4double fire( G4double a, G4double b );
112 
113  inline G4long fireInt( G4long n );
114 
115  inline G4long fireInt( G4long m, G4long n );
116 
117  inline G4int fireBit();
118 
119  void fireArray (const G4int size, G4double* vect);
120 
121  void fireArray (const G4int size, G4double* vect,
122  G4double lx, G4double dx);
123 
125  G4double operator()( G4double width );
127 
128 private:
129 
130  // ShootBits generates an integer random number,
131  // which is used by fireBit().
132  // The number is stored in randomInt and firstUnusedBit
133 
134  inline void fireBits();
135  static inline void shootBits();
136  static inline void shootBits(CLHEP::HepRandomEngine*);
137 
138  // In MSB, the most significant bit of the integer random number
139  // generated by ShootBits() is set.
140  // Note:
141  // the number of significant bits must be chosen so that
142  // - an unsigned long can hold it
143  // - and it should be less than the number of bits returned
144  // by Shoot() which are not affected by precision problems
145  // on _each_ architecture.
146  // (Aim: the random generators should be machine-independent).
147 
148  static const unsigned long MSB;
149  static const G4int MSBBits;
150  // These two are set up in RandFlat.cc and need not be saved/restored
151 
152  unsigned long randomInt;
153  unsigned long firstUnusedBit;
154  static G4ThreadLocal unsigned long staticRandomInt;
155  static G4ThreadLocal unsigned long staticFirstUnusedBit;
156 
157  CLHEP::HepRandomEngine* localEngine;
161 
162 };
163 
164 #include "G4MTRandFlat.icc"
165 
166 #endif
void fireArray(const G4int size, G4double *vect)
static const G4int MSBBits
static const unsigned long MSB
static void shootBits()
G4bool deleteEngine
long G4long
Definition: G4Types.hh:80
static G4double shoot()
#define width
static G4ThreadLocal unsigned long staticRandomInt
G4double a
Definition: TRTMaterials.hh:39
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
G4double defaultB
static G4ThreadLocal unsigned long staticFirstUnusedBit
unsigned long randomInt
virtual ~G4MTRandFlat()
G4long fireInt(G4long n)
G4double fire()
bool G4bool
Definition: G4Types.hh:79
static G4int shootBit()
const G4int n
static void shootArray(const G4int size, G4double *vect)
static G4long shootInt(G4long n)
CLHEP::HepRandomEngine * localEngine
G4MTRandFlat(CLHEP::HepRandomEngine &anEngine)
static const double m
Definition: G4SIunits.hh:110
double G4double
Definition: G4Types.hh:76
unsigned long firstUnusedBit
void fireBits()
G4double operator()()
G4double defaultA
G4int fireBit()