00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // INCL++ intra-nuclear cascade model 00027 // Pekka Kaitaniemi, CEA and Helsinki Institute of Physics 00028 // Davide Mancusi, CEA 00029 // Alain Boudard, CEA 00030 // Sylvie Leray, CEA 00031 // Joseph Cugnon, University of Liege 00032 // 00033 #define INCLXX_IN_GEANT4_MODE 1 00034 00035 #include "globals.hh" 00036 00037 /* 00038 * G4INCLRandom.hh 00039 * 00040 * \date 7 June 2009 00041 * \author Pekka Kaitaniemi 00042 */ 00043 00044 #ifndef G4INCLRANDOM_HH_ 00045 #define G4INCLRANDOM_HH_ 00046 00047 #include <iostream> 00048 #include <cmath> 00049 #include "G4INCLIRandomGenerator.hh" 00050 #include "G4INCLThreeVector.hh" 00051 #include "G4INCLGlobals.hh" 00052 #include "G4INCLLogger.hh" 00053 00054 namespace G4INCL { 00055 00056 class Random { 00057 private: 00058 Random() {} 00059 virtual ~Random() {} 00060 00061 private: 00062 static IRandomGenerator *theGenerator; 00063 00064 public: 00070 static void setGenerator(G4INCL::IRandomGenerator *aGenerator) { 00071 if(isInitialized()) { 00072 ERROR("INCL random number generator already initialized." << std::endl); 00073 } else { 00074 theGenerator = aGenerator; 00075 } 00076 }; 00077 00082 static void setSeeds(const SeedVector &sv) { 00083 theGenerator->setSeeds(sv); 00084 }; 00085 00090 static SeedVector getSeeds() { 00091 return theGenerator->getSeeds(); 00092 }; 00093 00097 static G4double shoot() {return theGenerator->flat(); }; 00098 00102 static G4double shoot0() { 00103 G4double r; 00104 while( (r=shoot()) <= 0. ) 00105 ; 00106 return r; 00107 } 00108 00112 static G4double shoot1() { 00113 G4double r; 00114 while( (r=shoot()) >= 1. ) 00115 ; 00116 return r; 00117 } 00118 00122 static G4double gauss(G4double sigma=1.); 00123 00127 static ThreeVector normVector(G4double norm=1.); 00128 00133 static ThreeVector sphereVector(G4double rmax=1.) { 00134 return normVector( rmax*Math::pow13(shoot0()) ); 00135 } 00136 00142 static ThreeVector gaussVector(G4double sigma=1.) { 00143 const G4double sigmax = sigma * Math::oneOverSqrtThree; 00144 return ThreeVector(gauss(sigmax), gauss(sigmax), gauss(sigmax)); 00145 } 00146 00150 static void deleteGenerator() { 00151 delete theGenerator; 00152 theGenerator = 0; 00153 } 00154 00158 static G4bool isInitialized() { 00159 if(theGenerator == 0) return false; 00160 return true; 00161 }; 00162 }; 00163 00164 } 00165 00166 #endif /* G4INCLRANDOM_HH_ */