CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testRandom.cc File Reference
#include "CLHEP/Units/GlobalPhysicalConstants.h"
#include "CLHEP/Random/Randomize.h"
#include <iostream>
#include <cstdlib>

Go to the source code of this file.

Functions

void init ()
 
void layout ()
 
void dist_layout ()
 
void user_layout ()
 
void start_test ()
 
int main ()
 

Variables

HepJamesRandom theJamesEngine
 
RandEngine theRandEngine
 
DRand48Engine theDRand48Engine
 
RanluxEngine theRanluxEngine (19780503, 4)
 
Ranlux64Engine theRanlux64Engine
 
RanluxppEngine theRanluxppEngine
 
RanecuEngine theRanecuEngine
 
Hurd160Engine theHurd160Engine
 
Hurd288Engine theHurd288Engine
 
MixMaxRng theMixMaxEngine
 
MTwistEngine theMTwistEngine
 
RanshiEngine theRanshiEngine
 
DualRand theDualRandEngine
 
TripleRand theTripleRandEngine
 

Function Documentation

◆ dist_layout()

void dist_layout ( )

Definition at line 94 of file testRandom.cc.

95{
96 float m1=3.0;
97 const int size=5;
98 double vect[size];
99
100 HepJamesRandom aJamesEngine;
101 RandEngine aRandEngine;
102 DRand48Engine aDRand48Engine;
103 RanluxEngine aRanluxEngine(19780503,4);
104 Ranlux64Engine aRanlux64Engine;
105 RanluxppEngine aRanluxppEngine;
106 RanecuEngine aRanecuEngine;
107 Hurd288Engine aHurd288Engine;
108 MixMaxRng aMixMaxEngine;
109 MTwistEngine aMTwistEngine;
110 RanshiEngine aRanshiEngine;
111 TripleRand aTripleRandEngine;
112
113 RandFlat aFlatObj(aJamesEngine);
114 RandExponential anExponentialObj(aRandEngine);
115 RandExpZiggurat anExpZigguratObj(aMixMaxEngine);
116 RandGauss aGaussObj(aDRand48Engine);
117 RandBreitWigner aBreitObj(aRanluxEngine);
118 RandPoisson aPoissonObj(aRanecuEngine);
119 RandBinomial aBinomialObj(aHurd288Engine);
120 RandChiSquare aChiSquareObj(aMTwistEngine);
121 RandGamma aGammaObj(aRanshiEngine);
122 RandStudentT aStudentTObj(aTripleRandEngine);
123
124 cout << " ----- Press <ENTER> to continue -----";
125 if ( cin.get() != '\n') exit(0);
126 cout << endl << endl;
127 cout << "-------------------- Shooting test on distribution objects --------------------" << endl;
128 cout << endl;
129 cout << " Flat ]0,1[ : " << aFlatObj.fire() << endl;
130 cout << " Flat ]0,5[ : " << aFlatObj.fire(5) << endl;
131 cout << " Flat ]-5,3[ : " << aFlatObj.fire(-5,3) << endl;
132 cout << " Exp (m=1) : " << anExponentialObj.fire() << endl;
133 cout << " Exp (m=3) : " << anExponentialObj.fire(3) << endl;
134 cout << " ExpZig (m=1) : " << anExpZigguratObj.fire() << endl;
135 cout << " ExpZig (m=3) : " << anExpZigguratObj.fire(3) << endl;
136 cout << " Gauss (m=1) : " << aGaussObj.fire() << endl;
137 cout << " Gauss (m=3,v=1) : " << aGaussObj.fire(3,1) << endl;
138 cout << " Wigner(1,0.2) : " << aBreitObj.fire(1,0.2) << endl;
139 cout << " Wigner(1,0.2,1) : " << aBreitObj.fire(1,0.2,1) << endl;
140 cout << " Wigner2(1,0.2) : " << aBreitObj.fireM2(1,0.2) << endl;
141 cout << " Wigner2(1,0.2,1) : " << aBreitObj.fireM2(1,0.2,1) << endl;
142 cout << " IntFlat [0,99[ : " << aFlatObj.fireInt(99) << endl;
143 cout << " IntFlat [-99,37[ : " << aFlatObj.fireInt(-99,37) << endl;
144 cout << " Poisson (m=3.0) : " << aPoissonObj.fire(m1) << endl;
145 cout << " Binomial(n=1,p=0.5) : " << aBinomialObj.fire() << endl;
146 cout << " Binomial(n=-5,p=0.3): " << aBinomialObj.fire(-5,0.3) << endl;
147 cout << " ChiSqr (a=1) : " << aChiSquareObj.fire() << endl;
148 cout << " ChiSqr (a=-5) : " << aChiSquareObj.fire(-5) << endl;
149 cout << " Gamma (k=1,l=1) : " << aGammaObj.fire() << endl;
150 cout << " Gamma (k=3,l=0.5) : " << aGammaObj.fire(3,0.5) << endl;
151 cout << " StudT (a=1) : " << aStudentTObj.fire() << endl;
152 cout << " StudT (a=2.5) : " << aStudentTObj.fire(2.5) << endl;
153 cout << endl;
154 cout << " Shooting an array of 5 flat numbers ..." << endl << endl;
155 aFlatObj.fireArray(size,vect);
156 for ( int i=0; i<size; ++i )
157 cout << " " << vect[i];
158 cout << endl << endl;
159 cout << " ----- Press <ENTER> to continue -----";
160 if ( cin.get() != '\n') exit(0);
161} // end dist_layout()
#define exit(x)

