2#include "CLHEP/Units/GlobalPhysicalConstants.h"
3#include "CLHEP/Random/Randomize.h"
4#include "CLHEP/Random/NonRandomEngine.h"
5#include "CLHEP/Random/defs.h"
13 std::ofstream
output(
"testInstanceRestore.cout");
15 std::ostream &
output = std::cout;
24#define TEST_ENGINE_NAMES
25#define TEST_INSTANCE_METHODS
37 std::vector<double> ab(2);
43 std::vector<double> v;
46 for (
int i=0; i<n; i++) {
57 output << E::engineName() <<
"\n";
58 if (E::engineName() != name) {
59 std::cout <<
"???? engineName mismatch for " << name <<
" <--> "
60 << E::engineName() <<
"\n";
62 output <<
"???? engineName mismatch for " << name <<
" <--> "
63 << E::engineName() <<
"\n";
68 if (e.name() != name) {
69 std::cout <<
"???? name mismatch for " << name <<
" <--> "
72 output <<
"???? name mismatch for " << name <<
" <--> "
80template <
class E,
class D>
85 if (d.engine().name() != e.name()) {
86 std::cout <<
"???? Improper d.engine() \n";
88 output <<
"???? Improper d.engine() \n";
98 output <<
"checkEngineInstanceSave for " << e.name() <<
"\n";
99 long pr=
output.precision(20);
101 for (
int i=0; i<100; i++) r += e.flat();
102 {std::ofstream os (
"instance_engine.save"); os << e;}
103 for (
int i=0; i<100; i++) r += e.flat();
104 double keyValue1 = e.flat();
105 double keyValue2 = e.flat();
107 output << keyValue1 <<
" " << keyValue2 <<
"\n";
110 {std::ifstream is (
"instance_engine.save"); is >> e2;}
111 for (
int i=0; i<100; i++) r += e2.flat();
112 double k1 = e2.flat();
113 double k2 = e2.flat();
115 output << k1 <<
" " << k2 <<
"\n";
117 if ( !(
equals(k1,keyValue1)) || !(
equals(k2,keyValue2)) ) {
118 std::cout <<
"???? checkInstanceSave failed for " << e.name() <<
"\n";
120 output <<
"???? checkInstanceSave failed for " << e.name() <<
"\n";
128template <
class E,
class D>
131 assert( &
dynamic_cast<E &
>(d.engine()) );
133 output <<
"checkSaveDistribution with " << d.engine().name()
134 <<
", " << d.name() <<
"\n";
137 double keyValue1, keyValue2, keyValue3, keyValue4;
138 for (
int i=0; i<nth; i++) r += d();
139 {std::ofstream os (
"instance_distribution.save"); os << d.engine() << d;}
144 {std::ofstream os (
"instance2_distribution.save"); os << d.engine() << d;}
147 long pr =
output.precision(20);
149 output <<
"keyValue1 = " << keyValue1 <<
150 " keyValue2 = " << keyValue2 <<
"\n";
151 output <<
"keyValue3 = " << keyValue3 <<
152 " keyValue3 = " << keyValue4 <<
"\n";
157 { std::ifstream is (
"instance_distribution.save"); is >> e >> d2;}
160 { std::ifstream is (
"instance2_distribution.save"); is >> e >> d2;}
164 pr =
output.precision(20);
165 output <<
"k1 = " << k1 <<
166 " k2 = " << k2 <<
"\n";
167 output <<
"k3 = " << k3 <<
168 " k4 = " << k4 <<
"\n";
173 std::cout <<
"???? Incorrect restored value for distribution "
176 output <<
"???? Incorrect restored value for distribution "
187 assert( &
dynamic_cast<E &
>(d.
engine()) );
190 <<
", " << d.
name() <<
"\n";
191 double __attribute__ ((unused)) r = 0;
193 double keyValue1, keyValue2, keyValue3, keyValue4;
194 for (
int i=0; i<nth; i++) r += d();
195 {std::ofstream os (
"instance_distribution.save"); os << d.
engine() << d;}
200 {std::ofstream os (
"instance2_distribution.save"); os << d.
engine() << d;}
203 long pr =
output.precision(20);
205 output <<
"keyValue1 = " << keyValue1 <<
206 " keyValue2 = " << keyValue2 <<
"\n";
207 output <<
"keyValue3 = " << keyValue3 <<
208 " keyValue3 = " << keyValue4 <<
"\n";
214 { std::ifstream is (
"instance_distribution.save"); is >> e >> d2;}
217 { std::ifstream is (
"instance2_distribution.save"); is >> e >> d2;}
221 pr =
output.precision(20);
222 output <<
"k1 = " << k1 <<
223 " k2 = " << k2 <<
"\n";
224 output <<
"k3 = " << k3 <<
225 " k4 = " << k4 <<
"\n";
230 std::cout <<
"???? Incorrect restored value for distribution "
233 output <<
"???? Incorrect restored value for distribution "
246 stat |= checkSaveDistribution<E,RandGauss> (d,33); }
248 stat |= checkSaveDistribution<E,RandGauss> (d,34); }
250 stat |= checkSaveDistribution<E,RandGaussQ> (d,33); }
252 stat |= checkSaveDistribution<E,RandGaussT> (d,33); }
254 stat |= checkSaveDistribution<E,RandBinomial> (d,33); }
255 {
RandFlat d(
new E(12576),12.5,35.0);
256 stat |= checkSaveDistribution<E,RandFlat> (d,33); }
258 stat |= checkSaveDistribution<E,RandBit> (d,31); }
260 stat |= checkSaveDistribution<E,RandBit> (d,32); }
262 stat |= checkSaveDistribution<E,RandBit> (d,33); }
264 stat |= checkSaveDistribution<E,RandBreitWigner> (d,33); }
266 stat |= checkSaveDistribution<E,RandChiSquare> (d,33); }
268 stat |= checkSaveDistribution<E,RandExponential> (d,33); }
270 stat |= checkSaveDistribution<E,RandGamma> (d,33); }
272 stat |= checkSaveDistribution<E,RandLandau> (d,33); }
274 stat |= checkSaveDistribution<E,RandStudentT> (d,33); }
281 stat |= checkSaveDistribution<E,RandPoisson> (d,33); }
283 stat |= checkSaveDistribution<E,RandPoisson> (d,34); }
285 stat |= checkSaveDistribution<E,RandPoisson> (d,35); }
287 stat |= checkSaveDistribution<E,RandPoisson> (d,36); }
289 stat |= checkSaveDistribution<E,RandPoisson> (d,37); }
291 stat |= checkSaveDistribution<E,RandPoisson> (d,38); }
293 stat |= checkSaveDistribution<E,RandPoisson> (d,39); }
295 stat |= checkSaveDistribution<E,RandPoissonQ> (d,33); }
297 stat |= checkSaveDistribution<E,RandPoissonQ> (d,32); }
299 stat |= checkSaveDistribution<E,RandPoissonQ> (d,31); }
301 stat |= checkSaveDistribution<E,RandPoissonQ> (d,30); }
303 stat |= checkSaveDistribution<E,RandPoissonQ> (d,33); }
305 stat |= checkSaveDistribution<E,RandPoissonQ> (d,34); }
307 stat |= checkSaveDistribution<E,RandPoissonQ> (d,34); }
309 stat |= checkSaveDistribution<E,RandPoissonT> (d,33); }
311 stat |= checkSaveDistribution<E,RandPoissonT> (d,33); }
313 stat |= checkSaveDistribution<E,RandPoissonT> (d,34); }
315 stat |= checkSaveDistribution<E,RandPoissonT> (d,34); }
317 stat |= checkSaveDistribution<E,RandPoissonT> (d,10); }
319 stat |= checkSaveDistribution<E,RandPoissonT> (d,11); }
321 stat |= checkSaveDistribution<E,RandPoissonT> (d,12); }
323 {std::vector<double> pdf;
325 for (
int i = 0; i < nbins; ++i)
326 pdf.push_back( 5*i + (10.5-i) * (10.5-i) );
328 stat |= checkRandGeneralDistribution<E> (d,33); }
341#ifdef TEST_ENGINE_NAMES
342 output <<
"\n=============================================\n";
344 output <<
"Check all engine names were entered correctly \n";
345 output <<
"=============================================\n\n";
347 stat |= checkEngineName<DRand48Engine >(
"DRand48Engine");
348 stat |= checkEngineName<DualRand >(
"DualRand");
349 stat |= checkEngineName<Hurd160Engine >(
"Hurd160Engine");
350 stat |= checkEngineName<Hurd288Engine >(
"Hurd288Engine");
351 stat |= checkEngineName<HepJamesRandom>(
"HepJamesRandom");
352 stat |= checkEngineName<MixMaxRng >(
"MixMaxRng");
353 stat |= checkEngineName<MTwistEngine >(
"MTwistEngine");
354 stat |= checkEngineName<RandEngine >(
"RandEngine");
355 stat |= checkEngineName<RanecuEngine >(
"RanecuEngine");
356 stat |= checkEngineName<Ranlux64Engine>(
"Ranlux64Engine");
357 stat |= checkEngineName<RanluxEngine >(
"RanluxEngine");
358 stat |= checkEngineName<RanluxppEngine>(
"RanluxppEngine");
359 stat |= checkEngineName<RanshiEngine >(
"RanshiEngine");
360 stat |= checkEngineName<TripleRand >(
"TripleRand");
363#ifdef TEST_INSTANCE_METHODS
364 output <<
"===========================================\n\n";
366 output <<
"Check instance methods for specific engines \n";
367 output <<
" specific engines and distributions\n";
368 output <<
"===========================================\n\n";
384 {std::vector<double> nonRand =
aSequence(500);
389 stat |= checkDistributions<DualRand>();
390 stat |= checkDistributions<Hurd160Engine>();
391 stat |= checkDistributions<Hurd288Engine>();
392 stat |= checkDistributions<HepJamesRandom>();
393 stat |= checkDistributions<MixMaxRng>();
394 stat |= checkDistributions<MTwistEngine>();
395 stat |= checkDistributions<Ranlux64Engine>();
396 stat |= checkDistributions<RanluxEngine>();
397 stat |= checkDistributions<RanluxppEngine>();
398 stat |= checkDistributions<RanshiEngine>();
399 stat |= checkDistributions<TripleRand>();
404 output <<
"\n=============================================\n\n";
407 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
408 output <<
"One or more problems detected: stat = " << stat <<
"\n";
410 output <<
"testInstanceRestore passed with no problems detected.\n";
413 if (stat == 0)
return 0;
414 if (stat > 0)
return -(stat|1);
virtual std::string name() const =0
void setRandomSequence(double *s, int n)
HepRandomEngine & engine()
int checkEngineInstanceSave(E &e)
int checkSaveDistribution(D &d, int nth)
int checkEngineName(const std::string &name)
std::ofstream output("testInstanceRestore.cout")
int checkRandGeneralDistribution(RandGeneral &d, int nth)
std::vector< double > aSequence(int n)
bool equals(double a, double b)
bool equals01(const std::vector< double > &ab)