35 #include "CLHEP/Random/RandGauss.h" 
   36 #include "CLHEP/Random/DoubConv.h" 
   46 CLHEP_THREAD_LOCAL 
bool RandGauss::set_st = 
false;
 
   47 CLHEP_THREAD_LOCAL 
double RandGauss::nextGauss_st = 0.0;
 
   49 RandGauss::~RandGauss() {
 
   52 double RandGauss::operator()() {
 
   53   return fire( defaultMean, defaultStdDev );
 
   56 double RandGauss::operator()( 
double mean, 
double stdDev ) {
 
   57   return fire( mean, stdDev );
 
   74   HepRandomEngine* anEngine = HepRandom::getTheEngine();
 
   77     v1 = 2.0 * anEngine->flat() - 1.0;
 
   78     v2 = 2.0 * anEngine->flat() - 1.0;
 
   82   fac = std::sqrt(-2.0*std::log(r)/r);
 
   89 void RandGauss::shootArray( 
const int size, 
double* vect,
 
   90                             double mean, 
double stdDev )
 
   92   for( 
double* v = vect; v != vect + size; ++v )
 
   93     *v = 
shoot(mean,stdDev);
 
  107   double v1,v2,
fac,val;
 
  110     v1 = 2.0 * anEngine->flat() - 1.0;
 
  111     v2 = 2.0 * anEngine->flat() - 1.0;
 
  115   fac = std::sqrt( -2.0*std::log(r)/r);
 
  122 void RandGauss::shootArray( HepRandomEngine* anEngine,
 
  123                             const int size, 
double* vect,
 
  124                             double mean, 
double stdDev )
 
  126   for( 
double* v = vect; v != vect + size; ++v )
 
  127     *v = 
shoot(anEngine,mean,stdDev);
 
  141   double v1,v2,
fac,val;
 
  144     v1 = 2.0 * localEngine->flat() - 1.0;
 
  145     v2 = 2.0 * localEngine->flat() - 1.0;
 
  149   fac = std::sqrt(-2.0*std::log(r)/r);
 
  156 void RandGauss::fireArray( 
const int size, 
double* vect)
 
  158   for( 
double* v = vect; v != vect + size; ++v )
 
  159     *v = fire( defaultMean, defaultStdDev );
 
  162 void RandGauss::fireArray( 
const int size, 
double* vect,
 
  163                            double mean, 
double stdDev )
 
  165   for( 
double* v = vect; v != vect + size; ++v )
 
  166     *v = fire( mean, stdDev );
 
  169 void RandGauss::saveEngineStatus ( 
const char filename[] ) {
 
  172   getTheEngine()->saveStatus( filename );
 
  176   std::ofstream outfile ( filename, std::ios::app );
 
  179     std::vector<unsigned long> t(2);
 
  180     t = DoubConv::dto2longs(getVal());
 
  181     outfile << 
"RANDGAUSS CACHED_GAUSSIAN: Uvec "  
  182             << getVal() << 
" " << t[0] << 
" " << t[1] << 
"\n";
 
  184     outfile << 
"RANDGAUSS NO_CACHED_GAUSSIAN: 0 \n" ;
 
  189 void RandGauss::restoreEngineStatus( 
const char filename[] ) {
 
  192   getTheEngine()->restoreStatus( filename );
 
  196   std::ifstream infile ( filename, std::ios::in );
 
  199   char inputword[] = 
"NO_KEYWORD    "; 
 
  203     if (strcmp(inputword,
"RANDGAUSS")==0) 
break;
 
  204     if (infile.eof()) 
break;
 
  212   if (strcmp(inputword,
"RANDGAUSS")==0) {
 
  216     if (strcmp(setword,
"CACHED_GAUSSIAN:") ==0) {
 
  217       if (possibleKeywordInput(infile, 
"Uvec", nextGauss_st)) {
 
  218         std::vector<unsigned long> t(2);
 
  219         infile >> nextGauss_st >> t[0] >> t[1]; 
 
  220         nextGauss_st = DoubConv::longs2double(t); 
 
  226       infile >> nextGauss_st; 
 
  236 std::ostream & RandGauss::put ( std::ostream & os )
 const {
 
  237   os << 
name() << 
"\n";
 
  238   int prec = os.precision(20);
 
  239   std::vector<unsigned long> t(2);
 
  241   t = DoubConv::dto2longs(defaultMean);
 
  242   os << defaultMean << 
" " << t[0] << 
" " << t[1] << 
"\n";
 
  243   t = DoubConv::dto2longs(defaultStdDev);
 
  244   os << defaultStdDev << 
" " << t[0] << 
" " << t[1] << 
"\n";
 
  246     t = DoubConv::dto2longs(nextGauss);
 
  247     os << 
"nextGauss " << nextGauss << 
" " << t[0] << 
" " << t[1] << 
"\n";
 
  249     os << 
"no_cached_nextGauss \n";
 
  255 std::istream & RandGauss::get ( std::istream & is ) {
 
  258   if (inName != 
name()) {
 
  259     is.clear(std::ios::badbit | is.rdstate());
 
  260     std::cerr << 
"Mismatch when expecting to read state of a " 
  261               << 
name() << 
" distribution\n" 
  262               << 
"Name found was " << inName
 
  263               << 
"\nistream is left in the badbit state\n";
 
  268   if (possibleKeywordInput(is, 
"Uvec", c1)) {
 
  269     std::vector<unsigned long> t(2);
 
  270     is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t); 
 
  271     is >> defaultStdDev>>t[0]>>t[1]; defaultStdDev = DoubConv::longs2double(t); 
 
  275     if (ng == 
"nextGauss") {
 
  276       is >> nextGauss >> t[0] >> t[1]; nextGauss = DoubConv::longs2double(t);
 
  282   is >> defaultMean >> c2 >> defaultStdDev;
 
  283   if ( (!is) || (c1 != 
"Mean:") || (c2 != 
"Sigma:") ) {
 
  284     std::cerr << 
"i/o problem while expecting to read state of a " 
  285               << 
name() << 
" distribution\n" 
  286               << 
"default mean and/or sigma could not be read\n";
 
  289   is >> c1 >> c2 >> nextGauss;
 
  290   if ( (!is) || (c1 != 
"RANDGAUSS") ) {
 
  291     is.clear(std::ios::badbit | is.rdstate());
 
  292     std::cerr << 
"Failure when reading caching state of RandGauss\n";
 
  295   if (c2 == 
"CACHED_GAUSSIAN:") {
 
  297   } 
else if (c2 == 
"NO_CACHED_GAUSSIAN:") {
 
  300     is.clear(std::ios::badbit | is.rdstate());
 
  301     std::cerr << 
"Unexpected caching state keyword of RandGauss:" << c2
 
  302               << 
"\nistream is left in the badbit state\n";
 
  309 std::ostream & RandGauss::saveDistState ( std::ostream & os ) {
 
  310   int prec = os.precision(20);
 
  311   std::vector<unsigned long> t(2);
 
  312   os << distributionName() << 
"\n";
 
  315     t = DoubConv::dto2longs(getVal());
 
  316     os << 
"nextGauss_st " << getVal() << 
" " << t[0] << 
" " << t[1] << 
"\n";
 
  318     os << 
"no_cached_nextGauss_st \n";
 
  324 std::istream & RandGauss::restoreDistState ( std::istream & is ) {
 
  327   if (inName != distributionName()) {
 
  328     is.clear(std::ios::badbit | is.rdstate());
 
  329     std::cerr << 
"Mismatch when expecting to read static state of a " 
  330               << distributionName() << 
" distribution\n" 
  331               << 
"Name found was " << inName
 
  332               << 
"\nistream is left in the badbit state\n";
 
  337   if (possibleKeywordInput(is, 
"Uvec", c1)) {
 
  338     std::vector<unsigned long> t(2);
 
  342     if (ng == 
"nextGauss_st") {
 
  343       is >> nextGauss_st >> t[0] >> t[1]; 
 
  344       nextGauss_st = DoubConv::longs2double(t);
 
  350   is >> c2 >> nextGauss_st;
 
  351   if ( (!is) || (c1 != 
"RANDGAUSS") ) {
 
  352     is.clear(std::ios::badbit | is.rdstate());
 
  353     std::cerr << 
"Failure when reading caching state of static RandGauss\n";
 
  356   if (c2 == 
"CACHED_GAUSSIAN:") {
 
  358   } 
else if (c2 == 
"NO_CACHED_GAUSSIAN:") {
 
  361     is.clear(std::ios::badbit | is.rdstate());
 
  362     std::cerr << 
"Unexpected caching state keyword of static RandGauss:" << c2
 
  363               << 
"\nistream is left in the badbit state\n";
 
  368 std::ostream & RandGauss::saveFullState ( std::ostream & os ) {
 
  369   HepRandom::saveFullState(os);
 
  374 std::istream & RandGauss::restoreFullState ( std::istream & is ) {
 
  375   HepRandom::restoreFullState(is);
 
  376   restoreDistState(is);
 
ThreeVector shoot(const G4int Ap, const G4int Af)
 
static c2_factory< G4double > c2
 
static int engine(pchar, pchar, double &, pchar &, const dic_type &)
 
static double normal(HepRandomEngine *eptr)
 
static const G4double fac