Referenced by start_test().

◆ init()

void init ( )

Definition at line 29 of file testRandom.cc.

30{
31 HepRandom r;
32 cout << "r=" << r() << endl;
33
34 cout << endl << endl;
35 cout << "---------------------------- Random shooting test -----------------------------" << endl;
36 cout << " -------------------- " << endl;
37 cout << " >>> Random Engines available <<<" << endl << endl;
38 cout << " > HepJamesRandom (default)" << endl;
39 cout << " > Rand" << endl;
40 cout << " > DRand48" << endl;
41 cout << " > Ranlux" << endl;
42 cout << " > Ranlux64" << endl;
43 cout << " > Ranluxpp" << endl;
44 cout << " > Ranecu" << endl;
45 cout << " > Hurd160" << endl;
46 cout << " > Hurd288" << endl;
47 cout << " > MixMax" << endl;
48 cout << " > MTwist" << endl;
49 cout << " > Ranshi" << endl;
50 cout << " > DualRand" << endl;
51 cout << " > TripleRand" << endl << endl;
52 cout << " ----- Press <ENTER> to continue -----";
53 if ( cin.get() != '\n') exit(0);
54 cout << endl;
55
56} // end init()

Referenced by CLHEP::HepDiagMatrix::HepDiagMatrix(), CLHEP::HepMatrix::HepMatrix(), CLHEP::HepSymMatrix::HepSymMatrix(), CLHEP::HepVector::HepVector(), and main().

◆ layout()

void layout ( )

Definition at line 58 of file testRandom.cc.

59{
60 float m1=3.0;
61 const int size=5;
62 double vect[size];
63
64 cout << " Flat ]0,1[ : " << RandFlat::shoot() << endl;
65 cout << " Flat ]0,5[ : " << RandFlat::shoot(5) << endl;
66 cout << " Flat ]-5,3[ : " << RandFlat::shoot(-5,3) << endl;
67 cout << " Exp (m=1) : " << RandExponential::shoot() << endl;
68 cout << " Exp (m=3) : " << RandExponential::shoot(3) << endl;
69 cout << " Gauss (m=1) : " << RandGauss::shoot() << endl;
70 cout << " Gauss (m=3,v=1) : " << RandGauss::shoot(3,1) << endl;
71 cout << " Wigner(1,0.2) : " << RandBreitWigner::shoot(1,0.2) << endl;
72 cout << " Wigner(1,0.2,1) : " << RandBreitWigner::shoot(1,0.2,1) << endl;
73 cout << " Wigner2(1,0.2) : " << RandBreitWigner::shootM2(1,0.2) << endl;
74 cout << " Wigner2(1,0.2,1) : " << RandBreitWigner::shootM2(1,0.2,1) << endl;
75 cout << " IntFlat [0,99[ : " << RandFlat::shootInt(99) << endl;
76 cout << " IntFlat [-99,37[ : " << RandFlat::shootInt(-99,37) << endl;
77 cout << " Poisson (m=3.0) : " << RandPoisson::shoot(m1) << endl;
78 cout << " Binomial(n=1,p=0.5) : " << RandBinomial::shoot() << endl;
79 cout << " Binomial(n=-5,p=0.3): " << RandBinomial::shoot(-5,0.3) << endl;
80 cout << " ChiSqr (a=1) : " << RandChiSquare::shoot() << endl;
81 cout << " ChiSqr (a=-5) : " << RandChiSquare::shoot(-5) << endl;
82 cout << " Gamma (k=1,l=1) : " << RandGamma::shoot() << endl;
83 cout << " Gamma (k=3,l=0.5) : " << RandGamma::shoot(3,0.5) << endl;
84 cout << " StudT (a=1) : " << RandStudentT::shoot() << endl;
85 cout << " StudT (a=2.5) : " << RandStudentT::shoot(2.5) << endl;
86 cout << endl;
87 cout << " Shooting an array of 5 flat numbers ..." << endl << endl;
88 RandFlat::shootArray(size,vect);
89 for ( int i=0; i<size; ++i )
90 cout << " " << vect[i];
91 cout << endl << endl;
92} // end layout()
static double shoot()
static double shootM2(double a=1.0, double b=0.2)
static double shoot(double a=1.0, double b=0.2)
static double shoot()
static long shootInt(long n)
static double shoot()
Definition: RandFlat.cc:63
static void shootArray(const int size, double *vect)
Definition: RandFlat.cc:67
static double shoot()
static double shoot()
Definition: RandGauss.cc:64
static long shoot(double mean=1.0)
Definition: RandPoisson.cc:95
static double shoot()

