Geant4
9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RandomTools.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
//
30
// ---------------------------------------------------------------------------
31
// GEANT 4 class header file
32
// ---------------------------------------------------------------------------
33
// Class description:
34
//
35
// Utility functions
36
37
// History:
38
//
39
// 07.11.08 - P.Gumplinger, based on implementation in G4OpBoundaryProcess
40
//
41
// ---------------------------------------------------------------------------
42
43
#ifndef G4RANDOMTOOLS_HH
44
#define G4RANDOMTOOLS_HH
45
46
#include <
CLHEP/Units/PhysicalConstants.h
>
47
48
#include "
globals.hh
"
49
#include "
Randomize.hh
"
50
#include "
G4RandomDirection.hh
"
51
52
// ---------------------------------------------------------------------------
53
// Returns a random lambertian unit vector
54
//
55
inline
G4ThreeVector
G4LambertianRand
(
const
G4ThreeVector
& normal)
56
{
57
G4ThreeVector
vect;
58
G4double
ndotv;
59
60
do
61
{
62
vect =
G4RandomDirection
();
63
ndotv = normal * vect;
64
65
if
(ndotv < 0.0)
66
{
67
vect = -vect;
68
ndotv = -ndotv;
69
}
70
71
}
while
(!(
G4UniformRand
() < ndotv));
72
73
return
vect;
74
}
75
76
// ---------------------------------------------------------------------------
77
// Chooses a random vector within a plane given by the unit normal
78
//
79
inline
G4ThreeVector
G4PlaneVectorRand
(
const
G4ThreeVector
& normal)
80
{
81
G4ThreeVector
vec1 = normal.
orthogonal
();
82
G4ThreeVector
vec2 = vec1.
cross
(normal);
83
84
G4double
phi = CLHEP::twopi*
G4UniformRand
();
85
G4double
cosphi = std::cos(phi);
86
G4double
sinphi = std::sin(phi);
87
88
return
cosphi * vec1 + sinphi * vec2;
89
}
90
91
#endif
/* G4RANDOMTOOLS_HH */
G4RandomDirection.hh
G4RandomDirection
G4ThreeVector G4RandomDirection()
Definition:
G4RandomDirection.hh:55
G4LambertianRand
G4ThreeVector G4LambertianRand(const G4ThreeVector &normal)
Definition:
G4RandomTools.hh:55
G4PlaneVectorRand
G4ThreeVector G4PlaneVectorRand(const G4ThreeVector &normal)
Definition:
G4RandomTools.hh:79
G4double
double G4double
Definition:
G4Types.hh:64
PhysicalConstants.h
Randomize.hh
G4UniformRand
#define G4UniformRand()
Definition:
Randomize.hh:53
CLHEP::Hep3Vector
Definition:
ThreeVector.h:41
CLHEP::Hep3Vector::orthogonal
Hep3Vector orthogonal() const
CLHEP::Hep3Vector::cross
Hep3Vector cross(const Hep3Vector &) const
globals.hh
geant4-v9.6.0
source
global
HEPRandom
include
G4RandomTools.hh
Generated by
1.9.6