Changeset 850 for trunk/source/global/HEPRandom/include
- Timestamp:
- Sep 10, 2008, 5:40:37 PM (16 years ago)
- Location:
- trunk/source/global/HEPRandom/include
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/global/HEPRandom/include/G4Poisson.hh
r833 r850 26 26 // 27 27 // $Id: G4Poisson.hh,v 1.9 2006/06/29 19:00:44 gunter Exp $ 28 // GEANT4 tag $Name: $28 // GEANT4 tag $Name: HEAD $ 29 29 // 30 30 // -
trunk/source/global/HEPRandom/include/G4RandomDirection.hh
r833 r850 25 25 // 26 26 // 27 // $Id: G4RandomDirection.hh,v 1. 3 2006/06/29 19:00:47 gunterExp $28 // GEANT4 tag $Name: geant4-09-01-patch-02$27 // $Id: G4RandomDirection.hh,v 1.5 2008/03/19 17:00:20 gcosmo Exp $ 28 // GEANT4 tag $Name: HEAD $ 29 29 // 30 30 // … … 34 34 // Class description: 35 35 // 36 // Fun tion returning a unit 3-vector homogeneously randomised over 4pi36 // Function returning a unit 3-vector homogeneously randomised over 4pi 37 37 // solid angle. It can be used in any particle scattering methods 38 38 // instead of: 39 39 // z=R1, x=SQRT(1-R1*R1)*SIN(2*pi*R2), y=SQRT(1-R1*R1)*COS(2*pi*R2) 40 40 // providing more performant results. 41 42 // History: 43 // 18.03.08 V. Grichine, unit radius sphere surface based algorithm 44 // ~ 2007 M. Kossov, algorithm based on 8 Quadrants technique 45 // 41 46 // ------------------------------------------------------------ 42 47 #ifndef G4RANDOMDIR_HH … … 49 54 inline G4ThreeVector G4RandomDirection() 50 55 { 51 // Randomization in one of 8 Quadrants (x>0, y>0, z>0) 52 // 53 G4double x=G4UniformRand(), y=G4UniformRand(), z=G4UniformRand(); 54 G4double r2= x*x+y*y+z*z; 55 while(r2>1.||r2<.000001) 56 { 57 x = G4UniformRand(); y = G4UniformRand(); z = G4UniformRand(); 58 r2=x*x+y*y+z*z; 59 } 60 G4double r=std::sqrt(r2), quad=G4UniformRand(); 61 62 if(quad>0.5) 63 { 64 if(quad>0.75) 65 { 66 if(quad>0.875) return G4ThreeVector(-x/r,-y/r,-z/r); 67 else return G4ThreeVector(-x/r,-y/r, z/r); 68 } 69 else 70 { 71 if(quad>0.625) return G4ThreeVector(-x/r, y/r,-z/r); 72 else return G4ThreeVector(-x/r, y/r, z/r); 73 } 74 } 75 else 76 { 77 if(quad>0.25) 78 { 79 if(quad>0.375) return G4ThreeVector( x/r,-y/r,-z/r); 80 else return G4ThreeVector( x/r,-y/r, z/r); 81 } 82 else if(quad>0.125) return G4ThreeVector( x/r, y/r,-z/r); 83 } 84 return G4ThreeVector( x/r, y/r, z/r); 56 G4double cosTheta = 2.*G4UniformRand()-1.; 57 G4double sinTheta2 = 1. - cosTheta*cosTheta; 58 if( sinTheta2 < 0.) sinTheta2 = 0.; 59 G4double sinTheta = std::sqrt(sinTheta2); 60 G4double phi = twopi*G4UniformRand(); 61 return G4ThreeVector(sinTheta*std::cos(phi), 62 sinTheta*std::sin(phi), cosTheta).unit(); 85 63 } 86 64 -
trunk/source/global/HEPRandom/include/Randomize.hh
r833 r850 26 26 // 27 27 // $Id: Randomize.hh,v 1.7 2006/06/29 19:00:50 gunter Exp $ 28 // GEANT4 tag $Name: $28 // GEANT4 tag $Name: HEAD $ 29 29 // 30 30 #ifndef randomize_h
Note: See TracChangeset
for help on using the changeset viewer.