Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4INCLRandom.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// INCL++ intra-nuclear cascade model
27// Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28// Davide Mancusi, CEA
29// Alain Boudard, CEA
30// Sylvie Leray, CEA
31// Joseph Cugnon, University of Liege
32//
33// INCL++ revision: v5.1.8
34//
35#define INCLXX_IN_GEANT4_MODE 1
36
37#include "globals.hh"
38
39/*
40 * G4INCLRandom.hh
41 *
42 * \date 7 June 2009
43 * \author Pekka Kaitaniemi
44 */
45
46#ifndef G4INCLRANDOM_HH_
47#define G4INCLRANDOM_HH_
48
49#include <iostream>
50#include <cmath>
52#include "G4INCLThreeVector.hh"
53#include "G4INCLGlobals.hh"
54#include "G4INCLLogger.hh"
55
56namespace G4INCL {
57
58 class Random {
59 private:
60 Random() {}
61 virtual ~Random() {}
62
63 private:
64 static IRandomGenerator *theGenerator;
65
66 public:
67 /**
68 * Set the random number generator implementation to be used globally by INCL.
69 *
70 * @see G4INCL::IRandomGenerator
71 */
72 static void setGenerator(G4INCL::IRandomGenerator *aGenerator) {
73 if(isInitialized()) {
74 ERROR("INCL random number generator already initialized." << std::endl);
75 } else {
76 theGenerator = aGenerator;
77 }
78 };
79
80 /**
81 * Set the seeds of the current generator.
82 *
83 */
84 static void setSeeds(const SeedVector &sv) {
85 theGenerator->setSeeds(sv);
86 };
87
88 /**
89 * Get the seeds of the current generator.
90 *
91 */
93 return theGenerator->getSeeds();
94 };
95
96 /**
97 * Generate flat distribution of random numbers.
98 */
99 static G4double shoot() {return theGenerator->flat(); };
100
101 /**
102 * Return a random number in the ]0,1] interval
103 */
104 static G4double shoot0() {
105 G4double r;
106 while( (r=shoot()) <= 0. )
107 ;
108 return r;
109 }
110
111 /**
112 * Return a random number in the [0,1[ interval
113 */
114 static G4double shoot1() {
115 G4double r;
116 while( (r=shoot()) >= 1. )
117 ;
118 return r;
119 }
120
121 /**
122 * Generate random numbers using gaussian distribution.
123 */
124 static G4double gauss(G4double sigma=1.);
125
126 /**
127 * Generate isotropically-distributed ThreeVectors of given norm.
128 */
129 static ThreeVector normVector(G4double norm=1.);
130
131 /**
132 * Generate ThreeVectors that are uniformly distributed in a sphere of
133 * radius rmax.
134 */
136 return normVector( rmax*Math::pow13(shoot0()) );
137 }
138
139 /** \brief Generate Gaussianly-distributed ThreeVectors
140 *
141 * Generate ThreeVectors that are distributed as a three-dimensional
142 * Gaussian of the given sigma.
143 */
145 const G4double sigmax = sigma * Math::oneOverSqrtThree;
146 return ThreeVector(gauss(sigmax), gauss(sigmax), gauss(sigmax));
147 }
148
149 /**
150 * Delete the generator
151 */
152 static void deleteGenerator() {
153 delete theGenerator;
154 theGenerator = 0;
155 }
156
157 /**
158 * Check if the generator is initialized.
159 */
161 if(theGenerator == 0) return false;
162 return true;
163 };
164 };
165
166}
167
168#endif /* G4INCLRANDOM_HH_ */
#define ERROR(x)
double G4double
Definition: G4Types.hh:64
bool G4bool
Definition: G4Types.hh:67
shared_ptr< HepRandom > theGenerator
Definition: Random.cc:59
static ThreeVector normVector(G4double norm=1.)
Definition: G4INCLRandom.cc:73
static G4double shoot()
Definition: G4INCLRandom.hh:99
static G4double gauss(G4double sigma=1.)
Definition: G4INCLRandom.cc:53
static void setSeeds(const SeedVector &sv)
Definition: G4INCLRandom.hh:84
static ThreeVector sphereVector(G4double rmax=1.)
static void setGenerator(G4INCL::IRandomGenerator *aGenerator)
Definition: G4INCLRandom.hh:72
static SeedVector getSeeds()
Definition: G4INCLRandom.hh:92
static G4double shoot1()
static void deleteGenerator()
static ThreeVector gaussVector(G4double sigma=1.)
Generate Gaussianly-distributed ThreeVectors.
static G4bool isInitialized()
static G4double shoot0()
G4double pow13(G4double x)
const G4double oneOverSqrtThree
std::vector< long > SeedVector