Referenced by start_test().

◆ main()

int main ( )

Definition at line 374 of file testRandom.cc.

374 {
375
376 init();
377 start_test();
378
379 return 0;
380}
void init()
Definition: testRandom.cc:29
void start_test()
Definition: testRandom.cc:273

◆ start_test()

void start_test ( )

Definition at line 273 of file testRandom.cc.

274{
275 cout << "------------------------- Test on HepJamesRandom ----------------------------" << endl;
276 cout << endl;
277 layout();
278 cout << " ----- Press <ENTER> to continue -----";
279 if ( cin.get() != '\n') exit(0);
280 cout << endl;
281 cout << "--------------------------- Test on RandEngine ------------------------------" << endl;
282 cout << endl;
284 layout();
285 cout << " ----- Press <ENTER> to continue -----";
286 if ( cin.get() != '\n') exit(0);
287 cout << endl;
288 cout << "------------------------- Test on DRand48Engine -----------------------------" << endl;
289 cout << endl;
291 layout();
292 cout << " ----- Press <ENTER> to continue -----";
293 if ( cin.get() != '\n') exit(0);
294 cout << endl;
295 cout << "--------------------- Test on RanluxEngine (luxury 4) ------------------------" << endl;
296 cout << endl;
298 layout();
299 cout << " ----- Press <ENTER> to continue -----";
300 if ( cin.get() != '\n') exit(0);
301 cout << endl;
302 cout << "------------------------- Test on Ranlux64Engine -----------------------------" << endl;
303 cout << endl;
305 layout();
306 cout << " ----- Press <ENTER> to continue -----";
307 if ( cin.get() != '\n') exit(0);
308 cout << endl;
309 cout << "------------------------- Test on RanluxppEngine -----------------------------" << endl;
310 cout << endl;
312 layout();
313 cout << " ----- Press <ENTER> to continue -----";
314 if ( cin.get() != '\n') exit(0);
315 cout << endl;
316 cout << "-------------------------- Test on RanecuEngine ------------------------------" << endl;
317 cout << endl;
319 layout();
320 cout << " ----- Press <ENTER> to continue -----";
321 if ( cin.get() != '\n') exit(0);
322 cout << endl;
323 cout << "------------------------- Test on Hurd160Engine ------------------------------" << endl;
324 cout << endl;
326 layout();
327 cout << " ----- Press <ENTER> to continue -----";
328 if ( cin.get() != '\n') exit(0);
329 cout << endl;
330 cout << "------------------------- Test on Hurd288Engine ------------------------------" << endl;
331 cout << endl;
333 layout();
334 cout << " ----- Press <ENTER> to continue -----";
335 if ( cin.get() != '\n') exit(0);
336 cout << endl;
337 cout << "-------------------------- Test on MixMaxEngine ------------------------------" << endl;
338 cout << endl;
340 layout();
341 cout << " ----- Press <ENTER> to continue -----";
342 if ( cin.get() != '\n') exit(0);
343 cout << endl;
344 cout << "-------------------------- Test on MTwistEngine ------------------------------" << endl;
345 cout << endl;
347 layout();
348 cout << " ----- Press <ENTER> to continue -----";
349 if ( cin.get() != '\n') exit(0);
350 cout << endl;
351 cout << "-------------------------- Test on RanshiEngine ------------------------------" << endl;
352 cout << endl;
354 layout();
355 cout << " ----- Press <ENTER> to continue -----";
356 if ( cin.get() != '\n') exit(0);
357 cout << endl;
358 cout << "------------------------- Test on DualRandEngine -----------------------------" << endl;
359 cout << endl;
361 layout();
362 cout << " ----- Press <ENTER> to continue -----";
363 if ( cin.get() != '\n') exit(0);
364 cout << endl;
365 cout << "------------------------ Test on TripleRandEngine ----------------------------" << endl;
366 cout << endl;
368 layout();
369 dist_layout();
370 user_layout();
371} // end start_test()
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:275
RandEngine theRandEngine
Definition: testRandom.cc:15
RanluxppEngine theRanluxppEngine
Definition: testRandom.cc:19
void user_layout()
Definition: testRandom.cc:163
RanshiEngine theRanshiEngine
Definition: testRandom.cc:25
MixMaxRng theMixMaxEngine
Definition: testRandom.cc:23
Hurd160Engine theHurd160Engine
Definition: testRandom.cc:21
Ranlux64Engine theRanlux64Engine
Definition: testRandom.cc:18
RanecuEngine theRanecuEngine
Definition: testRandom.cc:20
TripleRand theTripleRandEngine
Definition: testRandom.cc:27
DRand48Engine theDRand48Engine
Definition: testRandom.cc:16
DualRand theDualRandEngine
Definition: testRandom.cc:26
void dist_layout()
Definition: testRandom.cc:94
RanluxEngine theRanluxEngine(19780503, 4)
MTwistEngine theMTwistEngine
Definition: testRandom.cc:24
void layout()
Definition: testRandom.cc:58
Hurd288Engine theHurd288Engine
Definition: testRandom.cc:22

