|
||||
File indexing completed on 2025-01-18 09:59:01
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // 0027 // 0028 // 0029 // ------------------------------------------------------------ 0030 // GEANT 4 class header file 0031 // ------------------------------------------------------------ 0032 // Class description: 0033 // 0034 // Function returning a unit 3-vector homogeneously randomised over 4pi 0035 // solid angle. It can be used in any particle scattering methods 0036 // instead of: 0037 // z=R1, x=SQRT(1-R1*R1)*SIN(2*pi*R2), y=SQRT(1-R1*R1)*COS(2*pi*R2) 0038 // providing more performant results. 0039 0040 // History: 0041 // 19.10.17 E. Tcherniaev, use of G.Marsaglia (1972) method 0042 // 06.04.17 E. Tcherniaev, added G4RandomDirection(cosTheta) 0043 // 15.03.16 E. Tcherniaev, removed unnecessary if and unit() 0044 // 18.03.08 V. Grichine, unit radius sphere surface based algorithm 0045 // ~ 2007 M. Kossov, algorithm based on 8 Quadrants technique 0046 // 0047 // ------------------------------------------------------------ 0048 #ifndef G4RANDOMDIR_HH 0049 #define G4RANDOMDIR_HH 0050 0051 #include <CLHEP/Units/PhysicalConstants.h> 0052 0053 #include "G4ThreeVector.hh" 0054 #include "Randomize.hh" 0055 #include "globals.hh" 0056 0057 // G.Marsaglia (1972) method 0058 inline G4ThreeVector G4RandomDirection() 0059 { 0060 G4double u, v, b; 0061 do 0062 { 0063 u = 2. * G4UniformRand() - 1.; 0064 v = 2. * G4UniformRand() - 1.; 0065 b = u * u + v * v; 0066 } while(b > 1.); 0067 G4double a = 2. * std::sqrt(1. - b); 0068 return G4ThreeVector(a * u, a * v, 2. * b - 1.); 0069 } 0070 0071 inline G4ThreeVector G4RandomDirection(G4double cosTheta) 0072 { 0073 G4double z = (1. - cosTheta) * G4UniformRand() + cosTheta; 0074 G4double rho = std::sqrt((1. + z) * (1. - z)); 0075 G4double phi = CLHEP::twopi * G4UniformRand(); 0076 return G4ThreeVector(rho * std::cos(phi), rho * std::sin(phi), z); 0077 } 0078 0079 #endif /* G4RANDOMDIR_HH */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |