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