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