Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4Poisson.hh,v 1.7 2004/11/12 17:38:34 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-07-00-patch-01 $ 27 // 26 // 28 // << 27 // 29 // ------------------------------------------- 28 // ------------------------------------------------------------ 30 // GEANT 4 class header file << 29 // GEANT 4 class header file 31 // ------------------------------------------- 30 // ------------------------------------------------------------ 32 // Class description: 31 // Class description: 33 // 32 // 34 // G4Poisson is the C++ implementation of the 33 // G4Poisson is the C++ implementation of the CERNLIB GPOISS algorithm 35 // for the generation of Poisson distributed r 34 // for the generation of Poisson distributed random numbers. It has been 36 // adapted to invoke HepRandom from CLHEP for 35 // adapted to invoke HepRandom from CLHEP for the primary engine generators. 37 // GPOISS is recognized to be a faster algorit 36 // GPOISS is recognized to be a faster algorithm, providing however a less 38 // accurate output, than the algorithm adopted 37 // accurate output, than the algorithm adopted in CLHEP. 39 38 40 // ------------------------------------------- 39 // ------------------------------------------------------------ 41 #ifndef G4POISSON_HH 40 #ifndef G4POISSON_HH 42 #define G4POISSON_HH 41 #define G4POISSON_HH 43 42 44 #include <CLHEP/Units/PhysicalConstants.h> << 43 #include "globals.hh" 45 << 46 #include "G4Exp.hh" << 47 #include "G4Types.hh" << 48 #include "Randomize.hh" 44 #include "Randomize.hh" 49 45 50 inline G4long G4Poisson(G4double mean) 46 inline G4long G4Poisson(G4double mean) 51 { 47 { 52 G4long number = 0; << 48 G4long number = 0; 53 const G4int border = 16; << 49 const G4int border = 16; 54 const G4double limit = 2e9; << 50 G4double limit = 2e9; 55 << 51 56 if(mean <= border) << 52 if(mean <= border) { 57 { << 53 G4double position = RandFlat::shoot(); 58 G4double position = G4UniformRand(); << 54 G4double poissonValue = std::exp(-mean); 59 G4double poissonValue = G4Exp(-mean); << 55 G4double poissonSum = poissonValue; 60 G4double poissonSum = poissonValue; << 56 61 << 57 while(poissonSum <= position) { 62 while(poissonSum <= position) << 58 number++ ; 63 { << 59 poissonValue *= mean/number; 64 ++number; << 65 poissonValue *= mean / number; << 66 poissonSum += poissonValue; 60 poissonSum += poissonValue; 67 } 61 } 68 return number; 62 return number; 69 } // the case of mean <= 16 << 63 } // the case of mean <= 16 70 64 71 G4double t = std::sqrt(-2. * std::log(G4Unif << 65 G4double value, t, y; 72 std::cos(2. * CLHEP::pi * G4Uni << 66 t = std::sqrt(-2*std::log(RandFlat::shoot())); 73 G4double value = mean + t * std::sqrt(mean) << 67 y = twopi*RandFlat::shoot(); 74 if(value < 0.) << 68 t *= std::cos(y); 75 { << 69 value = mean + t*std::sqrt(mean) + 0.5; 76 return 0; << 70 if(value <= 0) {return 0;} 77 } << 71 if(value >= limit) { return G4long(limit);} 78 return (value >= limit) ? G4long(limit) : G4 << 72 return G4long(value); 79 } 73 } 80 74 81 #endif /* G4POISSON_HH */ << 75 #endif /* G4POISSON_HH */ 82 76