StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
randomTest1.cc
1 /***************************************************************************
2  *
3  * $Id: randomTest1.cc,v 1.2 2003/09/02 17:59:38 perev Exp $
4  *
5  * Author: Brian Lasiuk, May 1998
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: randomTest1.cc,v $
13  * Revision 1.2 2003/09/02 17:59:38 perev
14  * gcc 3.2 updates + WarnOff
15  *
16  * Revision 1.1 1999/02/17 12:44:01 ullrich
17  * New Revision
18  *
19  * Revision 1.1 1999/01/23 00:26:50 ullrich
20  * Initial Revision
21  *
22  **************************************************************************/
23 #include <Stiostream.h>
24 #include <string>
25 #include "StGlobals.hh"
26 #include "StPrompt.hh"
27 #include "Random.h"
28 
29 // the random engines
30 #include "JamesRandom.h"
31 #include "RanecuEngine.h"
32 #include "RanluxEngine.h"
33 #include "DRand48Engine.h"
34 #include "RandEngine.h"
35 
36 // the different distributions
37 #include "RandFlat.h"
38 #include "RandPoisson.h"
39 #include "RandExponential.h"
40 #include "RandGauss.h"
41 #include "RandBreitWigner.h"
42 
43 // --------------------- MAIN -------------------------- //
44 int main()
45 {
46  HepJamesRandom engine; // default engine
47  RanluxEngine engine2;
48 
49  RandFlat flatDistribution(engine);
50  RandGauss gaussDistribution(engine);
51  RandExponential exponentialDistribution(engine);
52  RandPoisson poissonDistribution(engine);
53  RandBreitWigner breitWignerDistribution(engine);
54 
55  const int size=5; // array size
56  const int numberOfNumbers = 10; // # of numbers to generate
57 
58  int *vecI = new int[size]; // StInt vecI[size]
59  long *vecL = new long[size];
60  double *vec = new double[size]; // StDouble vec[size];
61 
62  StInt distribution=1;
63 
64  // counters
65  int i, jj;
66 
67  do {
68  cout << "(1) Flat" << "\n"
69  << "(2) Gaussian" << "\n"
70  << "(3) Exponential" << "\n"
71  << "(4) Poissonian" << "\n"
72  << "(5) Breit-Wigner" << endl;
73 
74  StPrompt("Which Distribution?", distribution);
75 
76  if(distribution>0 && distribution<6)
77  break;
78 
79  } while(true);
80 
81 
82  double mean = 2;
83  double width = 10;
84  double cut = 4;
85 
86  // Single numbers:
87 
88  StDouble flatNumber;
89  StInt flatINumber;
90  StDouble gaussNumber;
91  StDouble exponentialNumber;
92  StInt poissonNumber;
93  StDouble bwNumber;
94 
95  switch(distribution) {
96  case 1:
97  cout << "Flat Distribution:" << endl;
98  for(jj=0; jj<numberOfNumbers; jj++) {
99  flatNumber = flatDistribution.shoot();
100  PR(flatNumber);
101  }
102  cout << endl;
103  for(jj=0; jj<numberOfNumbers; jj++) {
104  flatNumber = flatDistribution.shoot(width);
105  PR(flatNumber);
106  }
107  cout << endl;
108  for(jj=0; jj<numberOfNumbers; jj++) {
109  flatNumber = flatDistribution.shoot(width,width+5);
110  PR(flatNumber);
111  }
112  cout << endl;
113  for(jj=0; jj<numberOfNumbers; jj++) {
114  flatINumber =
115  flatDistribution.shootInt(width);
116  PR(flatINumber);
117  }
118  cout << endl;
119  for(jj=0; jj<numberOfNumbers; jj++) {
120  flatINumber = (int) flatDistribution.shoot(width,width+5);
121  PR(flatINumber);
122  }
123  cout << endl;
124  for(jj=0; jj<numberOfNumbers; jj++) {
125  flatINumber = flatDistribution.shootBit();
126  PR(flatINumber);
127  }
128  cout << "Specify an Engine" << endl;
129  for(jj=0; jj<numberOfNumbers; jj++) {
130  flatNumber = flatDistribution.shoot(&engine2);
131  PR(flatNumber);
132  }
133  cout << endl;
134  for(jj=0; jj<numberOfNumbers; jj++) {
135  flatNumber = flatDistribution.shoot(&engine2, width);
136  PR(flatNumber);
137  }
138  cout << endl;
139  for(jj=0; jj<numberOfNumbers; jj++) {
140  flatNumber = flatDistribution.shoot(&engine2, width,width+5);
141  PR(flatNumber);
142  }
143  cout << endl;
144  for(jj=0; jj<numberOfNumbers; jj++) {
145  flatINumber = flatDistribution.shootInt(&engine2, width);
146  PR(flatINumber);
147  }
148  cout << endl;
149  for(jj=0; jj<numberOfNumbers; jj++) {
150  flatINumber = (int) flatDistribution.shoot(&engine2, width,width+5);
151  PR(flatINumber);
152  }
153  cout << endl;
154  for(jj=0; jj<numberOfNumbers; jj++) {
155  flatINumber = flatDistribution.shootBit(&engine2);
156  PR(flatINumber);
157  }
158  cout << "ARRAYs of numbers" << endl;
159  flatDistribution.shootArray(size,vec);
160  for(i=0; i<size; i++)
161  cout << "i " << *(vec+i) << endl;
162 
163  cout << endl;
164  flatDistribution.shootArray(size,vec, width, width+10);
165  for(i=0; i<size; i++)
166  cout << "i " << *(vec+i) << endl;
167 
168  cout << endl;
169  flatDistribution.shootArray(&engine2, size,vec);
170  for(i=0; i<size; i++)
171  cout << "i " << *(vec+i) << endl;
172 
173  cout << endl;
174  flatDistribution.shootArray(&engine2, size,vec, width, width+10);
175  for(i=0; i<size; i++)
176  cout << "i " << *(vec+i) << endl;
177 
178  cout << "operator()" << endl;
179  for(i=0; i<size; i++) {
180  cout << "flatDistribution() " << flatDistribution() << endl;
181  }
182  break;
183 
184  case 2:
185  cout << "Gaussian Distribution:" << endl;
186  for(jj=0; jj<numberOfNumbers; jj++) {
187  gaussNumber = gaussDistribution.shoot();
188  PR(gaussNumber);
189  }
190  for(jj=0; jj<numberOfNumbers; jj++) {
191  gaussNumber = gaussDistribution.shoot(mean,width);
192  PR(gaussNumber);
193  }
194  for(jj=0; jj<numberOfNumbers; jj++) {
195  gaussNumber = gaussDistribution.shoot(&engine2);
196  PR(gaussNumber);
197  }
198  for(jj=0; jj<numberOfNumbers; jj++) {
199  gaussNumber = gaussDistribution.shoot(&engine2,mean,width);
200  PR(gaussNumber);
201  }
202  for(jj=0; jj<numberOfNumbers; jj++) {
203  gaussNumber = gaussDistribution.fire();
204  PR(gaussNumber);
205  }
206  for(jj=0; jj<numberOfNumbers; jj++) {
207  gaussNumber = gaussDistribution.fire(mean,width);
208  PR(gaussNumber);
209  }
210  cout << "Arrays" << endl;
211  gaussDistribution.shootArray(size,vec,mean,width);
212  for(i=0; i<size; i++)
213  cout << "i " << *(vec+i) << endl;
214  cout << endl;
215  gaussDistribution.shootArray(&engine2,size,vec,mean,width);
216  for(i=0; i<size; i++)
217  cout << "i " << *(vec+i) << endl;
218  cout << endl;
219  gaussDistribution.fireArray(size,vec,mean,width);
220  for(i=0; i<size; i++)
221  cout << "i " << *(vec+i) << endl;
222 
223  break;
224  case 3:
225  cout << "Exponential Distribution:" << endl;
226  for(jj=0; jj<numberOfNumbers; jj++) {
227  exponentialNumber = exponentialDistribution.shoot();
228  PR(exponentialNumber);
229  }
230  for(jj=0; jj<numberOfNumbers; jj++) {
231  exponentialNumber = exponentialDistribution.shoot(mean);
232  PR(exponentialNumber);
233  }
234  for(jj=0; jj<numberOfNumbers; jj++) {
235  exponentialNumber = exponentialDistribution.fire();
236  PR(exponentialNumber);
237  }
238  for(jj=0; jj<numberOfNumbers; jj++) {
239  exponentialNumber = exponentialDistribution.fire(mean);
240  PR(exponentialNumber);
241  }
242  cout << "Specify Engine" << endl;
243  for(jj=0; jj<numberOfNumbers; jj++) {
244  exponentialNumber = exponentialDistribution.shoot(&engine2);
245  PR(exponentialNumber);
246  }
247  for(jj=0; jj<numberOfNumbers; jj++) {
248  exponentialNumber = exponentialDistribution.shoot(&engine2,mean);
249  PR(exponentialNumber);
250  }
251  cout << "Arrays" << endl;
252  exponentialDistribution.shootArray(size,vec,mean);
253  for(i=0; i<size; i++)
254  cout << "i " << *(vec+i) << endl;
255  cout << endl;
256  exponentialDistribution.shootArray(&engine2,size,vec,mean);
257  for(i=0; i<size; i++)
258  cout << "i " << *(vec+i) << endl;
259  cout << endl;
260  exponentialDistribution.fireArray(size,vec,mean);
261  for(i=0; i<size; i++)
262  cout << "i " << *(vec+i) << endl;
263 
264  break;
265  case 4:
266  for(jj=0; jj<numberOfNumbers; jj++) {
267  poissonNumber = poissonDistribution.shoot();
268  PR(poissonNumber);
269  }
270  for(jj=0; jj<numberOfNumbers; jj++) {
271  poissonNumber = poissonDistribution.shoot(mean);
272  PR(poissonNumber);
273  }
274  for(jj=0; jj<numberOfNumbers; jj++) {
275  poissonNumber = poissonDistribution.fire();
276  PR(poissonNumber);
277  }
278  for(jj=0; jj<numberOfNumbers; jj++) {
279  poissonNumber = poissonDistribution.fire(mean);
280  PR(poissonNumber);
281  }
282  cout << "Specify Engine" << endl;
283  for(jj=0; jj<numberOfNumbers; jj++) {
284  poissonNumber = poissonDistribution.shoot(&engine2);
285  PR(poissonNumber);
286  }
287  for(jj=0; jj<numberOfNumbers; jj++) {
288  poissonNumber = poissonDistribution.shoot(&engine2,mean);
289  PR(poissonNumber);
290  }
291  cout << "Arrays" << endl;
292  poissonDistribution.shootArray(size,vecL,mean);
293  for(i=0; i<size; i++)
294  cout << "i " << *(vecL+i) << endl;
295  cout << endl;
296  poissonDistribution.shootArray(&engine2,size,vecL,mean);
297  for(i=0; i<size; i++)
298  cout << "i " << *(vecL+i) << endl;
299  cout << endl;
300  poissonDistribution.fireArray(size,vecL,mean);
301  for(i=0; i<size; i++)
302  cout << "i " << *(vecL+i) << endl;
303 
304  break;
305  case 5:
306  cout << "Breit-Wigner Distribution:" << endl;
307  for(jj=0; jj<numberOfNumbers; jj++) {
308  bwNumber = breitWignerDistribution.shoot(mean, width);
309  PR(bwNumber);
310  }
311  for(jj=0; jj<numberOfNumbers; jj++) {
312  bwNumber = breitWignerDistribution.shoot(mean, width, cut);
313  PR(bwNumber);
314  }
315  for(jj=0; jj<numberOfNumbers; jj++) {
316  bwNumber = breitWignerDistribution.shootM2(mean, width);
317  PR(bwNumber);
318  }
319  for(jj=0; jj<numberOfNumbers; jj++) {
320  bwNumber = breitWignerDistribution.shootM2(mean, width, cut);
321  PR(bwNumber);
322  }
323  cout << "Specify an engine" << endl;
324  for(jj=0; jj<numberOfNumbers; jj++) {
325  bwNumber = breitWignerDistribution.shoot(&engine2, mean, width);
326  PR(bwNumber);
327  }
328  for(jj=0; jj<numberOfNumbers; jj++) {
329  bwNumber = breitWignerDistribution.shoot(&engine2, mean, width, cut);
330  PR(bwNumber);
331  }
332  for(jj=0; jj<numberOfNumbers; jj++) {
333  bwNumber = breitWignerDistribution.shootM2(&engine2, mean, width);
334  PR(bwNumber);
335  }
336  for(jj=0; jj<numberOfNumbers; jj++) {
337  bwNumber = breitWignerDistribution.shootM2(&engine2, mean, width, cut);
338  PR(bwNumber);
339  }
340  for(jj=0; jj<numberOfNumbers; jj++) {
341  bwNumber = breitWignerDistribution.fire(mean, width, cut);
342  PR(bwNumber);
343  }
344  for(jj=0; jj<numberOfNumbers; jj++) {
345  bwNumber = breitWignerDistribution.fireM2(mean, width, cut);
346  PR(bwNumber);
347  }
348  cout << endl;
349  cout << "ARRAYS:" << endl;
350  breitWignerDistribution.shootArray(size, vec,mean, width, cut);
351  for(i=0; i<size; i++)
352  cout << "i " << *(vec+i) << endl;
353  cout << endl;
354  breitWignerDistribution.shootArray(&engine2, size, vec,mean, width, cut);
355  for(i=0; i<size; i++)
356  cout << "i " << *(vec+i) << endl;
357  cout << endl;
358  breitWignerDistribution.fireArray(size, vec,mean, width, cut);
359  for(i=0; i<size; i++)
360  cout << "i " << *(vec+i) << endl;
361 
362  break;
363  default:
364  break;
365  }
366 
367  delete [] vecI;
368  delete [] vecL;
369  delete [] vec;
370 
371  return 0;
372 }