File indexing completed on 2026-04-10 07:50:32
0001 #pragma once
0002
0003 #include <CLHEP/Units/PhysicalConstants.h>
0004
0005 #include "globals.hh"
0006 #include "Randomize.hh"
0007 #include "G4ThreeVector.hh"
0008
0009 #ifdef DEBUG_TAG
0010 #include "SEvt.hh"
0011 #include "U4Stack.h"
0012 #endif
0013
0014
0015
0016 inline G4ThreeVector U4RandomDirection()
0017 {
0018 G4double u0, u1 ;
0019
0020 G4double u, v, b;
0021 do {
0022
0023 u0 = G4UniformRand() ;
0024 #ifndef PRODUCTION
0025 #ifdef DEBUG_TAG
0026 SEvt::AddTag(1, U4Stack_RandomDirection, u0 );
0027 #endif
0028 #endif
0029 u1 = G4UniformRand() ;
0030 #ifndef PRODUCTION
0031 #ifdef DEBUG_TAG
0032 SEvt::AddTag(1, U4Stack_RandomDirection, u1 );
0033 #endif
0034 #endif
0035 u = 2.*u0 - 1.;
0036 v = 2.*u1 - 1.;
0037 b = u*u + v*v;
0038 } while (b > 1.);
0039 G4double a = 2.*std::sqrt(1. - b);
0040 return G4ThreeVector(a*u, a*v, 2.*b - 1.);
0041 }
0042
0043