source: trunk/source/global/HEPRandom/include/G4RandomTools.hh @ 1358

Last change on this file since 1358 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 3.2 KB
Line 
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: G4RandomTools.hh,v 1.2 2008/11/07 17:54:21 gum Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30//
31// ---------------------------------------------------------------------------
32//      GEANT 4 class header file
33// ---------------------------------------------------------------------------
34// Class description:
35//
36// Utility functions
37
38// History:
39//
40// 07.11.08 - P.Gumplinger, based on implementation in G4OpBoundaryProcess
41//
42// ---------------------------------------------------------------------------
43
44#ifndef G4RANDOMTOOLS_HH
45#define G4RANDOMTOOLS_HH
46
47#include "globals.hh"
48#include "Randomize.hh"
49#include "G4RandomDirection.hh"
50
51// ---------------------------------------------------------------------------
52// Returns a random lambertian unit vector
53//
54inline G4ThreeVector G4LambertianRand(const G4ThreeVector& normal)
55{
56  G4ThreeVector vect;
57  G4double ndotv;
58
59  do
60  {
61    vect = G4RandomDirection();
62    ndotv = normal * vect;
63
64    if (ndotv < 0.0)
65    {
66      vect = -vect;
67      ndotv = -ndotv;
68    }
69
70  } while (!(G4UniformRand() < ndotv));
71
72  return vect;
73}
74
75// ---------------------------------------------------------------------------
76// Chooses a random vector within a plane given by the unit normal
77//
78inline G4ThreeVector G4PlaneVectorRand(const G4ThreeVector& normal)
79{
80  G4ThreeVector vec1 = normal.orthogonal();
81  G4ThreeVector vec2 = vec1.cross(normal);
82
83  G4double phi = twopi*G4UniformRand();
84  G4double cosphi = std::cos(phi);
85  G4double sinphi = std::sin(phi);
86
87  return cosphi * vec1 + sinphi * vec2;
88}
89
90#endif  /* G4RANDOMTOOLS_HH */
Note: See TracBrowser for help on using the repository browser.