Import Geant4 1.0.0 source tree
This commit is contained in:
@@ -5,24 +5,21 @@
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4Poisson.hh,v 1.2 1999/05/11 19:43:11 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
// $Id: G4Poisson.hh,v 1.4 1999/11/16 17:31:35 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// For information related to this code contact:
|
||||
// CERN, IT Division, ASD group
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// Description:
|
||||
// -----------
|
||||
// Class description:
|
||||
//
|
||||
// G4Poisson is the C++ implementation of the CERNLIB GPOISS algorithm
|
||||
// for the generation of Gaussian distributed random numbers. It has been
|
||||
// for the generation of Poisson distributed random numbers. It has been
|
||||
// adapted to invoke HepRandom from CLHEP for the primary engine generators.
|
||||
// GPOISS is recognized to be a faster algorithm, providing however a less
|
||||
// accurate output, than the algorithm adopted in CLHEP.
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#ifndef G4POISSON_HH
|
||||
#define G4POISSON_HH
|
||||
@@ -30,7 +27,7 @@
|
||||
#include "globals.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
G4long G4Poisson(G4double mean)
|
||||
inline G4long G4Poisson(G4double mean)
|
||||
{
|
||||
G4long number = 0;
|
||||
const G4int border = 16;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: Randomize.hh,v 1.1 1999/01/07 16:08:58 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-00-01 $
|
||||
// $Id: Randomize.hh,v 1.2 1999/11/16 17:31:35 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
#ifndef randomize_h
|
||||
#define randomize_h 1
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4RandDistributionTest.cc,v 1.3 1999/11/23 15:00:00 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
#include "Randomize.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
HepJamesRandom theJamesEngine;
|
||||
RandEngine theRandEngine;
|
||||
DRand48Engine theDRand48Engine;
|
||||
RanluxEngine theRanluxEngine(19780503,4);
|
||||
RanecuEngine theRanecuEngine;
|
||||
|
||||
void init()
|
||||
{
|
||||
char Pause;
|
||||
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << "---------------------------- Random shooting test -----------------------------" << G4endl;
|
||||
G4cout << " -------------------- " << G4endl;
|
||||
G4cout << " >>> Random Engines available <<<" << G4endl << G4endl;
|
||||
G4cout << " > HepJamesRandom (default)" << G4endl;
|
||||
G4cout << " > Rand" << G4endl;
|
||||
G4cout << " > DRand48" << G4endl;
|
||||
G4cout << " > Ranlux" << G4endl;
|
||||
G4cout << " > Ranecu" << G4endl << G4endl;
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
|
||||
} // end init()
|
||||
|
||||
|
||||
void layout()
|
||||
{
|
||||
HepFloat m=3.0;
|
||||
const HepInt size=5;
|
||||
HepDouble vect[size];
|
||||
|
||||
G4cout << " Flat ]0,1[ : " << RandFlat::shoot() << G4endl;
|
||||
G4cout << " Flat ]0,5[ : " << RandFlat::shoot(5) << G4endl;
|
||||
G4cout << " Flat ]-5,3[ : " << RandFlat::shoot(-5,3) << G4endl;
|
||||
G4cout << " Exp (m=1) : " << RandExponential::shoot() << G4endl;
|
||||
G4cout << " Exp (m=3) : " << RandExponential::shoot(3) << G4endl;
|
||||
G4cout << " Gauss (m=1) : " << RandGauss::shoot() << G4endl;
|
||||
G4cout << " Gauss (m=3,v=1) : " << RandGauss::shoot(3,1) << G4endl;
|
||||
G4cout << " Wigner(1,0.2) : " << RandBreitWigner::shoot(1,0.2) << G4endl;
|
||||
G4cout << " Wigner(1,0.2,1) : " << RandBreitWigner::shoot(1,0.2,1) << G4endl;
|
||||
G4cout << " Wigner2(1,0.2) : " << RandBreitWigner::shootM2(1,0.2) << G4endl;
|
||||
G4cout << " Wigner2(1,0.2,1) : " << RandBreitWigner::shootM2(1,0.2,1) << G4endl;
|
||||
G4cout << " IntFlat [0,99[ : " << RandFlat::shootInt(99) << G4endl;
|
||||
G4cout << " IntFlat [-99,37[ : " << RandFlat::shootInt(-99,37) << G4endl;
|
||||
G4cout << " Poisson (m=3.0) : " << RandPoisson::shoot(m) << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << " Shooting an array of 5 flat numbers ..." << G4endl << G4endl;
|
||||
RandFlat::shootArray(size,vect);
|
||||
for ( HepInt i=0; i<size; ++i )
|
||||
G4cout << " " << vect[i];
|
||||
G4cout << G4endl << G4endl;
|
||||
} // end layout()
|
||||
|
||||
void dist_layout()
|
||||
{
|
||||
HepFloat m=3.0;
|
||||
const HepInt size=5;
|
||||
HepDouble vect[size];
|
||||
char Pause;
|
||||
|
||||
HepJamesRandom aJamesEngine;
|
||||
RandEngine aRandEngine;
|
||||
DRand48Engine aDRand48Engine;
|
||||
RanluxEngine aRanluxEngine(19780503,4);
|
||||
RanecuEngine aRanecuEngine;
|
||||
|
||||
RandFlat aFlatObj(aJamesEngine);
|
||||
RandExponential anExponentialObj(aRandEngine);
|
||||
RandGauss aGaussObj(aDRand48Engine);
|
||||
RandBreitWigner aBreitObj(aRanluxEngine);
|
||||
RandPoisson aPoissonObj(aRanecuEngine);
|
||||
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << "-------------------- Shooting test on distribution objects --------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << " Flat ]0,1[ : " << aFlatObj.fire() << G4endl;
|
||||
G4cout << " Flat ]0,5[ : " << aFlatObj.fire(5) << G4endl;
|
||||
G4cout << " Flat ]-5,3[ : " << aFlatObj.fire(-5,3) << G4endl;
|
||||
G4cout << " Exp (m=1) : " << anExponentialObj.fire() << G4endl;
|
||||
G4cout << " Exp (m=3) : " << anExponentialObj.fire(3) << G4endl;
|
||||
G4cout << " Gauss (m=1) : " << aGaussObj.fire() << G4endl;
|
||||
G4cout << " Gauss (m=3,v=1) : " << aGaussObj.fire(3,1) << G4endl;
|
||||
G4cout << " Wigner(1,0.2) : " << aBreitObj.fire(1,0.2) << G4endl;
|
||||
G4cout << " Wigner(1,0.2,1) : " << aBreitObj.fire(1,0.2,1) << G4endl;
|
||||
G4cout << " Wigner2(1,0.2) : " << aBreitObj.fireM2(1,0.2) << G4endl;
|
||||
G4cout << " Wigner2(1,0.2,1) : " << aBreitObj.fireM2(1,0.2,1) << G4endl;
|
||||
G4cout << " IntFlat [0,99[ : " << aFlatObj.fireInt(99) << G4endl;
|
||||
G4cout << " IntFlat [-99,37[ : " << aFlatObj.fireInt(-99,37) << G4endl;
|
||||
G4cout << " Poisson (m=3.0) : " << aPoissonObj.fire(m) << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << " Shooting an array of 5 flat numbers ..." << G4endl << G4endl;
|
||||
aFlatObj.fireArray(size,vect);
|
||||
for ( HepInt i=0; i<size; ++i )
|
||||
G4cout << " " << vect[i];
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
} // end dist_layout()
|
||||
|
||||
void user_layout()
|
||||
{
|
||||
HepFloat m=3.0;
|
||||
const HepInt size=5;
|
||||
HepDouble vect[size];
|
||||
char sel;
|
||||
HepRandomEngine* anEngine;
|
||||
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << "-------------------- Shooting test skeeping the generator ---------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << " >>> Select a Random Engine <<<" << G4endl << G4endl;
|
||||
G4cout << " 1. HepJamesRandom (default)" << G4endl;
|
||||
G4cout << " 2. Rand" << G4endl;
|
||||
G4cout << " 3. DRand48" << G4endl;
|
||||
G4cout << " 4. Ranlux" << G4endl;
|
||||
G4cout << " 5. Ranecu" << G4endl << G4endl;
|
||||
G4cout << " > ";
|
||||
G4cin >> sel;
|
||||
while ((sel!='1')&&(sel!='2')&&(sel!='3')&&(sel!='4')&&(sel!='5')) {
|
||||
G4cout << G4endl << " >>> Choice not legal !! [1..5]<<<" << G4endl;
|
||||
G4cin >> sel;
|
||||
}
|
||||
|
||||
switch (sel) {
|
||||
case '1':
|
||||
anEngine = &theJamesEngine;
|
||||
break;
|
||||
case '2':
|
||||
anEngine = &theRandEngine;
|
||||
break;
|
||||
case '3':
|
||||
anEngine = &theDRand48Engine;
|
||||
break;
|
||||
case '4':
|
||||
anEngine = &theRanluxEngine;
|
||||
break;
|
||||
case '5':
|
||||
anEngine = &theRanecuEngine;
|
||||
break;
|
||||
|
||||
default:
|
||||
anEngine = &theJamesEngine;
|
||||
break;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
|
||||
G4cout << " Flat ]0,1[ : " << RandFlat::shoot(anEngine) << G4endl;
|
||||
G4cout << " Flat ]0,5[ : " << RandFlat::shoot(anEngine,5) << G4endl;
|
||||
G4cout << " Flat ]-5,3[ : " << RandFlat::shoot(anEngine,-5,3) << G4endl;
|
||||
G4cout << " Exp (m=1) : " << RandExponential::shoot(anEngine) << G4endl;
|
||||
G4cout << " Exp (m=3) : " << RandExponential::shoot(anEngine,3) << G4endl;
|
||||
G4cout << " Gauss (m=1) : " << RandGauss::shoot(anEngine) << G4endl;
|
||||
G4cout << " Gauss (m=3,v=1) : " << RandGauss::shoot(anEngine,3,1) << G4endl;
|
||||
G4cout << " Wigner(1,0.2) : " << RandBreitWigner::shoot(anEngine,1,0.2) << G4endl;
|
||||
G4cout << " Wigner(1,0.2,1) : " << RandBreitWigner::shoot(anEngine,1,0.2,1) << G4endl;
|
||||
G4cout << " Wigner2(1,0.2) : " << RandBreitWigner::shootM2(anEngine,1,0.2) << G4endl;
|
||||
G4cout << " Wigner2(1,0.2,1) : " << RandBreitWigner::shootM2(anEngine,1,0.2,1) << G4endl;
|
||||
G4cout << " IntFlat [0,99[ : " << RandFlat::shootInt(anEngine,99) << G4endl;
|
||||
G4cout << " IntFlat [-99,37[ : " << RandFlat::shootInt(anEngine,-99,37) << G4endl;
|
||||
G4cout << " Poisson (m=3.0) : " << RandPoisson::shoot(anEngine,m) << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << " Shooting an array of 5 flat numbers ..." << G4endl << G4endl;
|
||||
RandFlat::shootArray(anEngine,size,vect);
|
||||
for ( HepInt i=0; i<size; ++i )
|
||||
G4cout << " " << vect[i];
|
||||
G4cout << G4endl << G4endl;
|
||||
} // end layout()
|
||||
|
||||
void start_test()
|
||||
{
|
||||
char Pause;
|
||||
|
||||
G4cout << "------------------------- Test on HepJamesRandom ----------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
layout();
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
G4cout << "--------------------------- Test on RandEngine ------------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theRandEngine);
|
||||
layout();
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
G4cout << "------------------------- Test on DRand48Engine -----------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theDRand48Engine);
|
||||
layout();
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
G4cout << "--------------------- Test on RanluxEngine (luxury 4) ------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theRanluxEngine);
|
||||
layout();
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
G4cout << "-------------------------- Test on RanecuEngine ------------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theRanecuEngine);
|
||||
layout();
|
||||
dist_layout();
|
||||
user_layout();
|
||||
} // end start_test()
|
||||
|
||||
|
||||
HepInt main() {
|
||||
|
||||
init();
|
||||
start_test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4RandGlobalTest.cc,v 1.3 1999/11/23 15:00:00 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
#include "Randomize.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
RandEngine theRandEngine;
|
||||
DRand48Engine theDRand48Engine;
|
||||
RanluxEngine theRanluxEngine(19780503,4);
|
||||
RanecuEngine theRanecuEngine;
|
||||
|
||||
//======================== CHI-SQUARED TEST ============================
|
||||
|
||||
HepInt box[10], chi[8], more=1;
|
||||
HepInt prob[8] = { 1, 5, 25, 50, 75, 95, 99, 100 };
|
||||
HepFloat perc[8] = { 2.09, 3.33, 5.90, 8.34, 11.39, 16.92, 21.67, 100.0 };
|
||||
|
||||
void even_test(HepInt seq)
|
||||
{
|
||||
HepInt i,j;
|
||||
char Pause;
|
||||
|
||||
for (i=0; i<8; ++i)
|
||||
chi[i]=0;
|
||||
|
||||
G4cout << "\t\t\t --- CHI-SQUARED TEST ---" << G4endl;
|
||||
HepInt fac = HepInt(seq/100);
|
||||
|
||||
G4cout << G4endl;
|
||||
|
||||
for (HepInt k=0; k<seq; ++k) {
|
||||
for (i=0; i<10; ++i)
|
||||
box[i]=0;
|
||||
for (i=0; i<1000; ++i) {
|
||||
HepInt h = HepInt(100*G4UniformRand());
|
||||
for (j=0; j<10; ++j)
|
||||
if ((10*j <= h) && (h < 10*(j+1))) ++box[j];
|
||||
}
|
||||
HepFloat X=0;
|
||||
for (i=0; i<10; ++i) {
|
||||
HepFloat t=HepFloat(box[i]-100);
|
||||
X += t*t;
|
||||
}
|
||||
X /= 100;
|
||||
if (k == (seq%100)) {
|
||||
G4cout << "\tDistribution of a single run (rand_valuex100) ..."
|
||||
<< G4endl << G4endl;
|
||||
G4cout << "\t\t 1 10 20 30 40 50 60 70 80 90 100" << G4endl;
|
||||
G4cout << "\t\t";
|
||||
for (j=0; j<10; ++j)
|
||||
G4cout << box[j] << " ";
|
||||
G4cout << G4endl;
|
||||
G4cout << "\t\t\t Chi-squared = " << X << G4endl << G4endl;
|
||||
}
|
||||
for (i=0; i<8; ++i)
|
||||
if (X <= perc[i]) ++chi[i];
|
||||
}
|
||||
G4cout << "\tDistribution of Chi-squared for " << seq << " sequences ..."
|
||||
<< G4endl << G4endl;
|
||||
G4cout << "\t\t\t %" << "\tChi-sq " << "\tExpected" << G4endl;
|
||||
for (j=0; j<8; ++j)
|
||||
G4cout << "\t\t\tX <= " << perc[j] << ":\t" << chi[j]/fac
|
||||
<< "\t" << prob[j] << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << G4endl;
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
if (more == 1)
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
} // end even_test()
|
||||
|
||||
//====================== SERIAL CORRELATION TEST =======================
|
||||
|
||||
void corr_test(HepInt seq)
|
||||
{
|
||||
HepInt i,j;
|
||||
char Pause;
|
||||
HepDouble U;
|
||||
HepDouble UU;
|
||||
HepDouble UV;
|
||||
HepDouble corr = 0.;
|
||||
HepDouble stde = 0.;
|
||||
HepDouble mv = -1./999;
|
||||
HepDouble std = (-mv)*sqrt(HepDouble(1000*(997)/(1001)));
|
||||
HepDouble next, uni, w, mve, temp[10000];
|
||||
|
||||
G4cout << "\t\t\t--- SERIAL CORRELATION TEST ---" << G4endl << G4endl;
|
||||
|
||||
for (j=0; j<seq; ++j) {
|
||||
U = 0.; UU = 0.; UV = 0.;
|
||||
uni = G4UniformRand();
|
||||
w = uni;
|
||||
for (i=1; i<1000; ++i) {
|
||||
next = G4UniformRand();
|
||||
U += next;
|
||||
UU += next*next;
|
||||
UV += uni*next;
|
||||
uni = next;
|
||||
}
|
||||
U += w;
|
||||
UU += w*w;
|
||||
UV += uni*w;
|
||||
temp[j] = (1000*UV-U*U)/(1000*UU-U*U);
|
||||
corr += temp[j];
|
||||
}
|
||||
|
||||
mve = corr/seq;
|
||||
for (j=0; j<seq; ++j) {
|
||||
temp[j] -= mve;
|
||||
stde += temp[j]*temp[j];
|
||||
}
|
||||
stde = sqrt((1./(seq-1))*stde);
|
||||
|
||||
G4cout << "Mean value predicted : " << mv << "\t"
|
||||
<< "Standard deviation predicted: " << std << G4endl
|
||||
<< "Mean value effective : " << mve << "\t"
|
||||
<< "Standard deviation effective: " << stde << G4endl << G4endl;
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
|
||||
} // end corr_test
|
||||
|
||||
//=========================== SPATIAL TEST =============================
|
||||
|
||||
#define PI 3.1415926
|
||||
|
||||
static unsigned long twotoj[16] = { 0x1L,0x2L,0x4L,0x8L,0x10L,0x20L,0x40L,
|
||||
0x80L,0x100L,0x200L,0x400L,0x800L,
|
||||
0x1000L,0x2000L,0x4000L,0x8000L };
|
||||
|
||||
HepFloat fnc(HepFloat x1, HepFloat x2, HepFloat x3, HepFloat x4)
|
||||
{
|
||||
return (HepFloat) sqrt(x1*x1+x2*x2+x3*x3+x4*x4);
|
||||
}
|
||||
|
||||
void spat_test ()
|
||||
{
|
||||
char Pause;
|
||||
long iy[4],jpower,k;
|
||||
HepInt i,j;
|
||||
HepFloat x1,x2,x3,x4,yprob[4];
|
||||
|
||||
G4cout << "\t\t\t --- SPATIAL TEST ---" << G4endl
|
||||
<< "\tCalculates PI statistically using volume of unit n-sphere "
|
||||
<< "n = 2,3,4"
|
||||
<< G4endl << G4endl;
|
||||
for (i=1; i<=3; i++) iy[i]=0;
|
||||
G4cout << "\t\t\t# pts\tPI\t(4/3)PI\t(1/2)PI^2" << G4endl << G4endl;
|
||||
for (j=1; j<=15; j++) {
|
||||
for (k=twotoj[j-1]; k>=0; k--) {
|
||||
x1 = (HepFloat) G4UniformRand();
|
||||
x2 = (HepFloat) G4UniformRand();
|
||||
x3 = (HepFloat) G4UniformRand();
|
||||
x4 = (HepFloat) G4UniformRand();
|
||||
if (fnc(x1,x2,0.,0.) < 1.) ++iy[1];
|
||||
if (fnc(x1,x2,x3,0.) < 1.) ++iy[2];
|
||||
if (fnc(x1,x2,x3,x4) < 1.) ++iy[3];
|
||||
}
|
||||
jpower = twotoj[j];
|
||||
for (i=1; i<=3; i++)
|
||||
yprob[i] = (HepFloat) twotoj[i+1]*iy[i]/jpower;
|
||||
if ((jpower <= 32768) && (jpower != 0))
|
||||
G4cout << "\t\t\t" << jpower << "\t" << yprob[1] << "\t"
|
||||
<< yprob[2] << "\t" << yprob[3] << G4endl;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
G4cout << "\t\t\tactual" << "\t" << PI << "\t"
|
||||
<< 4.*PI/3. << "\t" << .5*PI*PI << G4endl << G4endl;
|
||||
|
||||
if (more != 99) {
|
||||
G4cout << " ----- Press <ENTER> to continue -----";
|
||||
if ( (Pause = G4cin.get()) != '\n') exit(0);
|
||||
G4cout << G4endl;
|
||||
}
|
||||
} // end spat_test()
|
||||
|
||||
//============================= GLOBAL =================================
|
||||
|
||||
void init()
|
||||
{
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << "-------------------------- Random distribution test ---------------------------" << G4endl;
|
||||
G4cout << " ------------------------ " << G4endl;
|
||||
G4cout << " >>> Random Engines available <<< " << G4endl << G4endl;
|
||||
G4cout << " > HepJamesRandom (default)" << G4endl;
|
||||
G4cout << " > Rand" << G4endl;
|
||||
G4cout << " > DRand48" << G4endl;
|
||||
G4cout << " > Ranlux" << G4endl;
|
||||
G4cout << " > Ranecu" << G4endl << G4endl;
|
||||
G4cout << " >>> Tests performed <<< " << G4endl << G4endl;
|
||||
G4cout << " > Even distribution test" << G4endl;
|
||||
G4cout << " > Serial correlation test" << G4endl;
|
||||
G4cout << " > Spatial test" << G4endl;
|
||||
G4cout << G4endl << G4endl;
|
||||
|
||||
} // end init()
|
||||
|
||||
|
||||
void layout(HepInt seq)
|
||||
{
|
||||
even_test(seq);
|
||||
corr_test(seq);
|
||||
spat_test();
|
||||
} // end layout()
|
||||
|
||||
|
||||
void start_test()
|
||||
{
|
||||
char sel;
|
||||
HepInt seq;
|
||||
|
||||
G4cout << " Select the number of random values sequences:" << G4endl;
|
||||
G4cout << "\t a - 100 sequences of 1000 random values" << G4endl;
|
||||
G4cout << "\t b - 1000 sequences of 1000 random values" << G4endl;
|
||||
G4cout << "\t c - 10000 sequences of 1000 random values" << G4endl;
|
||||
G4cout << " > ";
|
||||
G4cin >> sel;
|
||||
if ((sel!='a')&&(sel!='b')&&(sel!='c'))
|
||||
exit(0);
|
||||
switch (sel) {
|
||||
case 'a':
|
||||
seq = 100;
|
||||
break;
|
||||
case 'b':
|
||||
seq = 1000;
|
||||
break;
|
||||
case 'c':
|
||||
seq = 10000;
|
||||
break;
|
||||
default:
|
||||
seq = 100;
|
||||
break;
|
||||
}
|
||||
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << "------------------------- Test on HepJamesRandom ----------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
layout(seq);
|
||||
G4cout << G4endl << G4endl;
|
||||
more = 0;
|
||||
G4cout << "--------------------------- Test on RandEngine ------------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theRandEngine);
|
||||
layout(seq);
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << "------------------------- Test on DRand48Engine -----------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theDRand48Engine);
|
||||
layout(seq);
|
||||
G4cout << G4endl << G4endl;
|
||||
G4cout << "--------------------- Test on RanluxEngine (luxury 4) ------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theRanluxEngine);
|
||||
layout(seq);
|
||||
G4cout << G4endl << G4endl;
|
||||
more = 99;
|
||||
G4cout << "-------------------------- Test on RanecuEngine ------------------------------" << G4endl;
|
||||
G4cout << G4endl;
|
||||
HepRandom::setTheEngine(&theRanecuEngine);
|
||||
layout(seq);
|
||||
} // end start_test()
|
||||
|
||||
|
||||
HepInt main() {
|
||||
|
||||
init();
|
||||
start_test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4ShootBitTest.cc,v 1.3 1999/11/23 15:00:01 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-01-00 $
|
||||
//
|
||||
//
|
||||
|
||||
// Tests RandFlat::fireBit() member function
|
||||
// Peter Urban, 5th Sep 1996
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "g4std/iomanip.h"
|
||||
#include "Randomize.hh"
|
||||
#include "G4Timer.hh"
|
||||
|
||||
int main()
|
||||
{
|
||||
HepRandomEngine* e= HepRandom::getTheEngine();
|
||||
RandFlat r(*e);
|
||||
|
||||
const long NumTest= 10000;
|
||||
|
||||
G4cout << "Printed value: (relative frequency - probability)" << G4endl;
|
||||
G4cout << NumTest << " random numbers" << G4endl << G4endl;
|
||||
|
||||
long sum= 0;
|
||||
long i, j;
|
||||
|
||||
for (i=0; i<NumTest; i++) {
|
||||
sum+= r.fireBit();
|
||||
}
|
||||
G4cout << "fireBit " << double(sum)/NumTest-0.5 << G4endl;
|
||||
sum= 0;
|
||||
for (i=0; i<NumTest; i++) {
|
||||
sum+= r.shootBit();
|
||||
}
|
||||
G4cout << "shootBit " << double(sum)/NumTest-0.5 << G4endl;
|
||||
sum= 0;
|
||||
for (i=0; i<NumTest; i++) {
|
||||
sum+= r.shootBit(e);
|
||||
}
|
||||
G4cout << "shootBit(engine) " << double(sum)/NumTest-0.5 << G4endl;
|
||||
|
||||
|
||||
const long Num= 1000000;
|
||||
int iii; long lll;
|
||||
|
||||
G4Timer theTimer;
|
||||
G4cout << G4endl << "Performance test: " << G4endl;
|
||||
|
||||
G4cout << "shootBit() vs G4UniformRand()<0.5: ";
|
||||
theTimer.Start();
|
||||
for (i=0; i<Num; i++)
|
||||
iii = RandFlat::shootBit();
|
||||
theTimer.Stop();
|
||||
G4cout << theTimer.GetUserElapsed() << " vs ";
|
||||
theTimer.Start();
|
||||
for (i=0; i<Num; i++)
|
||||
G4UniformRand()<0.5;
|
||||
theTimer.Stop();
|
||||
G4cout << theTimer.GetUserElapsed() << G4endl << G4endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# $Id: GNUmakefile,v 1.1 1999/01/07 16:08:59 gunter Exp $
|
||||
# ----------------------------------------------------------------
|
||||
# Makes test program in environment variable G4TARGET.
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
ifndef G4TARGET
|
||||
G4TARGET := $(TESTTARGET)
|
||||
endif
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../../..
|
||||
endif
|
||||
|
||||
G4EXEC_BUILD = true
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
|
||||
# Override some variables for binmake.gmk.
|
||||
#
|
||||
INCFLAGS := -I$(G4BASE)/global/management/include \
|
||||
-I$(G4BASE)/global/HEPRandom/include
|
||||
LDLIBS := -lG4global
|
||||
|
||||
include $(G4INSTALL)/config/binmake.gmk
|
||||
Reference in New Issue
Block a user