47bool RandGauss::set_st =
false;
48double RandGauss::nextGauss_st = 0.0;
58 return fire( mean, stdDev );
78 v1 = 2.0 * anEngine->
flat() - 1.0;
79 v2 = 2.0 * anEngine->
flat() - 1.0;
83 fac = std::sqrt(-2.0*std::log(r)/r);
91 double mean,
double stdDev )
93 for(
double* v = vect; v != vect + size; ++v )
94 *v =
shoot(mean,stdDev);
108 double v1,v2,fac,val;
111 v1 = 2.0 * anEngine->
flat() - 1.0;
112 v2 = 2.0 * anEngine->
flat() - 1.0;
116 fac = std::sqrt( -2.0*std::log(r)/r);
124 const int size,
double* vect,
125 double mean,
double stdDev )
127 for(
double* v = vect; v != vect + size; ++v )
128 *v =
shoot(anEngine,mean,stdDev);
142 double v1,v2,fac,val;
150 fac = std::sqrt(-2.0*std::log(r)/r);
159 for(
double* v = vect; v != vect + size; ++v )
164 double mean,
double stdDev )
166 for(
double* v = vect; v != vect + size; ++v )
167 *v =
fire( mean, stdDev );
177 std::ofstream outfile ( filename, std::ios::app );
180 std::vector<unsigned long> t(2);
182 outfile <<
"RANDGAUSS CACHED_GAUSSIAN: Uvec "
183 <<
getVal() <<
" " << t[0] <<
" " << t[1] <<
"\n";
185 outfile <<
"RANDGAUSS NO_CACHED_GAUSSIAN: 0 \n" ;
197 std::ifstream infile ( filename, std::ios::in );
200 char inputword[] =
"NO_KEYWORD ";
204 if (strcmp(inputword,
"RANDGAUSS")==0)
break;
205 if (infile.eof())
break;
213 if (strcmp(inputword,
"RANDGAUSS")==0) {
217 if (strcmp(setword,
"CACHED_GAUSSIAN:") ==0) {
219 std::vector<unsigned long> t(2);
220 infile >> nextGauss_st >> t[0] >> t[1];
227 infile >> nextGauss_st;
238 os <<
name() <<
"\n";
239 int prec = os.precision(20);
240 std::vector<unsigned long> t(2);
243 os <<
defaultMean <<
" " << t[0] <<
" " << t[1] <<
"\n";
248 os <<
"nextGauss " << nextGauss <<
" " << t[0] <<
" " << t[1] <<
"\n";
250 std::cout <<
"put(): nextGauss = " << nextGauss <<
"\n";
254 std::cout <<
"put(): No nextGauss \n";
256 os <<
"no_cached_nextGauss \n";
265 if (inName !=
name()) {
266 is.clear(std::ios::badbit | is.rdstate());
267 std::cerr <<
"Mismatch when expecting to read state of a "
268 <<
name() <<
" distribution\n"
269 <<
"Name found was " << inName
270 <<
"\nistream is left in the badbit state\n";
276 std::vector<unsigned long> t(2);
283 if (ng !=
"nextGauss")
284 std::cout <<
"get(): ng = " << ng <<
"\n";
286 if (ng ==
"nextGauss") {
289 std::cout <<
"get(): nextGauss read back as " << nextGauss <<
"\n";
297 if ( (!is) || (c1 !=
"Mean:") || (c2 !=
"Sigma:") ) {
298 std::cerr <<
"i/o problem while expecting to read state of a "
299 <<
name() <<
" distribution\n"
300 <<
"default mean and/or sigma could not be read\n";
303 is >> c1 >> c2 >> nextGauss;
304 if ( (!is) || (c1 !=
"RANDGAUSS") ) {
305 is.clear(std::ios::badbit | is.rdstate());
306 std::cerr <<
"Failure when reading caching state of RandGauss\n";
309 if (c2 ==
"CACHED_GAUSSIAN:") {
311 }
else if (c2 ==
"NO_CACHED_GAUSSIAN:") {
314 is.clear(std::ios::badbit | is.rdstate());
315 std::cerr <<
"Unexpected caching state keyword of RandGauss:" << c2
316 <<
"\nistream is left in the badbit state\n";
324 int prec = os.precision(20);
325 std::vector<unsigned long> t(2);
330 os <<
"nextGauss_st " <<
getVal() <<
" " << t[0] <<
" " << t[1] <<
"\n";
332 os <<
"no_cached_nextGauss_st \n";
342 is.clear(std::ios::badbit | is.rdstate());
343 std::cerr <<
"Mismatch when expecting to read static state of a "
345 <<
"Name found was " << inName
346 <<
"\nistream is left in the badbit state\n";
352 std::vector<unsigned long> t(2);
356 if (ng ==
"nextGauss_st") {
357 is >> nextGauss_st >> t[0] >> t[1];
364 is >> c2 >> nextGauss_st;
365 if ( (!is) || (c1 !=
"RANDGAUSS") ) {
366 is.clear(std::ios::badbit | is.rdstate());
367 std::cerr <<
"Failure when reading caching state of static RandGauss\n";
370 if (c2 ==
"CACHED_GAUSSIAN:") {
372 }
else if (c2 ==
"NO_CACHED_GAUSSIAN:") {
375 is.clear(std::ios::badbit | is.rdstate());
376 std::cerr <<
"Unexpected caching state keyword of static RandGauss:" << c2
377 <<
"\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)
shared_ptr< HepRandomEngine > localEngine
HepRandomEngine & engine()
static std::ostream & saveFullState(std::ostream &os)
static std::string distributionName()
static void setVal(double nextVal)
static void setFlag(bool val)
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)