35#include "CLHEP/Random/defs.h"
36#include "CLHEP/Random/RandGauss.h"
37#include "CLHEP/Random/DoubConv.h"
50CLHEP_THREAD_LOCAL
bool RandGauss::set_st =
false;
51CLHEP_THREAD_LOCAL
double RandGauss::nextGauss_st = 0.0;
61 return fire( mean, stdDev );
81 v1 = 2.0 * anEngine->
flat() - 1.0;
82 v2 = 2.0 * anEngine->
flat() - 1.0;
86 fac = std::sqrt(-2.0*std::log(r)/r);
94 double mean,
double stdDev )
96 for(
double* v = vect; v != vect + size; ++v )
97 *v =
shoot(mean,stdDev);
111 double v1,v2,fac,val;
114 v1 = 2.0 * anEngine->
flat() - 1.0;
115 v2 = 2.0 * anEngine->
flat() - 1.0;
119 fac = std::sqrt( -2.0*std::log(r)/r);
127 const int size,
double* vect,
128 double mean,
double stdDev )
130 for(
double* v = vect; v != vect + size; ++v )
131 *v =
shoot(anEngine,mean,stdDev);
145 double v1,v2,fac,val;
153 fac = std::sqrt(-2.0*std::log(r)/r);
162 for(
double* v = vect; v != vect + size; ++v )
167 double mean,
double stdDev )
169 for(
double* v = vect; v != vect + size; ++v )
170 *v =
fire( mean, stdDev );
190 nextGauss_st = nextVal;
200 std::ofstream outfile ( filename, std::ios::app );
203 std::vector<unsigned long> t(2);
205 outfile <<
"RANDGAUSS CACHED_GAUSSIAN: Uvec "
206 <<
getVal() <<
" " << t[0] <<
" " << t[1] <<
"\n";
208 outfile <<
"RANDGAUSS NO_CACHED_GAUSSIAN: 0 \n" ;
220 std::ifstream infile ( filename, std::ios::in );
223 char inputword[] =
"NO_KEYWORD ";
227 if (strcmp(inputword,
"RANDGAUSS")==0)
break;
228 if (infile.eof())
break;
236 if (strcmp(inputword,
"RANDGAUSS")==0) {
240 if (strcmp(setword,
"CACHED_GAUSSIAN:") ==0) {
242 std::vector<unsigned long> t(2);
243 infile >> nextGauss_st >> t[0] >> t[1];
250 infile >> nextGauss_st;
261 os <<
name() <<
"\n";
262 long prec = os.precision(20);
263 std::vector<unsigned long> t(2);
266 os <<
defaultMean <<
" " << t[0] <<
" " << t[1] <<
"\n";
271 os <<
"nextGauss " << nextGauss <<
" " << t[0] <<
" " << t[1] <<
"\n";
273 std::cout <<
"put(): nextGauss = " << nextGauss <<
"\n";
277 std::cout <<
"put(): No nextGauss \n";
279 os <<
"no_cached_nextGauss \n";
288 if (inName !=
name()) {
289 is.clear(std::ios::badbit | is.rdstate());
290 std::cerr <<
"Mismatch when expecting to read state of a "
291 <<
name() <<
" distribution\n"
292 <<
"Name found was " << inName
293 <<
"\nistream is left in the badbit state\n";
299 std::vector<unsigned long> t(2);
306 if (ng !=
"nextGauss")
307 std::cout <<
"get(): ng = " << ng <<
"\n";
309 if (ng ==
"nextGauss") {
312 std::cout <<
"get(): nextGauss read back as " << nextGauss <<
"\n";
320 if ( (!is) || (c1 !=
"Mean:") || (c2 !=
"Sigma:") ) {
321 std::cerr <<
"i/o problem while expecting to read state of a "
322 <<
name() <<
" distribution\n"
323 <<
"default mean and/or sigma could not be read\n";
326 is >> c1 >> c2 >> nextGauss;
327 if ( (!is) || (c1 !=
"RANDGAUSS") ) {
328 is.clear(std::ios::badbit | is.rdstate());
329 std::cerr <<
"Failure when reading caching state of RandGauss\n";
332 if (c2 ==
"CACHED_GAUSSIAN:") {
334 }
else if (c2 ==
"NO_CACHED_GAUSSIAN:") {
337 is.clear(std::ios::badbit | is.rdstate());
338 std::cerr <<
"Unexpected caching state keyword of RandGauss:" << c2
339 <<
"\nistream is left in the badbit state\n";
347 long prec = os.precision(20);
348 std::vector<unsigned long> t(2);
353 os <<
"nextGauss_st " <<
getVal() <<
" " << t[0] <<
" " << t[1] <<
"\n";
355 os <<
"no_cached_nextGauss_st \n";
365 is.clear(std::ios::badbit | is.rdstate());
366 std::cerr <<
"Mismatch when expecting to read static state of a "
368 <<
"Name found was " << inName
369 <<
"\nistream is left in the badbit state\n";
375 std::vector<unsigned long> t(2);
379 if (ng ==
"nextGauss_st") {
380 is >> nextGauss_st >> t[0] >> t[1];
387 is >> c2 >> nextGauss_st;
388 if ( (!is) || (c1 !=
"RANDGAUSS") ) {
389 is.clear(std::ios::badbit | is.rdstate());
390 std::cerr <<
"Failure when reading caching state of static RandGauss\n";
393 if (c2 ==
"CACHED_GAUSSIAN:") {
395 }
else if (c2 ==
"NO_CACHED_GAUSSIAN:") {
398 is.clear(std::ios::badbit | is.rdstate());
399 std::cerr <<
"Unexpected caching state keyword of static RandGauss:" << c2
400 <<
"\nistream is left in the badbit state\n";
static double longs2double(const std::vector< unsigned long > &v)
static std::vector< unsigned long > dto2longs(double d)
virtual void restoreStatus(const char filename[]="Config.conf")=0
virtual void saveStatus(const char filename[]="Config.conf") const =0
static HepRandomEngine * getTheEngine()
static std::ostream & saveFullState(std::ostream &os)
static std::istream & restoreFullState(std::istream &is)
static std::ostream & saveDistState(std::ostream &os)
static std::istream & restoreFullState(std::istream &is)
static void restoreEngineStatus(const char filename[]="Config.conf")
std::istream & get(std::istream &is)
std::ostream & put(std::ostream &os) const
void fireArray(const int size, double *vect)
static void shootArray(const int size, double *vect, double mean=0.0, double stdDev=1.0)
static void setVal(double nextVal)
HepRandomEngine & engine()
static std::ostream & saveFullState(std::ostream &os)
static void setFlag(bool val)
static std::string distributionName()
std::shared_ptr< HepRandomEngine > localEngine
static std::istream & restoreDistState(std::istream &is)
virtual double operator()()
static void saveEngineStatus(const char filename[]="Config.conf")
bool possibleKeywordInput(IS &is, const std::string &key, T &t)