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
30 using namespace CLHEP;
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 <<
" <--> "
80 template <
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 int pr=
output.precision(20);
101 for (
int i=0; i<100; i++) r += e.flat();
102 {std::ofstream os (
"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 (
"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";
128 template <
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 (
"distribution.save1"); os << d.engine() << d;}
144 {std::ofstream os (
"distribution.save2"); os << d.engine() << d;}
147 int pr =
output.precision(20);
149 output <<
"keyValue1 = " << keyValue1 <<
150 " keyValue2 = " << keyValue2 <<
"\n";
151 output <<
"keyValue3 = " << keyValue3 <<
152 " keyValue3 = " << keyValue4 <<
"\n";
157 { std::ifstream is (
"distribution.save1"); is >> e >> d2;}
160 { std::ifstream is (
"distribution.save2"); 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";
193 double keyValue1, keyValue2, keyValue3, keyValue4;
194 for (
int i=0; i<nth; i++) r += d();
195 {std::ofstream os (
"distribution.save1"); os << d.
engine() << d;}
200 {std::ofstream os (
"distribution.save2"); os << d.
engine() << d;}
203 int pr =
output.precision(20);
205 output <<
"keyValue1 = " << keyValue1 <<
206 " keyValue2 = " << keyValue2 <<
"\n";
207 output <<
"keyValue3 = " << keyValue3 <<
208 " keyValue3 = " << keyValue4 <<
"\n";
214 { std::ifstream is (
"distribution.save1"); is >> e >> d2;}
217 { std::ifstream is (
"distribution.save2"); 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<MTwistEngine >(
"MTwistEngine");
353 stat |= checkEngineName<RandEngine >(
"RandEngine");
354 stat |= checkEngineName<RanecuEngine >(
"RanecuEngine");
355 stat |= checkEngineName<Ranlux64Engine>(
"Ranlux64Engine");
356 stat |= checkEngineName<RanluxEngine >(
"RanluxEngine");
357 stat |= checkEngineName<RanshiEngine >(
"RanshiEngine");
358 stat |= checkEngineName<TripleRand >(
"TripleRand");
361 #ifdef TEST_INSTANCE_METHODS
362 output <<
"===========================================\n\n";
363 output <<
" Part III\n";
364 output <<
"Check instance methods for specific engines \n";
365 output <<
" specific engines and distributions\n";
366 output <<
"===========================================\n\n";
380 {std::vector<double> nonRand =
aSequence(500);
385 stat |= checkDistributions<DualRand>();
386 stat |= checkDistributions<Hurd160Engine>();
387 stat |= checkDistributions<Hurd288Engine>();
388 stat |= checkDistributions<HepJamesRandom>();
389 stat |= checkDistributions<MTwistEngine>();
390 stat |= checkDistributions<Ranlux64Engine>();
391 stat |= checkDistributions<RanluxEngine>();
392 stat |= checkDistributions<RanshiEngine>();
393 stat |= checkDistributions<TripleRand>();
398 output <<
"\n=============================================\n\n";
401 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
402 output <<
"One or more problems detected: stat = " << stat <<
"\n";
404 output <<
"testInstanceRestore passed with no problems detected.\n";
407 if (stat == 0)
return 0;
408 if (stat > 0)
return -(stat|1);