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

Go to the source code of this file.

Functions

G4ThreeVector G4RandomDirection ()
 

Function Documentation

G4ThreeVector G4RandomDirection ( )
inline

Definition at line 55 of file G4RandomDirection.hh.

References G4UniformRand, and CLHEP::Hep3Vector::unit().

Referenced by G4MuMinusCapturePrecompound::ApplyYourself(), G4MuonMinusBoundDecay::ApplyYourself(), XPhononStackingAction::ClassifyNewTrack(), G4PionDecayMakeSpin::DaughterPolarization(), export_G4RandomDirection(), G4LambertianRand(), XPrimaryGeneratorAction::GeneratePrimaries(), G4PhononScattering::PostStepDoIt(), G4eeTo3PiModel::SampleSecondaries(), G4HeatedKleinNishinaCompton::SampleSecondaries(), and XPrimaryGeneratorAction::XPrimaryGeneratorAction().

56 {
57  G4double cosTheta = 2.*G4UniformRand()-1.;
58  G4double sinTheta2 = 1. - cosTheta*cosTheta;
59  if( sinTheta2 < 0.) sinTheta2 = 0.;
60  G4double sinTheta = std::sqrt(sinTheta2);
61  G4double phi = CLHEP::twopi*G4UniformRand();
62  return G4ThreeVector(sinTheta*std::cos(phi),
63  sinTheta*std::sin(phi), cosTheta).unit();
64 }
CLHEP::Hep3Vector G4ThreeVector
#define G4UniformRand()
Definition: Randomize.hh:87
Hep3Vector unit() const
double G4double
Definition: G4Types.hh:76