Referenced by main().

◆ user_layout()

void user_layout ( )

Definition at line 163 of file testRandom.cc.

164{
165 float m1=3.0;
166 const int size=5;
167 double vect[size];
168 char sel;
169 HepRandomEngine* anEngine;
170
171 cout << endl << endl;
172 cout << "-------------------- Shooting test skeeping the generator ---------------------" << endl;
173 cout << endl;
174 cout << " >>> Select a Random Engine <<<" << endl << endl;
175 cout << " a. HepJamesRandom (default)" << endl;
176 cout << " b. Rand" << endl;
177 cout << " c. DRand48" << endl;
178 cout << " d. Ranlux" << endl;
179 cout << " e. Ranlux64" << endl;
180 cout << " f. Ranecu" << endl;
181 cout << " g. Hurd160" << endl;
182 cout << " h. Hurd288" << endl;
183 cout << " i. MTwist" << endl;
184 cout << " j. Ranshi" << endl;
185 cout << " k. DualRand" << endl;
186 cout << " l. TripleRand" << endl;
187 cout << " m. MixMax" << endl << endl;
188 cout << " > ";
189 cin >> sel;
190 while ((sel!='a')&&(sel!='b')&&(sel!='c')&&(sel!='d')&&(sel!='e')&&
191 (sel!='f')&&(sel!='g')&&(sel!='h')&&(sel!='i')&&(sel!='j')&&
192 (sel!='k')&&(sel!='l')&&(sel!='m')) {
193 cout << endl << " >>> Choice not legal !! [a..m]<<<" << endl;
194 cin >> sel;
195 }
196
197 switch (sel) {
198 case 'a':
199 anEngine = &theJamesEngine;
200 break;
201 case 'b':
202 anEngine = &theRandEngine;
203 break;
204 case 'c':
205 anEngine = &theDRand48Engine;
206 break;
207 case 'd':
208 anEngine = &theRanluxEngine;
209 break;
210 case 'e':
211 anEngine = &theRanlux64Engine;
212 break;
213 case 'f':
214 anEngine = &theRanecuEngine;
215 break;
216 case 'g':
217 anEngine = &theHurd160Engine;
218 break;
219 case 'h':
220 anEngine = &theHurd288Engine;
221 break;
222 case 'i':
223 anEngine = &theMTwistEngine;
224 break;
225 case 'j':
226 anEngine = &theRanshiEngine;
227 break;
228 case 'k':
229 anEngine = &theDualRandEngine;
230 break;
231 case 'l':
232 anEngine = &theTripleRandEngine;
233 break;
234 case 'm':
235 anEngine = &theMixMaxEngine;
236 break;
237 default:
238 anEngine = &theJamesEngine;
239 break;
240 }
241 cout << endl;
242
243 cout << " Flat ]0,1[ : " << RandFlat::shoot(anEngine) << endl;
244 cout << " Flat ]0,5[ : " << RandFlat::shoot(anEngine,5) << endl;
245 cout << " Flat ]-5,3[ : " << RandFlat::shoot(anEngine,-5,3) << endl;
246 cout << " Exp (m=1) : " << RandExponential::shoot(anEngine) << endl;
247 cout << " Exp (m=3) : " << RandExponential::shoot(anEngine,3) << endl;
248 cout << " Gauss (m=1) : " << RandGauss::shoot(anEngine) << endl;
249 cout << " Gauss (m=3,v=1) : " << RandGauss::shoot(anEngine,3,1) << endl;
250 cout << " Wigner(1,0.2) : " << RandBreitWigner::shoot(anEngine,1,0.2) << endl;
251 cout << " Wigner(1,0.2,1) : " << RandBreitWigner::shoot(anEngine,1,0.2,1) << endl;
252 cout << " Wigner2(1,0.2) : " << RandBreitWigner::shootM2(anEngine,1,0.2) << endl;
253 cout << " Wigner2(1,0.2,1) : " << RandBreitWigner::shootM2(anEngine,1,0.2,1) << endl;
254 cout << " IntFlat [0,99[ : " << RandFlat::shootInt(anEngine,99) << endl;
255 cout << " IntFlat [-99,37[ : " << RandFlat::shootInt(anEngine,-99,37) << endl;
256 cout << " Poisson (m=3.0) : " << RandPoisson::shoot(anEngine,m1) << endl;
257 cout << " Binomial(n=1,p=0.5) : " << RandBinomial::shoot(anEngine) << endl;
258 cout << " Binomial(n=-5,p=0.3): " << RandBinomial::shoot(anEngine,-5,0.3) << endl;
259 cout << " ChiSqr (a=1) : " << RandChiSquare::shoot(anEngine) << endl;
260 cout << " ChiSqr (a=-5) : " << RandChiSquare::shoot(anEngine,-5) << endl;
261 cout << " Gamma (k=1,l=1) : " << RandGamma::shoot(anEngine) << endl;
262 cout << " Gamma (k=3,l=0.5) : " << RandGamma::shoot(anEngine,3,0.5) << endl;
263 cout << " StudT (a=1) : " << RandStudentT::shoot(anEngine) << endl;
264 cout << " StudT (a=2.5) : " << RandStudentT::shoot(anEngine,2.5) << endl;
265 cout << endl;
266 cout << " Shooting an array of 5 flat numbers ..." << endl << endl;
267 RandFlat::shootArray(anEngine,size,vect);
268 for ( int i=0; i<size; ++i )
269 cout << " " << vect[i];
270 cout << endl << endl;
271} // end layout()
HepJamesRandom theJamesEngine
Definition: testRandom.cc:14

