Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RandomTools.hh File Reference
#include <CLHEP/Units/PhysicalConstants.h>
#include "G4RandomDirection.hh"
#include "G4ThreeVector.hh"
#include "G4TwoVector.hh"
#include "Randomize.hh"
#include "globals.hh"

Go to the source code of this file.

Functions

G4ThreeVector G4LambertianRand (const G4ThreeVector &normal)
 
G4ThreeVector G4PlaneVectorRand (const G4ThreeVector &normal)
 
G4double G4RandomRadiusInRing (G4double rmin, G4double rmax)
 
G4TwoVector G4RandomPointInEllipse (G4double a, G4double b)
 
G4TwoVector G4RandomPointOnEllipse (G4double a, G4double b)
 
G4ThreeVector G4RandomPointOnEllipsoid (G4double a, G4double b, G4double c)
 

Function Documentation

◆ G4LambertianRand()

G4ThreeVector G4LambertianRand ( const G4ThreeVector normal)
inline

Definition at line 58 of file G4RandomTools.hh.

59{
60 G4ThreeVector vect;
61 G4double ndotv;
62 G4int count = 0;
63 const G4int max_trials = 1024;
64
65 do
66 {
67 ++count;
68 vect = G4RandomDirection();
69 ndotv = normal * vect;
70
71 if(ndotv < 0.0)
72 {
73 vect = -vect;
74 ndotv = -ndotv;
75 }
76
77 } while(!(G4UniformRand() < ndotv) && (count < max_trials));
78
79 return vect;
80}
G4ThreeVector G4RandomDirection()
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4UniformRand()
Definition: Randomize.hh:52

◆ G4PlaneVectorRand()

G4ThreeVector G4PlaneVectorRand ( const G4ThreeVector normal)
inline

Definition at line 85 of file G4RandomTools.hh.

86{
87 G4ThreeVector vec1 = normal.orthogonal();
88 G4ThreeVector vec2 = vec1.cross(normal);
89
90 G4double phi = CLHEP::twopi * G4UniformRand();
91 G4double cosphi = std::cos(phi);
92 G4double sinphi = std::sin(phi);
93
94 return cosphi * vec1 + sinphi * vec2;
95}
Hep3Vector orthogonal() const
Hep3Vector cross(const Hep3Vector &) const

◆ G4RandomPointInEllipse()

G4TwoVector G4RandomPointInEllipse ( G4double  a,
G4double  b 
)
inline

Definition at line 115 of file G4RandomTools.hh.

116{
117 G4double aa = (a * a == 0) ? 0 : 1 / (a * a);
118 G4double bb = (b * b == 0) ? 0 : 1 / (b * b);
119 for(G4int i = 0; i < 1000; ++i)
120 {
121 G4double x = a * (2 * G4UniformRand() - 1);
122 G4double y = b * (2 * G4UniformRand() - 1);
123 if(x * x * aa + y * y * bb <= 1)
124 return G4TwoVector(x, y);
125 }
126 return G4TwoVector(0, 0);
127}
CLHEP::Hep2Vector G4TwoVector
Definition: G4TwoVector.hh:36

Referenced by G4Ellipsoid::GetPointOnSurface(), G4EllipticalCone::GetPointOnSurface(), and G4EllipticalTube::GetPointOnSurface().

◆ G4RandomPointOnEllipse()

G4TwoVector G4RandomPointOnEllipse ( G4double  a,
G4double  b 
)
inline

Definition at line 133 of file G4RandomTools.hh.

134{
135 G4double A = std::abs(a);
136 G4double B = std::abs(b);
137 G4double mu_max = std::max(A, B);
138
139 G4double x, y;
140 for(G4int i = 0; i < 1000; ++i)
141 {
142 G4double phi = CLHEP::twopi * G4UniformRand();
143 x = std::cos(phi);
144 y = std::sin(phi);
145 G4double mu = std::sqrt((B * x) * (B * x) + (A * y) * (A * y));
146 if(mu_max * G4UniformRand() <= mu)
147 break;
148 }
149 return G4TwoVector(A * x, B * y);
150}
double B(double temperature)
double A(double temperature)

Referenced by G4EllipticalTube::GetPointOnSurface().

◆ G4RandomPointOnEllipsoid()

G4ThreeVector G4RandomPointOnEllipsoid ( G4double  a,
G4double  b,
G4double  c 
)
inline

Definition at line 156 of file G4RandomTools.hh.

158{
159 G4double A = std::abs(a);
160 G4double B = std::abs(b);
161 G4double C = std::abs(c);
162 G4double mu_max = std::max(std::max(A * B, A * C), B * C);
163
165 for(G4int i = 0; i < 1000; ++i)
166 {
167 p = G4RandomDirection();
168 G4double xbc = p.x() * B * C;
169 G4double yac = p.y() * A * C;
170 G4double zab = p.z() * A * B;
171 G4double mu = std::sqrt(xbc * xbc + yac * yac + zab * zab);
172 if(mu_max * G4UniformRand() <= mu)
173 break;
174 }
175 return G4ThreeVector(A * p.x(), B * p.y(), C * p.z());
176}
double C(double temp)
CLHEP::Hep3Vector G4ThreeVector
double z() const
double x() const
double y() const

◆ G4RandomRadiusInRing()

G4double G4RandomRadiusInRing ( G4double  rmin,
G4double  rmax 
)
inline

Definition at line 100 of file G4RandomTools.hh.

101{
102 if(rmin == rmax)
103 {
104 return rmin;
105 }
107 return (rmin <= 0) ? rmax * std::sqrt(k)
108 : std::sqrt(k * rmax * rmax + (1. - k) * rmin * rmin);
109}

Referenced by G4EllipticalCone::GetPointOnSurface().