Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
G4RandomTools.hh File Reference
#include <CLHEP/Units/PhysicalConstants.h>
#include "globals.hh"
#include "Randomize.hh"
#include "G4RandomDirection.hh"

Go to the source code of this file.

Functions

G4ThreeVector G4LambertianRand (const G4ThreeVector &normal)
 
G4ThreeVector G4PlaneVectorRand (const G4ThreeVector &normal)
 

Function Documentation

G4ThreeVector G4LambertianRand ( const G4ThreeVector normal)
inline

Definition at line 55 of file G4RandomTools.hh.

References G4RandomDirection(), and G4UniformRand.

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 }
G4ThreeVector G4RandomDirection()
#define G4UniformRand()
Definition: Randomize.hh:87
double G4double
Definition: G4Types.hh:76
G4ThreeVector G4PlaneVectorRand ( const G4ThreeVector normal)
inline

Definition at line 79 of file G4RandomTools.hh.

References CLHEP::Hep3Vector::cross(), G4UniformRand, and CLHEP::Hep3Vector::orthogonal().

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 }
#define G4UniformRand()
Definition: Randomize.hh:87
Hep3Vector orthogonal() const
Hep3Vector cross(const Hep3Vector &) const
double G4double
Definition: G4Types.hh:76