StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
randomTest2.cc
1 /***************************************************************************
2  *
3  * $Id: randomTest2.cc,v 1.3 2003/09/02 17:59:38 perev Exp $
4  *
5  * Author: Brian Lasiuk, May 1998
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: randomTest2.cc,v $
13  * Revision 1.3 2003/09/02 17:59:38 perev
14  * gcc 3.2 updates + WarnOff
15  *
16  * Revision 1.2 1999/12/21 15:14:58 ullrich
17  * Modified to cope with new compiler version on Sun (CC5.0).
18  *
19  * Revision 1.1 1999/02/17 12:44:02 ullrich
20  * New Revision
21  *
22  * Revision 1.1 1999/01/23 00:26:51 ullrich
23  * Initial Revision
24  *
25  **************************************************************************/
26 #include <Stiostream.h>
27 #include "StGlobals.hh"
28 #include "Random.h"
29 
30 // the random engines
31 #include "JamesRandom.h"
32 #include "RanluxEngine.h"
33 
34 // the different distributions
35 #include "RandFlat.h"
36 #include "RandPoisson.h"
37 #include "RandExponential.h"
38 #include "RandGauss.h"
39 #include "RandBreitWigner.h"
40 
41 // --------------------- MAIN -------------------------- //
42 int main()
43 {
44  int i, jj;
45 
46  const StInt size = 5;
47  const StInt numberOfNumbers = 5;
48 
49  // Generator must be given an engine:
50  // - HepJamesRandom used by default
51 
52  HepJamesRandom engine1;
53  RanluxEngine engine2;
54 
55  //HepRandom quasiRandom(engine); // pass engine by reference
56  //HepRandom quasiRandom(&engine); // pass engine by pointer
57 
58  //engine.showStatus(); // show status of engine
59 
60  long seed = 7;
61  HepRandom quasiRandom; // or quasiRandom(seed);
62 
63  StDouble quasiRandomNumber =
64  quasiRandom.flat();
65  PR(quasiRandomNumber);
66 
67  int *vecI = new int[size]; // StInt vecI[size]
68  double *vec = new double[size]; // StDouble vec[size];
69 
70  quasiRandom.flatArray(size,vec);
71 
72  cout << "\nPseudo-Random numbers from a flat distribution." << endl;
73  for(int ii=0; ii<size; ii++)
74  cout << "i " << *(vec+ii) << endl;
75 
76  PR(quasiRandom.getTheSeed());
77  HepJamesRandom jr;
78 
79  cout << "All these numbers are the same:" << endl;
80  for(int iii=0; iii<size; iii++) {
81  jr.saveStatus();
82  PR(jr.flat());
83  jr.restoreStatus(); // restoring status keeps engine same
84  }
85 
86  cout << "\nDifferent distributions:" << endl;
87 
88  RandFlat flatDistribution(engine1);
89  RandGauss gaussDistribution(engine2);
90  RandExponential exponentialDistribution(engine1);
91  RandPoisson poissonDistribution(engine2);
92  RandBreitWigner breitWignerDistribution(engine2);
93 
94  double mean = 2;
95  double width = 10;
96 
97  cout << "Numbers from a Flat Distribution:" << endl;
98  for(jj=0; jj<numberOfNumbers; jj++) {
99  StDouble flatNumber =
100  flatDistribution.fire(width,width+10);
101  PR(flatNumber);
102  }
103 
104  cout << "\nNumbers from a Gaussian Distribution:" << endl;
105  for(jj=0; jj<numberOfNumbers; jj++) {
106  StDouble gaussNumber =
107  gaussDistribution.shoot();
108  PR(gaussNumber);
109  }
110 
111  cout << "\nNumbers from an Exponential Distribution:" << endl;
112  for(jj=0; jj<numberOfNumbers; jj++) {
113  StDouble exponentialNumber =
114  exponentialDistribution.shoot(&engine2, mean);
115  PR(exponentialNumber);
116  }
117 
118  cout << "\nNumbers from a Poissonian Distribution:" << endl;
119  for(jj=0; jj<numberOfNumbers; jj++) {
120  StDouble poissonNumber =
121  poissonDistribution.shoot();
122  PR(poissonNumber);
123  }
124 
125  cout << "\nAn Array of Numbers from a Breit-Wigner Distribution:" << endl;
126  breitWignerDistribution.shootArray(size, vec);
127 
128  for(i=0; i<size; i++)
129  cout << "(" << i << ") " << *(vec+i) << endl;
130 
131  return 0;
132 }