This commit was generated by cvs2svn to compensate for changes in r165,
[u/mrichter/AliRoot.git] / RALICE / AliRandom.h
CommitLineData
d88f97cc 1#ifndef ALIRANDOM_H
2#define ALIRANDOM_H
3///////////////////////////////////////////////////////////////////////////
4// Class AliRandom
5// Generate universal random numbers on all common machines.
6// Available distributions : Uniform, Gaussian, Poisson and
7// User defined function
8//
9// Features :
10// ----------
11// 1) Period = 2**144
12// 2) Same sequence of 24-bit real numbers on all common machines
13//
14// Reference :
15// -----------
16// G.Marsaglia and A.Zaman, FSU-SCRI-87-50, Florida State University, 1987.
17//
18// Coding example :
19// ----------------
20//
21// Float_t rndm; // Variable to hold a single random number
22// const Int_t n=1000;
23// Float_t rvec[n]; // Vector to hold n random numbers
24//
25// AliRandom r; // Create a Random object with default sequence
26//
27// rndm=r.Uniform(); // Provide a uniform random number in <0,1>
28// Float_t a=3.;
29// Float_t b=5.;
30// rndm=r.Uniform(a,b); // Provide a uniform random number in <a,b>
31// r.Uniform(rvec,n); // Provide n uniform randoms in <0,1> in rvec
32// r.Uniform(rvec,n,a,b); // Provide n uniform randoms in <a,b> in rvec
33//
34// rndm=r.Gauss(); // Provide a Gaussian random number with
35// // mean=0 and sigma=1
36// Float_t mean=25.;
37// Float_t sigma=5.;
38// rndm=r.Gauss(mean,sigma); // Provide a Gaussian random number
39// // with specified mean and sigma
40// r.Gauss(rvec,n); // n Gaussian randoms mean=0 sigma=1
41// r.Gauss(rvec,n,mean,sigma); // n Gaussian randoms with specified
42// // mean and sigma
43//
44// rndm=r.Poisson(mean); // Provide a Poisson random number with
45// // specified mean
46// r.Poisson(rvec,nmean); // n Poisson randoms with specified mean
47//
48// Int_t seed=1837724
49// AliRandom p(seed); // Create a Random object with specified seed.
50// // The sequence is started from scratch.
51// Int_t cnt1=25;
52// Int_t cnt2=8;
53// AliRandom q(seed,cnt1,cnt2); // Create a Random object with specified seed
54// // The sequence is started at the location
55// // denoted by the counters cnt1 and cnt2.
56//
57// q.Info(); // Print the current seed, cnt1 and cnt2 values.
58// q.GetSeed(); // Provide the current seed value.
59// q.GetCnt1(); // Provide the current cnt1 value.
60// q.GetCnt2(); // Provide the current cnt2 value.
61//
62// Float_t udist(Float_t x) // A user defined distribution
63// {
64// return x*x-4.*x;
65// }
66//
67// Int_t nbins=100;
68// q.SetUser(a,b,nbins,udist); // Initialise generator for udist distribution
69// q.User(); // Provide a random number according to the udist distribution
70// q.User(rvec,n); // Provide n randoms according to the udist distribution
71//
72// Float_t* x=new Float_t[nbins];
73// Float_t* y=new Float_t[nbins];
74//
75// ... code to fill x[] and y[] ..
76//
77// AliRandom s;
78// s.SetUser(x,y,nbins); // Initialise generator for (x[i],y[i]) distribution
79// s.User(); // Provide a random number according to the user distribution
80// s.User(rvec,n); // Provide n randoms according to the user distribution
81//
82// Notes :
83// -------
84// 1) Allowed seed values : 0 <= seed <= 921350143
85// Default seed = 53310452
86// 2) To ensure a unique sequence for each run, one can automatically
87// construct a seed value by e.g. using the date and time.
88// 3) Using the rvec facility saves a lot of CPU time for large n values.
89//
90//--- NvE 11-oct-1997 UU-SAP Utrecht
91///////////////////////////////////////////////////////////////////////////
92
93#include <iostream.h>
94#include <math.h>
95
96#include "TObject.h"
97
98class AliRandom : public TObject
99{
100 public:
101 AliRandom(); // Constructor with default sequence
102 AliRandom(Int_t seed); // Constructor with user defined seed
103 AliRandom(Int_t seed,Int_t cnt1,Int_t cnt2); // User defined starting point
104 ~AliRandom(); // Destructor
105 Int_t GetSeed(); // Provide current seed value
106 Int_t GetCnt1(); // Provide current counter value cnt1
107 Int_t GetCnt2(); // Provide current counter value cnt2
108 void Info(); // Print current seed, cnt1 and cnt2
109 Float_t Uniform(); // Uniform dist. within <0,1>
110 Float_t Uniform(Float_t a,Float_t b); // Uniform dist. within <a,b>
111 void Uniform(Float_t* vec,Int_t n); // n uniform randoms in <0,1>
112 void Uniform(Float_t* vec,Int_t n,Float_t a,Float_t b); // see above
113 Float_t Gauss(); // Gaussian dist. with mean=0 sigma=1
114 Float_t Gauss(Float_t mean,Float_t sigma); // Gaussian dist. with mean and sigma
115 void Gauss(Float_t* vec,Int_t n); // n Gaussian randoms mean=0 sigma=1
116 void Gauss(Float_t* vec,Int_t n,Float_t mean,Float_t sigma); // see above
117 Float_t Poisson(Float_t mean); // Poisson dist. with certain mean
118 void Poisson(Float_t* vec,Int_t n,Float_t mean); // n Poisson randoms with mean
119 void SetUser(Float_t a,Float_t b,Int_t n,Float_t (*f)(Float_t)); // User dist. f(x)
120 void SetUser(Float_t* x,Float_t* y,Int_t n); // User dist. arrays
121 Float_t User(); // Provide random in [a,b] according to user distribution
122 void User(Float_t* vec,Int_t n); // n randoms in [a,b] from user dist.
123
124 private:
125 Int_t fI,fJ,fSeed,fCnt1,fCnt2,fClip; // Indices, seed and counters
126 Float_t fU[97],fC,fCd,fCm; // The Fibonacci parameters
127 void Start(Int_t seed,Int_t cnt1,Int_t cnt2); // Start at certain point
128 void Unpack(Int_t seed,Int_t& i,Int_t& j,Int_t& k,Int_t& l); // Unpack the seed
129 void Uniform(Int_t n); // n uniform randoms for quick skipping
130 Int_t fNa; //! The number of bins of the area function
131 Float_t* fXa; //! The binned x values of the area function
132 Float_t* fYa; //! The corresponding y values of the area function
133 Float_t fYamin,fYamax; //! The min. and max. y values of the area function
134 Int_t* fIbins; //! The bin numbers of the random x candidates
135
136 ClassDef(AliRandom,1) // Class definition to enable ROOT I/O
137};
138#endif