Referenced by start_test().

Variable Documentation

◆ theDRand48Engine

DRand48Engine theDRand48Engine

Definition at line 16 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theDualRandEngine

DualRand theDualRandEngine

Definition at line 26 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theHurd160Engine

Hurd160Engine theHurd160Engine

Definition at line 21 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theHurd288Engine

Hurd288Engine theHurd288Engine

Definition at line 22 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theJamesEngine

HepJamesRandom theJamesEngine

Definition at line 14 of file testRandom.cc.

Referenced by user_layout().

◆ theMixMaxEngine

MixMaxRng theMixMaxEngine

Definition at line 23 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theMTwistEngine

MTwistEngine theMTwistEngine

Definition at line 24 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theRandEngine

RandEngine theRandEngine

Definition at line 15 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theRanecuEngine

RanecuEngine theRanecuEngine

Definition at line 20 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theRanlux64Engine

Ranlux64Engine theRanlux64Engine

Definition at line 18 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theRanluxEngine

RanluxEngine theRanluxEngine(19780503, 4) ( 19780503  ,
 
)

Referenced by start_test(), and user_layout().

◆ theRanluxppEngine

RanluxppEngine theRanluxppEngine

Definition at line 19 of file testRandom.cc.

Referenced by start_test().

◆ theRanshiEngine

RanshiEngine theRanshiEngine

Definition at line 25 of file testRandom.cc.

Referenced by start_test(), and user_layout().

◆ theTripleRandEngine

TripleRand theTripleRandEngine

Definition at line 27 of file testRandom.cc.

Referenced by start_test(), and user_layout().