Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/clhep/src/RandGauss.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/src/RandGauss.cc (Version 11.3.0) and /externals/clhep/src/RandGauss.cc (Version 10.1.p2)


                                                   >>   1 // $Id:$
  1 // -*- C++ -*-                                      2 // -*- C++ -*-
  2 //                                                  3 //
  3 // -------------------------------------------      4 // -----------------------------------------------------------------------
  4 //                             HEP Random           5 //                             HEP Random
  5 //                          --- RandGauss ---       6 //                          --- RandGauss ---
  6 //                      class implementation f      7 //                      class implementation file
  7 // -------------------------------------------      8 // -----------------------------------------------------------------------
  8 // This file is part of Geant4 (simulation too      9 // This file is part of Geant4 (simulation toolkit for HEP).
  9                                                    10 
 10 // ===========================================     11 // =======================================================================
 11 // Gabriele Cosmo - Created: 5th September 199     12 // Gabriele Cosmo - Created: 5th September 1995
 12 //                - Added methods to shoot arr     13 //                - Added methods to shoot arrays: 28th July 1997
 13 // J.Marraffino   - Added default arguments as     14 // J.Marraffino   - Added default arguments as attributes and
 14 //                  operator() with arguments.     15 //                  operator() with arguments. Introduced method normal()
 15 //                  for computation in fire():     16 //                  for computation in fire(): 16th Feb 1998
 16 // Gabriele Cosmo - Relocated static data from     17 // Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
 17 // M Fischler     - Copy constructor should su     18 // M Fischler     - Copy constructor should supply right engine to HepRandom:
 18 //        1/26/00.                                 19 //        1/26/00.
 19 // M Fischler     - Workaround for problem of      20 // M Fischler     - Workaround for problem of non-reproducing saveEngineStatus
 20 //        by saving cached gaussian.  March 20     21 //        by saving cached gaussian.  March 2000.
 21 // M Fischler     - Avoiding hang when file no     22 // M Fischler     - Avoiding hang when file not found in restoreEngineStatus 
 22 //                  12/3/04                        23 //                  12/3/04
 23 // M Fischler     - put and get to/from stream     24 // M Fischler     - put and get to/from streams 12/8/04
 24 // M Fischler     - save and restore dist to s     25 // M Fischler     - save and restore dist to streams 12/20/04
 25 // M Fischler   - put/get to/from streams uses     26 // M Fischler   - put/get to/from streams uses pairs of ulongs when
 26 //        storing doubles avoid problems with      27 //        storing doubles avoid problems with precision.
 27 //        Similarly for saveEngineStatus and R     28 //        Similarly for saveEngineStatus and RestoreEngineStatus
 28 //        and for save/restore distState           29 //        and for save/restore distState
 29 //        Care was taken that old-form output      30 //        Care was taken that old-form output can still be read back.
 30 //      4/14/05                                    31 //      4/14/05
 31 //                                                 32 //              
 32 // ===========================================     33 // =======================================================================
 33                                                    34 
 34 #include "CLHEP/Random/RandGauss.h"                35 #include "CLHEP/Random/RandGauss.h"
 35 #include "CLHEP/Random/DoubConv.h"                 36 #include "CLHEP/Random/DoubConv.h"
 36 #include <cmath>  // for std::log()            << 
 37 #include <iostream>                            << 
 38 #include <string.h> // for strcmp                  37 #include <string.h> // for strcmp
 39 #include <string>                              <<  38 #include <cmath>  // for std::log()
 40 #include <vector>                              << 
 41                                                    39 
 42 namespace CLHEP {                                  40 namespace CLHEP {
 43                                                    41 
 44 std::string RandGauss::name() const {return "R     42 std::string RandGauss::name() const {return "RandGauss";}
 45 HepRandomEngine & RandGauss::engine() {return      43 HepRandomEngine & RandGauss::engine() {return *localEngine;}
 46                                                    44 
 47 // Initialisation of static data                   45 // Initialisation of static data
 48 CLHEP_THREAD_LOCAL bool RandGauss::set_st = fa     46 CLHEP_THREAD_LOCAL bool RandGauss::set_st = false;
 49 CLHEP_THREAD_LOCAL double RandGauss::nextGauss     47 CLHEP_THREAD_LOCAL double RandGauss::nextGauss_st = 0.0;
 50                                                    48 
 51 RandGauss::~RandGauss() {                          49 RandGauss::~RandGauss() {
 52 }                                                  50 }
 53                                                    51 
 54 double RandGauss::operator()() {                   52 double RandGauss::operator()() {
 55   return fire( defaultMean, defaultStdDev );       53   return fire( defaultMean, defaultStdDev );
 56 }                                                  54 }
 57                                                    55 
 58 double RandGauss::operator()( double mean, dou     56 double RandGauss::operator()( double mean, double stdDev ) {
 59   return fire( mean, stdDev );                     57   return fire( mean, stdDev );
 60 }                                                  58 }
 61                                                    59 
 62 double RandGauss::shoot()                          60 double RandGauss::shoot()
 63 {                                                  61 {
 64   // Gaussian random numbers are generated two     62   // Gaussian random numbers are generated two at the time, so every other
 65   // time this is called we just return a numb     63   // time this is called we just return a number generated the time before.
 66                                                    64 
 67   if ( getFlag() ) {                               65   if ( getFlag() ) {
 68     setFlag(false);                                66     setFlag(false);
 69     double x = getVal();                           67     double x = getVal();
 70     return x;                                      68     return x; 
 71     // return getVal();                            69     // return getVal();
 72   }                                                70   } 
 73                                                    71 
 74   double r;                                        72   double r;
 75   double v1,v2,fac,val;                            73   double v1,v2,fac,val;
 76   HepRandomEngine* anEngine = HepRandom::getTh     74   HepRandomEngine* anEngine = HepRandom::getTheEngine();
 77                                                    75 
 78   do {                                             76   do {
 79     v1 = 2.0 * anEngine->flat() - 1.0;             77     v1 = 2.0 * anEngine->flat() - 1.0;
 80     v2 = 2.0 * anEngine->flat() - 1.0;             78     v2 = 2.0 * anEngine->flat() - 1.0;
 81     r = v1*v1 + v2*v2;                             79     r = v1*v1 + v2*v2;
 82   } while ( r > 1.0 );                             80   } while ( r > 1.0 );
 83                                                    81 
 84   fac = std::sqrt(-2.0*std::log(r)/r);             82   fac = std::sqrt(-2.0*std::log(r)/r);
 85   val = v1*fac;                                    83   val = v1*fac;
 86   setVal(val);                                     84   setVal(val);
 87   setFlag(true);                                   85   setFlag(true);
 88   return v2*fac;                                   86   return v2*fac;
 89 }                                                  87 }
 90                                                    88 
 91 void RandGauss::shootArray( const int size, do     89 void RandGauss::shootArray( const int size, double* vect,
 92                             double mean, doubl     90                             double mean, double stdDev )
 93 {                                                  91 {
 94   for( double* v = vect; v != vect + size; ++v     92   for( double* v = vect; v != vect + size; ++v )
 95     *v = shoot(mean,stdDev);                       93     *v = shoot(mean,stdDev);
 96 }                                                  94 }
 97                                                    95 
 98 double RandGauss::shoot( HepRandomEngine* anEn     96 double RandGauss::shoot( HepRandomEngine* anEngine )
 99 {                                                  97 {
100   // Gaussian random numbers are generated two     98   // Gaussian random numbers are generated two at the time, so every other
101   // time this is called we just return a numb     99   // time this is called we just return a number generated the time before.
102                                                   100 
103   if ( getFlag() ) {                              101   if ( getFlag() ) {
104     setFlag(false);                               102     setFlag(false);
105     return getVal();                              103     return getVal();
106   }                                               104   }
107                                                   105 
108   double r;                                       106   double r;
109   double v1,v2,fac,val;                           107   double v1,v2,fac,val;
110                                                   108 
111   do {                                            109   do {
112     v1 = 2.0 * anEngine->flat() - 1.0;            110     v1 = 2.0 * anEngine->flat() - 1.0;
113     v2 = 2.0 * anEngine->flat() - 1.0;            111     v2 = 2.0 * anEngine->flat() - 1.0;
114     r = v1*v1 + v2*v2;                            112     r = v1*v1 + v2*v2;
115   } while ( r > 1.0 );                            113   } while ( r > 1.0 );
116                                                   114 
117   fac = std::sqrt( -2.0*std::log(r)/r);           115   fac = std::sqrt( -2.0*std::log(r)/r);
118   val = v1*fac;                                   116   val = v1*fac;
119   setVal(val);                                    117   setVal(val);
120   setFlag(true);                                  118   setFlag(true);
121   return v2*fac;                                  119   return v2*fac;
122 }                                                 120 }
123                                                   121 
124 void RandGauss::shootArray( HepRandomEngine* a    122 void RandGauss::shootArray( HepRandomEngine* anEngine,
125                             const int size, do    123                             const int size, double* vect,
126                             double mean, doubl    124                             double mean, double stdDev )
127 {                                                 125 {
128   for( double* v = vect; v != vect + size; ++v    126   for( double* v = vect; v != vect + size; ++v )
129     *v = shoot(anEngine,mean,stdDev);             127     *v = shoot(anEngine,mean,stdDev);
130 }                                                 128 }
131                                                   129 
132 double RandGauss::normal()                        130 double RandGauss::normal()
133 {                                                 131 {
134   // Gaussian random numbers are generated two    132   // Gaussian random numbers are generated two at the time, so every other
135   // time this is called we just return a numb    133   // time this is called we just return a number generated the time before.
136                                                   134 
137   if ( set ) {                                    135   if ( set ) {
138     set = false;                                  136     set = false;
139     return nextGauss;                             137     return nextGauss;
140   }                                               138   }
141                                                   139 
142   double r;                                       140   double r;
143   double v1,v2,fac,val;                           141   double v1,v2,fac,val;
144                                                   142 
145   do {                                            143   do {
146     v1 = 2.0 * localEngine->flat() - 1.0;         144     v1 = 2.0 * localEngine->flat() - 1.0;
147     v2 = 2.0 * localEngine->flat() - 1.0;         145     v2 = 2.0 * localEngine->flat() - 1.0;
148     r = v1*v1 + v2*v2;                            146     r = v1*v1 + v2*v2;
149   } while ( r > 1.0 );                            147   } while ( r > 1.0 );
150                                                   148 
151   fac = std::sqrt(-2.0*std::log(r)/r);            149   fac = std::sqrt(-2.0*std::log(r)/r);
152   val = v1*fac;                                   150   val = v1*fac;
153   nextGauss = val;                                151   nextGauss = val;
154   set = true;                                     152   set = true;
155   return v2*fac;                                  153   return v2*fac;
156 }                                                 154 }
157                                                   155 
158 void RandGauss::fireArray( const int size, dou    156 void RandGauss::fireArray( const int size, double* vect)
159 {                                                 157 {
160   for( double* v = vect; v != vect + size; ++v    158   for( double* v = vect; v != vect + size; ++v )
161     *v = fire( defaultMean, defaultStdDev );      159     *v = fire( defaultMean, defaultStdDev );
162 }                                                 160 }
163                                                   161 
164 void RandGauss::fireArray( const int size, dou    162 void RandGauss::fireArray( const int size, double* vect,
165                            double mean, double    163                            double mean, double stdDev )
166 {                                                 164 {
167   for( double* v = vect; v != vect + size; ++v    165   for( double* v = vect; v != vect + size; ++v )
168     *v = fire( mean, stdDev );                    166     *v = fire( mean, stdDev );
169 }                                                 167 }
170                                                   168 
171 bool RandGauss::getFlag()                         169 bool RandGauss::getFlag()
172 {                                                 170 {
173   return set_st;                                  171   return set_st;
174 }                                                 172 }
175                                                   173 
176 void RandGauss::setFlag( bool val )               174 void RandGauss::setFlag( bool val )
177 {                                                 175 {
178   set_st = val;                                   176   set_st = val;
179 }                                                 177 }
180                                                   178 
181 double RandGauss::getVal()                        179 double RandGauss::getVal()
182 {                                                 180 {
183   return nextGauss_st;                            181   return nextGauss_st;
184 }                                                 182 }
185                                                   183 
186 void RandGauss::setVal( double nextVal )          184 void RandGauss::setVal( double nextVal )
187 {                                                 185 {
188   nextGauss_st = nextVal;                         186   nextGauss_st = nextVal;
189 }                                                 187 }
190                                                   188 
191 void RandGauss::saveEngineStatus ( const char     189 void RandGauss::saveEngineStatus ( const char filename[] ) {
192                                                   190 
193   // First save the engine status just like th    191   // First save the engine status just like the base class would do:
194   getTheEngine()->saveStatus( filename );         192   getTheEngine()->saveStatus( filename );
195                                                   193 
196   // Now append the cached variate, if any:       194   // Now append the cached variate, if any:
197                                                   195 
198   std::ofstream outfile ( filename, std::ios::    196   std::ofstream outfile ( filename, std::ios::app );
199                                                   197 
200   if ( getFlag() ) {                              198   if ( getFlag() ) {
201     std::vector<unsigned long> t(2);              199     std::vector<unsigned long> t(2);
202     t = DoubConv::dto2longs(getVal());            200     t = DoubConv::dto2longs(getVal());
203     outfile << "RANDGAUSS CACHED_GAUSSIAN: Uve    201     outfile << "RANDGAUSS CACHED_GAUSSIAN: Uvec " 
204       << getVal() << " " << t[0] << " " << t[1    202       << getVal() << " " << t[0] << " " << t[1] << "\n";
205   } else {                                        203   } else {
206     outfile << "RANDGAUSS NO_CACHED_GAUSSIAN:     204     outfile << "RANDGAUSS NO_CACHED_GAUSSIAN: 0 \n" ;
207   }                                               205   }
208                                                   206 
209 } // saveEngineStatus                             207 } // saveEngineStatus
210                                                   208 
211 void RandGauss::restoreEngineStatus( const cha    209 void RandGauss::restoreEngineStatus( const char filename[] ) {
212                                                   210 
213   // First restore the engine status just like    211   // First restore the engine status just like the base class would do:
214   getTheEngine()->restoreStatus( filename );      212   getTheEngine()->restoreStatus( filename );
215                                                   213 
216   // Now find the line describing the cached v    214   // Now find the line describing the cached variate:
217                                                   215 
218   std::ifstream infile ( filename, std::ios::i    216   std::ifstream infile ( filename, std::ios::in );
219   if (!infile) return;                            217   if (!infile) return;
220                                                   218 
221   char inputword[] = "NO_KEYWORD    "; // leav    219   char inputword[] = "NO_KEYWORD    "; // leaves room for 14 characters plus \0
222   while (true) {                                  220   while (true) {
223     infile.width(13);                             221     infile.width(13);
224     infile >> inputword;                          222     infile >> inputword;
225     if (strcmp(inputword,"RANDGAUSS")==0) brea    223     if (strcmp(inputword,"RANDGAUSS")==0) break;
226     if (infile.eof()) break;                      224     if (infile.eof()) break;
227   // If the file ends without the RANDGAUSS li    225   // If the file ends without the RANDGAUSS line, that means this
228   // was a file produced by an earlier version    226   // was a file produced by an earlier version of RandGauss.  We will
229   // replicated the old behavior in that case:    227   // replicated the old behavior in that case:  set_st is cleared.
230   }                                               228   }
231                                                   229 
232   // Then read and use the caching info:          230   // Then read and use the caching info:
233                                                   231 
234   if (strcmp(inputword,"RANDGAUSS")==0) {         232   if (strcmp(inputword,"RANDGAUSS")==0) {
235     char setword[40]; // the longest, staticFi    233     char setword[40]; // the longest, staticFirstUnusedBit: has length 21
236     infile.width(39);                             234     infile.width(39);
237     infile >> setword;  // setword should be C    235     infile >> setword;  // setword should be CACHED_GAUSSIAN:
238     if (strcmp(setword,"CACHED_GAUSSIAN:") ==0    236     if (strcmp(setword,"CACHED_GAUSSIAN:") ==0) {
239       if (possibleKeywordInput(infile, "Uvec",    237       if (possibleKeywordInput(infile, "Uvec", nextGauss_st)) {
240         std::vector<unsigned long> t(2);          238         std::vector<unsigned long> t(2);
241         infile >> nextGauss_st >> t[0] >> t[1]    239         infile >> nextGauss_st >> t[0] >> t[1]; 
242         nextGauss_st = DoubConv::longs2double(    240         nextGauss_st = DoubConv::longs2double(t); 
243       }                                           241       }
244       // is >> nextGauss_st encompassed by pos    242       // is >> nextGauss_st encompassed by possibleKeywordInput
245       setFlag(true);                              243       setFlag(true);
246     } else {                                      244     } else {
247       setFlag(false);                             245       setFlag(false);
248       infile >> nextGauss_st; // because a 0 w    246       infile >> nextGauss_st; // because a 0 will have been output
249     }                                             247     }
250   } else {                                        248   } else {
251     setFlag(false);                               249     setFlag(false);
252   }                                               250   }
253                                                   251 
254 } // restoreEngineStatus                          252 } // restoreEngineStatus
255                                                   253 
256   // Save and restore to/from streams             254   // Save and restore to/from streams
257                                                   255   
258 std::ostream & RandGauss::put ( std::ostream &    256 std::ostream & RandGauss::put ( std::ostream & os ) const {
259   os << name() << "\n";                           257   os << name() << "\n";
260   long prec = os.precision(20);                << 258   int prec = os.precision(20);
261   std::vector<unsigned long> t(2);                259   std::vector<unsigned long> t(2);
262   os << "Uvec\n";                                 260   os << "Uvec\n";
263   t = DoubConv::dto2longs(defaultMean);           261   t = DoubConv::dto2longs(defaultMean);
264   os << defaultMean << " " << t[0] << " " << t    262   os << defaultMean << " " << t[0] << " " << t[1] << "\n";
265   t = DoubConv::dto2longs(defaultStdDev);         263   t = DoubConv::dto2longs(defaultStdDev);
266   os << defaultStdDev << " " << t[0] << " " <<    264   os << defaultStdDev << " " << t[0] << " " << t[1] << "\n";
267   if ( set ) {                                    265   if ( set ) {
268     t = DoubConv::dto2longs(nextGauss);           266     t = DoubConv::dto2longs(nextGauss);
269     os << "nextGauss " << nextGauss << " " <<     267     os << "nextGauss " << nextGauss << " " << t[0] << " " << t[1] << "\n";
270   } else {                                        268   } else {
271     os << "no_cached_nextGauss \n";               269     os << "no_cached_nextGauss \n";
272   }                                               270   }
273   os.precision(prec);                             271   os.precision(prec);
274   return os;                                      272   return os;
275 } // put                                          273 } // put   
276                                                   274 
277 std::istream & RandGauss::get ( std::istream &    275 std::istream & RandGauss::get ( std::istream & is ) {
278   std::string inName;                             276   std::string inName;
279   is >> inName;                                   277   is >> inName;
280   if (inName != name()) {                         278   if (inName != name()) {
281     is.clear(std::ios::badbit | is.rdstate());    279     is.clear(std::ios::badbit | is.rdstate());
282     std::cerr << "Mismatch when expecting to r    280     std::cerr << "Mismatch when expecting to read state of a "
283             << name() << " distribution\n"        281             << name() << " distribution\n"
284         << "Name found was " << inName            282         << "Name found was " << inName
285         << "\nistream is left in the badbit st    283         << "\nistream is left in the badbit state\n";
286     return is;                                    284     return is;
287   }                                               285   }
288   std::string c1;                                 286   std::string c1;
289   std::string c2;                                 287   std::string c2;
290   if (possibleKeywordInput(is, "Uvec", c1)) {     288   if (possibleKeywordInput(is, "Uvec", c1)) {
291     std::vector<unsigned long> t(2);              289     std::vector<unsigned long> t(2);
292     is >> defaultMean >> t[0] >> t[1]; default    290     is >> defaultMean >> t[0] >> t[1]; defaultMean = DoubConv::longs2double(t); 
293     is >> defaultStdDev>>t[0]>>t[1]; defaultSt    291     is >> defaultStdDev>>t[0]>>t[1]; defaultStdDev = DoubConv::longs2double(t); 
294     std::string ng;                               292     std::string ng;
295     is >> ng;                                     293     is >> ng;
296     set = false;                                  294     set = false;
297     if (ng == "nextGauss") {                      295     if (ng == "nextGauss") {
298       is >> nextGauss >> t[0] >> t[1]; nextGau    296       is >> nextGauss >> t[0] >> t[1]; nextGauss = DoubConv::longs2double(t);
299       set = true;                                 297       set = true;
300     }                                             298     }
301     return is;                                    299     return is;
302   }                                               300   }
303   // is >> c1 encompassed by possibleKeywordIn    301   // is >> c1 encompassed by possibleKeywordInput
304   is >> defaultMean >> c2 >> defaultStdDev;       302   is >> defaultMean >> c2 >> defaultStdDev;
305   if ( (!is) || (c1 != "Mean:") || (c2 != "Sig    303   if ( (!is) || (c1 != "Mean:") || (c2 != "Sigma:") ) {
306     std::cerr << "i/o problem while expecting     304     std::cerr << "i/o problem while expecting to read state of a "
307             << name() << " distribution\n"        305             << name() << " distribution\n"
308         << "default mean and/or sigma could no    306         << "default mean and/or sigma could not be read\n";
309     return is;                                    307     return is;
310   }                                               308   }
311   is >> c1 >> c2 >> nextGauss;                    309   is >> c1 >> c2 >> nextGauss;
312   if ( (!is) || (c1 != "RANDGAUSS") ) {           310   if ( (!is) || (c1 != "RANDGAUSS") ) {
313     is.clear(std::ios::badbit | is.rdstate());    311     is.clear(std::ios::badbit | is.rdstate());
314     std::cerr << "Failure when reading caching    312     std::cerr << "Failure when reading caching state of RandGauss\n";
315     return is;                                    313     return is;
316   }                                               314   }
317   if (c2 == "CACHED_GAUSSIAN:") {                 315   if (c2 == "CACHED_GAUSSIAN:") {
318     set = true;                                   316     set = true;
319   } else if (c2 == "NO_CACHED_GAUSSIAN:") {       317   } else if (c2 == "NO_CACHED_GAUSSIAN:") {
320     set = false;                                  318     set = false;  
321   } else {                                        319   } else {
322     is.clear(std::ios::badbit | is.rdstate());    320     is.clear(std::ios::badbit | is.rdstate());
323     std::cerr << "Unexpected caching state key    321     std::cerr << "Unexpected caching state keyword of RandGauss:" << c2
324         << "\nistream is left in the badbit st    322         << "\nistream is left in the badbit state\n";
325   }                                               323   } 
326   return is;                                      324   return is;
327 } // get                                          325 } // get
328                                                   326 
329   // Static save and restore to/from streams      327   // Static save and restore to/from streams
330                                                   328   
331 std::ostream & RandGauss::saveDistState ( std:    329 std::ostream & RandGauss::saveDistState ( std::ostream & os ) {
332   long prec = os.precision(20);                << 330   int prec = os.precision(20);
333   std::vector<unsigned long> t(2);                331   std::vector<unsigned long> t(2);
334   os << distributionName() << "\n";               332   os << distributionName() << "\n";
335   os << "Uvec\n";                                 333   os << "Uvec\n";
336   if ( getFlag() ) {                              334   if ( getFlag() ) {
337     t = DoubConv::dto2longs(getVal());            335     t = DoubConv::dto2longs(getVal());
338     os << "nextGauss_st " << getVal() << " " <    336     os << "nextGauss_st " << getVal() << " " << t[0] << " " << t[1] << "\n";
339   } else {                                        337   } else {
340     os << "no_cached_nextGauss_st \n";            338     os << "no_cached_nextGauss_st \n";
341   }                                               339   }
342   os.precision(prec);                             340   os.precision(prec);
343   return os;                                      341   return os;
344 }                                                 342 }    
345                                                   343 
346 std::istream & RandGauss::restoreDistState ( s    344 std::istream & RandGauss::restoreDistState ( std::istream & is ) {
347   std::string inName;                             345   std::string inName;
348   is >> inName;                                   346   is >> inName;
349   if (inName != distributionName()) {             347   if (inName != distributionName()) {
350     is.clear(std::ios::badbit | is.rdstate());    348     is.clear(std::ios::badbit | is.rdstate());
351     std::cerr << "Mismatch when expecting to r    349     std::cerr << "Mismatch when expecting to read static state of a "
352             << distributionName() << " distrib    350             << distributionName() << " distribution\n"
353         << "Name found was " << inName            351         << "Name found was " << inName
354         << "\nistream is left in the badbit st    352         << "\nistream is left in the badbit state\n";
355     return is;                                    353     return is;
356   }                                               354   }
357   std::string c1;                                 355   std::string c1;
358   std::string c2;                                 356   std::string c2;
359   if (possibleKeywordInput(is, "Uvec", c1)) {     357   if (possibleKeywordInput(is, "Uvec", c1)) {
360     std::vector<unsigned long> t(2);              358     std::vector<unsigned long> t(2);
361     std::string ng;                               359     std::string ng;
362     is >> ng;                                     360     is >> ng;
363     setFlag (false);                              361     setFlag (false);
364     if (ng == "nextGauss_st") {                   362     if (ng == "nextGauss_st") {
365       is >> nextGauss_st >> t[0] >> t[1];         363       is >> nextGauss_st >> t[0] >> t[1]; 
366       nextGauss_st = DoubConv::longs2double(t)    364       nextGauss_st = DoubConv::longs2double(t);
367       setFlag (true);                             365       setFlag (true);
368     }                                             366     }
369     return is;                                    367     return is;
370   }                                               368   }
371   // is >> c1 encompassed by possibleKeywordIn    369   // is >> c1 encompassed by possibleKeywordInput
372   is >> c2 >> nextGauss_st;                       370   is >> c2 >> nextGauss_st;
373   if ( (!is) || (c1 != "RANDGAUSS") ) {           371   if ( (!is) || (c1 != "RANDGAUSS") ) {
374     is.clear(std::ios::badbit | is.rdstate());    372     is.clear(std::ios::badbit | is.rdstate());
375     std::cerr << "Failure when reading caching    373     std::cerr << "Failure when reading caching state of static RandGauss\n";
376     return is;                                    374     return is;
377   }                                               375   }
378   if (c2 == "CACHED_GAUSSIAN:") {                 376   if (c2 == "CACHED_GAUSSIAN:") {
379     setFlag(true);                                377     setFlag(true);
380   } else if (c2 == "NO_CACHED_GAUSSIAN:") {       378   } else if (c2 == "NO_CACHED_GAUSSIAN:") {
381     setFlag(false);                               379     setFlag(false);  
382   } else {                                        380   } else {
383     is.clear(std::ios::badbit | is.rdstate());    381     is.clear(std::ios::badbit | is.rdstate());
384     std::cerr << "Unexpected caching state key    382     std::cerr << "Unexpected caching state keyword of static RandGauss:" << c2
385         << "\nistream is left in the badbit st    383         << "\nistream is left in the badbit state\n";
386   }                                               384   } 
387   return is;                                      385   return is;
388 }                                                 386 } 
389                                                   387 
390 std::ostream & RandGauss::saveFullState ( std:    388 std::ostream & RandGauss::saveFullState ( std::ostream & os ) {
391   HepRandom::saveFullState(os);                   389   HepRandom::saveFullState(os);
392   saveDistState(os);                              390   saveDistState(os);
393   return os;                                      391   return os;
394 }                                                 392 }
395                                                   393   
396 std::istream & RandGauss::restoreFullState ( s    394 std::istream & RandGauss::restoreFullState ( std::istream & is ) {
397   HepRandom::restoreFullState(is);                395   HepRandom::restoreFullState(is);
398   restoreDistState(is);                           396   restoreDistState(is);
399   return is;                                      397   return is;
400 }                                                 398 }
401                                                   399 
402 }  // namespace CLHEP                             400 }  // namespace CLHEP
403                                                   401 
404                                                   402