1#include "CLHEP/Random/Randomize.h"
2#include "CLHEP/Random/defs.h"
5#include "CLHEP/Random/RandGaussQ.h"
6#include "CLHEP/Random/RandGaussT.h"
7#include "CLHEP/Random/RandPoissonQ.h"
8#include "CLHEP/Random/RandPoissonT.h"
9#include "CLHEP/Random/RandBit.h"
10#include "CLHEP/Units/PhysicalConstants.h"
35 static double cof[6] = {76.18009172947146,-86.50532032941677,
36 24.01409824083091, -1.231739572450155,
37 0.1208650973866179e-2, -0.5395239384953e-5};
41 tmp -= (x + 0.5) * std::log(tmp);
42 double ser = 1.000000000190015;
44 for ( j = 0; j <= 5; j++ ) {
48 return -tmp + std::log(2.5066282746310005*ser);
57 static double cof[6] = {76.18009172947146,-86.50532032941677,
58 24.01409824083091, -1.231739572450155,
59 0.1208650973866179e-2, -0.5395239384953e-5};
63 tmp -= (x + 0.5) * std::log(tmp);
64 double ser = 1.000000000190015;
66 for ( j = 0; j <= 5; j++ ) {
70 return -tmp + std::log(2.5066282746310005*ser/xx);
78 cout <<
"Enter 1 for RandGauss, 2 for RandGaussQ, 3 for DualRand flat: ";
83 cout <<
"\n--------------------------------------------\n";
84 cout <<
"Test of Gauss distribution speed\n\n";
87 cout <<
"Please enter an integer seed: ";
91 cout <<
"How many numbers should we generate: ";
94 cout <<
"\nInstantiating distribution utilizing DualRand engine...\n";
101 for (
int i=0; i < nNumbers; i++) {
105 cout <<
"\n Finished: sum is " << sum <<
" \n";
109 cout <<
"\n--------------------------------------------\n";
110 cout <<
"Test of RandGaussQ distribution speed\n\n";
113 cout <<
"Please enter an integer seed: ";
117 cout <<
"How many numbers should we generate: ";
120 cout <<
"\nInstantiating distribution utilizing DualRand engine...\n";
127 for (
int i=0; i < nNumbers; i++) {
131 cout <<
"\n Finished: sum is " << sum <<
" \n";
135 cout <<
"\n--------------------------------------------\n";
136 cout <<
"Test of DualRand flat speed\n\n";
139 cout <<
"Please enter an integer seed: ";
143 cout <<
"How many numbers should we generate: ";
146 cout <<
"\nInstantiating distribution utilizing DualRand engine...\n";
152 for (
int i=0; i < nNumbers; i++) {
156 cout <<
"\n Finished: sum is " << sum <<
" \n";
161 cout <<
"\nNow we will compute the first 20 gammas, using gammln:\n";
164 for (x=1; x <= 20; x+=1) {
165 cout << x << std::setprecision(20) <<
" " << std::exp(
gammln1(x))
166 <<
" " << std::exp(
gammln2(x)) <<
" difference in gammln2 = " <<
171 cout <<
"\nNow we will compute gamma of small numbers: \n";
173 for ( x=1; x > .000000001; x *= .9 ) {
174 cout << x << std::setprecision(20) <<
" " <<
175 1 - std::exp(
gammln1(x)) * std::exp(
gammln1(2-x)) * std::sin(CLHEP::pi*(1-x)) / (CLHEP::pi*(1-x)) <<
177 1 - std::exp(
gammln2(x)) * std::exp(
gammln1(2-x)) * std::sin(CLHEP::pi*(1-x)) / (CLHEP::pi*(1-x)) <<
183 cout <<
"\n--------------------------------------------\n";
184 cout <<
"Test of Poisson distribution speed\n\n";
187 cout <<
"Please enter an integer seed: ";
191 cout <<
"Please enter mu: ";
195 cout <<
"How many numbers should we generate: ";
198 cout <<
"\nInstantiating distribution utilizing DualRand engine...\n";
206 for (
int i=0; i < nNumbers; i++) {
214 cout <<
"\n Finished: sum is " << sum <<
" \n";
227 cout <<
"testing RandGaussT::shoot(100,10): " <<
229 cout <<
"testing RandGaussT::shoot(&e,100,10): " <<
232 cout <<
"testing gt.fire(): " << gt.
fire() <<
"\n";
233 cout <<
"testing gt.fire(200,2): " << gt.
fire(200,2) <<
"\n";
237 cout <<
"testing RandGaussQ::shoot(100,10): " <<
239 cout <<
"testing RandGaussQ::shoot(&e,100,10): " <<
242 cout <<
"testing qt.fire(): " << qt.
fire() <<
"\n";
243 cout <<
"testing qt.fire(200,2): " << qt.
fire(200,2) <<
"\n";
248 cout <<
"testing RandPoissonT::shoot(&e): "
250 cout <<
"testing RandPoissonT::shoot(90): " <<
252 cout <<
"testing RandPoissonT::shoot(&e,90): " <<
255 cout <<
"testing pgt.fire(): " << pgt.
fire() <<
"\n";
256 cout <<
"testing pgt.fire(20): " << pgt.
fire(20) <<
"\n";
260 cout <<
"testing RandPoissonQ::shoot(90): " <<
262 cout <<
"testing RandPoissonQ::shoot(&e,90): " <<
265 cout <<
"testing pqt.fire(): " << pqt.
fire() <<
"\n";
266 cout <<
"testing pqt.fire(20): " << pqt.
fire(20) <<
"\n";
270 cout <<
"testing RandBit::shoot(): " << RandBit::shoot() <<
"\n";
271 cout <<
"testing RandBit::shoot(&e): " << RandBit::shoot(&e) <<
"\n";
272 cout <<
"testing RandBit::shoot(10,20): " << RandBit::shoot(10,20) <<
"\n";
273 cout <<
"testing RandBit::shoot(&e,10,20): "<<
274 RandBit::shoot(&e,10,20) <<
"\n";
276 cout <<
"testing b.fire(): " << b.
fire() <<
"\n";
277 cout <<
"testing b.fire(10,20): " << b.
fire(10,20) <<
"\n";
279 cout <<
"testing RandBit::shootBit(): ";
280 for (i=0; i<40; i++) {
283 cout <<
"testing RandBit::shootBit(&e): ";
284 for (i=0; i<40; i++) {
287 cout <<
"testing RandBit::fireBit(): ";
288 for (i=0; i<40; i++) {
294 cout <<
"Timing RandFlat::shootBit(): Enter N: ";
298 for (i=0; i<N; i++) {
301 cout <<
"--------- Done.............. Sum = " << sum <<
"\n";
302 cout <<
"Timing RandBit::shootBit(): Enter N: ";
305 for (i=0; i<N; i++) {
308 cout <<
"--------- Done.............. Sum = " << sum <<
"\n";
static long shoot(double mean=1.0)
static long shoot(double mean=1.0)
double gammln2(double xx)
double gammln1(double xx)