Import Geant4 10.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 11:51:14 +02:00
parent e2d2f9810a
commit 286caacf06
12421 changed files with 730077 additions and 502383 deletions
+177
View File
@@ -0,0 +1,177 @@
#include "CLHEP/Random/DoubConv.h"
#include "CLHEP/Random/RandExpZiggurat.h"
#include <iostream>
#include <cmath> // for std::log()
namespace CLHEP {
bool RandExpZiggurat::ziggurat_is_init=RandExpZiggurat::ziggurat_init();
unsigned long RandExpZiggurat::kn[128], RandExpZiggurat::ke[256];
float RandExpZiggurat::wn[128],RandExpZiggurat::fn[128],RandExpZiggurat::we[256],RandExpZiggurat::fe[256];
std::string RandExpZiggurat::name() const {return "RandExpZiggurat";}
HepRandomEngine & RandExpZiggurat::engine() {return *localEngine;}
RandExpZiggurat::~RandExpZiggurat() {
if ( deleteEngine ) delete localEngine;
}
RandExpZiggurat::RandExpZiggurat(const RandExpZiggurat& right) : HepRandom(right),defaultMean(right.defaultMean)
{
if(!ziggurat_is_init) ziggurat_init();
}
double RandExpZiggurat::operator()()
{
return fire( defaultMean );
}
void RandExpZiggurat::shootArray( const int size, float* vect, float mean )
{
for (int i=0; i<size; ++i) vect[i] = shoot(mean);
}
void RandExpZiggurat::shootArray( const int size, double* vect, double mean )
{
for (int i=0; i<size; ++i) vect[i] = shoot(mean);
}
void RandExpZiggurat::shootArray(HepRandomEngine* anEngine, const int size, float* vect, float mean )
{
for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
}
void RandExpZiggurat::shootArray(HepRandomEngine* anEngine, const int size, double* vect, double mean )
{
for (int i=0; i<size; ++i) vect[i] = shoot(anEngine, mean);
}
void RandExpZiggurat::fireArray( const int size, float* vect)
{
for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
}
void RandExpZiggurat::fireArray( const int size, double* vect)
{
for (int i=0; i<size; ++i) vect[i] = fire( defaultMean );
}
void RandExpZiggurat::fireArray( const int size, float* vect, float mean )
{
for (int i=0; i<size; ++i) vect[i] = fire( mean );
}
void RandExpZiggurat::fireArray( const int size, double* vect, double mean )
{
for (int i=0; i<size; ++i) vect[i] = fire( mean );
}
std::ostream & RandExpZiggurat::put ( std::ostream & os ) const {
int pr=os.precision(20);
std::vector<unsigned long> t(2);
os << " " << name() << "\n";
os << "Uvec" << "\n";
t = DoubConv::dto2longs(defaultMean);
os << defaultMean << " " << t[0] << " " << t[1] << "\n";
os.precision(pr);
return os;
#ifdef REMOVED
int pr=os.precision(20);
os << " " << name() << "\n";
os << defaultMean << "\n";
os.precision(pr);
return os;
#endif
}
std::istream & RandExpZiggurat::get ( std::istream & is ) {
std::string inName;
is >> inName;
if (inName != name()) {
is.clear(std::ios::badbit | is.rdstate());
std::cerr << "Mismatch when expecting to read state of a "
<< name() << " distribution\n"
<< "Name found was " << inName
<< "\nistream is left in the badbit state\n";
return is;
}
if (possibleKeywordInput(is, "Uvec", defaultMean)) {
std::vector<unsigned long> t(2);
is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t);
return is;
}
// is >> defaultMean encompassed by possibleKeywordInput
return is;
}
float RandExpZiggurat::ziggurat_efix(unsigned long jz,HepRandomEngine* anEngine)
{
unsigned long iz=jz&255;
float x;
for(;;)
{
if(iz==0) return (7.69711-std::log(ziggurat_UNI(anEngine))); /* iz==0 */
x=jz*we[iz];
if( fe[iz]+ziggurat_UNI(anEngine)*(fe[iz-1]-fe[iz]) < std::exp(-x) ) return (x);
/* initiate, try to exit for(;;) loop */
jz=ziggurat_SHR3(anEngine);
iz=(jz&255);
if(jz<ke[iz]) return (jz*we[iz]);
}
}
bool RandExpZiggurat::ziggurat_init()
{
const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
int i;
/* Set up tables for RNOR */
q=vn/std::exp(-.5*dn*dn);
kn[0]=(unsigned long)((dn/q)*rzm1);
kn[1]=0;
wn[0]=q/rzm1;
wn[127]=dn/rzm1;
fn[0]=1.;
fn[127]=std::exp(-.5*dn*dn);
for(i=126;i>=1;i--) {
dn=std::sqrt(-2.*std::log(vn/dn+std::exp(-.5*dn*dn)));
kn[i+1]=(unsigned long)((dn/tn)*rzm1);
tn=dn;
fn[i]=std::exp(-.5*dn*dn);
wn[i]=dn/rzm1;
}
/* Set up tables for REXP */
q = ve/std::exp(-de);
ke[0]=(unsigned long)((de/q)*rzm2);
ke[1]=0;
we[0]=q/rzm2;
we[255]=de/rzm2;
fe[0]=1.;
fe[255]=std::exp(-de);
for(i=254;i>=1;i--) {
de=-std::log(ve/de+std::exp(-de));
ke[i+1]= (unsigned long)((de/te)*rzm2);
te=de;
fe[i]=std::exp(-de);
we[i]=de/rzm2;
}
ziggurat_is_init=true;
return true;
}
} // namespace CLHEP
+188
View File
@@ -0,0 +1,188 @@
#include "CLHEP/Random/RandGaussZiggurat.h"
#include "CLHEP/Units/PhysicalConstants.h"
#include <iostream>
#include <cmath> // for std::log()
namespace CLHEP {
bool RandGaussZiggurat::ziggurat_is_init=RandGaussZiggurat::ziggurat_init();
//bool RandGaussZiggurat::ziggurat_is_init=false;
unsigned long RandGaussZiggurat::kn[128], RandGaussZiggurat::ke[256];
float RandGaussZiggurat::wn[128],RandGaussZiggurat::fn[128],RandGaussZiggurat::we[256],RandGaussZiggurat::fe[256];
HepRandomEngine & RandGaussZiggurat::engine() {return RandGauss::engine();}
RandGaussZiggurat::~RandGaussZiggurat() {
}
std::string RandGaussZiggurat::name() const
{
return "RandGaussZiggurat";
}
bool RandGaussZiggurat::ziggurat_init()
{
const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
int i;
/* Set up tables for RNOR */
q=vn/std::exp(-.5*dn*dn);
kn[0]=(unsigned long)((dn/q)*rzm1);
kn[1]=0;
wn[0]=q/rzm1;
wn[127]=dn/rzm1;
fn[0]=1.;
fn[127]=std::exp(-.5*dn*dn);
for(i=126;i>=1;i--) {
dn=std::sqrt(-2.*std::log(vn/dn+std::exp(-.5*dn*dn)));
kn[i+1]=(unsigned long)((dn/tn)*rzm1);
tn=dn;
fn[i]=std::exp(-.5*dn*dn);
wn[i]=dn/rzm1;
}
/* Set up tables for REXP */
q = ve/std::exp(-de);
ke[0]=(unsigned long)((de/q)*rzm2);
ke[1]=0;
we[0]=q/rzm2;
we[255]=de/rzm2;
fe[0]=1.;
fe[255]=std::exp(-de);
for(i=254;i>=1;i--) {
de=-std::log(ve/de+std::exp(-de));
ke[i+1]= (unsigned long)((de/te)*rzm2);
te=de;
fe[i]=std::exp(-de);
we[i]=de/rzm2;
}
ziggurat_is_init=true;
//std::cout<<"Done RandGaussZiggurat::ziggurat_init()"<<std::endl;
return true;
}
float RandGaussZiggurat::ziggurat_nfix(long hz,HepRandomEngine* anEngine)
{
const float r = 3.442620f; /* The start of the right tail */
float x, y;
unsigned long iz=hz&127;
for(;;)
{
x=hz*wn[iz]; /* iz==0, handles the base strip */
if(iz==0) {
do {
/* change to (1.0 - UNI) as argument to std::log(), because CLHEP generates [0,1),
while the original UNI generates (0,1] */
x=-std::log(1.0 - ziggurat_UNI(anEngine))*0.2904764; /* .2904764 is 1/r */
y=-std::log(1.0 - ziggurat_UNI(anEngine));
} while(y+y<x*x);
return (hz>0)? r+x : -r-x;
}
/* iz>0, handle the wedges of other strips */
if( fn[iz]+(1.0 - ziggurat_UNI(anEngine))*(fn[iz-1]-fn[iz]) < std::exp(-.5*x*x) ) return x;
/* initiate, try to exit for(;;) for loop*/
hz=(signed)ziggurat_SHR3(anEngine);
iz=hz&127;
if((unsigned long)abs(hz)<kn[iz]) return (hz*wn[iz]);
}
}
double RandGaussZiggurat::operator()() {
return ziggurat_RNOR(localEngine.get()) * defaultStdDev + defaultMean;
}
double RandGaussZiggurat::operator()( double mean, double stdDev ) {
return ziggurat_RNOR(localEngine.get()) * stdDev + mean;
}
void RandGaussZiggurat::shootArray( const int size, float* vect, float mean, float stdDev )
{
for (int i=0; i<size; ++i) {
vect[i] = shoot(mean,stdDev);
}
}
void RandGaussZiggurat::shootArray( const int size, double* vect, double mean, double stdDev )
{
for (int i=0; i<size; ++i) {
vect[i] = shoot(mean,stdDev);
}
}
void RandGaussZiggurat::shootArray( HepRandomEngine* anEngine, const int size, float* vect, float mean, float stdDev )
{
for (int i=0; i<size; ++i) {
vect[i] = shoot(anEngine,mean,stdDev);
}
}
void RandGaussZiggurat::shootArray( HepRandomEngine* anEngine, const int size, double* vect, double mean, double stdDev )
{
for (int i=0; i<size; ++i) {
vect[i] = shoot(anEngine,mean,stdDev);
}
}
void RandGaussZiggurat::fireArray( const int size, float* vect)
{
for (int i=0; i<size; ++i) {
vect[i] = fire( defaultMean, defaultStdDev );
}
}
void RandGaussZiggurat::fireArray( const int size, double* vect)
{
for (int i=0; i<size; ++i) {
vect[i] = fire( defaultMean, defaultStdDev );
}
}
void RandGaussZiggurat::fireArray( const int size, float* vect, float mean, float stdDev )
{
for (int i=0; i<size; ++i) {
vect[i] = fire( mean, stdDev );
}
}
void RandGaussZiggurat::fireArray( const int size, double* vect, double mean, double stdDev )
{
for (int i=0; i<size; ++i) {
vect[i] = fire( mean, stdDev );
}
}
std::ostream & RandGaussZiggurat::put ( std::ostream & os ) const {
int pr=os.precision(20);
os << " " << name() << "\n";
RandGauss::put(os);
os.precision(pr);
return os;
}
std::istream & RandGaussZiggurat::get ( std::istream & is ) {
std::string inName;
is >> inName;
if (inName != name()) {
is.clear(std::ios::badbit | is.rdstate());
std::cerr << "Mismatch when expecting to read state of a "
<< name() << " distribution\n"
<< "Name found was " << inName
<< "\nistream is left in the badbit state\n";
return is;
}
RandGauss::get(is);
return is;
}
} // namespace CLHEP
+13
View File
@@ -210,17 +210,30 @@ void Evaluator::setSystemOfUnits(double meter,
const double Bq = 1./s;
setVariable("becquerel", Bq);
setVariable("Bq", Bq);
setVariable("kilobecquerel", kilo_ * Bq);
setVariable("kBq", kilo_ * Bq);
setVariable("megabecquerel", mega_ * Bq);
setVariable("MBq", mega_ * Bq);
setVariable("gigabecquerel", giga_ * Bq);
setVariable("GBq", giga_ * Bq);
// --- honors Pierre Curie (1859-1906) of France
// and Marie Sklodowska Curie (1867-1934) of Poland
setVariable("curie", 3.7e+10 * Bq);
setVariable("Ci", 3.7e+10 * Bq);
setVariable("millicurie", milli_ * 3.7e+10 * Bq);
setVariable("mCi", milli_ * 3.7e+10 * Bq);
setVariable("microcurie", micro_ * 3.7e+10 * Bq);
setVariable("uCi", micro_ * 3.7e+10 * Bq);
// Specific energy
// --- honors Louis Harold Gray, F.R.S. (1905-1965) of England
const double Gy = J / kg;
setVariable("gray", Gy);
setVariable("Gy", Gy);
setVariable("kilogray", kilo_ * Gy);
setVariable("milligray", milli_ * Gy);
setVariable("microgray", micro_ * Gy);
// Dose equivalent
const double Sv = J / kg;