ROOT  6.06/09
Reference Guide
RooRandom.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //////////////////////////////////////////////////////////////////////////////
18 //
19 // BEGIN_HTML
20 // This class provides a static interface for generating random numbers.
21 // By default a private copy of TRandom3 is used to generate all random numbers.
22 // END_HTML
23 //
24 #include <cassert>
25 
26 #include "RooFit.h"
27 
28 #include "RooRandom.h"
29 #include "RooRandom.h"
31 
32 #include "TRandom3.h"
33 
34 using namespace std;
35 
37  ;
38 
39 
40 TRandom* RooRandom::_theGenerator = 0;
41 RooQuasiRandomGenerator* RooRandom::_theQuasiGenerator = 0;
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Return a pointer to a singleton random-number generator
51 /// implementation. Creates the object the first time it is called.
52 
54 {
55  if (!_theGenerator) _theGenerator= new TRandom3();
56  return _theGenerator;
57 }
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// set the random number generator; takes ownership of the object passed as parameter
62 
64 {
65  if (_theGenerator) delete _theGenerator;
66  _theGenerator = gen;
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Return a pointer to a singleton quasi-random generator
71 /// implementation. Creates the object the first time it is called.
72 
74 {
75  if(!_theQuasiGenerator) _theQuasiGenerator= new RooQuasiRandomGenerator();
76  return _theQuasiGenerator;
77 }
78 
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Return a number uniformly distributed from (0,1)
82 
84 {
85  return generator->Rndm();
86 }
87 
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Fill the vector provided with random numbers uniformly distributed from (0,1)
91 
92 void RooRandom::uniform(UInt_t dimension, Double_t vector[], TRandom *generator)
93 {
94  generator->RndmArray(dimension, vector);
95 }
96 
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Return an integer uniformly distributed from [0,n-1]
100 
102 {
103  return generator->Integer(n);
104 }
105 
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Return a Gaussian random variable with mean 0 and variance 1.
109 
111 {
112  return generator->Gaus();
113 }
114 
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Return a quasi-random number in the range (0,1) using the
118 /// Niederreiter base 2 generator described in Bratley, Fox, Niederreiter,
119 /// ACM Trans. Model. Comp. Sim. 2, 195 (1992).
120 
122 {
123  return generator->generate(dimension,vector);
124 }
Random number generator class based on M.
Definition: TRandom3.h:29
static Double_t gaussian(TRandom *generator=randomGenerator())
Return a Gaussian random variable with mean 0 and variance 1.
Definition: RooRandom.cxx:110
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition: TRandom.cxx:548
static UInt_t integer(UInt_t max, TRandom *generator=randomGenerator())
Return an integer uniformly distributed from [0,n-1].
Definition: RooRandom.cxx:101
bool Bool_t
Definition: RtypesCore.h:59
static Bool_t quasi(UInt_t dimension, Double_t vector[], RooQuasiRandomGenerator *generator=quasiGenerator())
Return a quasi-random number in the range (0,1) using the Niederreiter base 2 generator described in ...
Definition: RooRandom.cxx:121
STL namespace.
ClassImp(RooRandom)
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:320
Bool_t generate(UInt_t dimension, Double_t vector[])
Generate the next number in the sequence for the specified dimension.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
static RooQuasiRandomGenerator * quasiGenerator()
Return a pointer to a singleton quasi-random generator implementation.
Definition: RooRandom.cxx:73
static void setRandomGenerator(TRandom *gen)
set the random number generator; takes ownership of the object passed as parameter ...
Definition: RooRandom.cxx:63
unsigned int UInt_t
Definition: RtypesCore.h:42
static struct Guard guard
Definition: RooRandom.h:48
static TRandom * _theGenerator
Definition: RooRandom.h:43
static Double_t uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Definition: RooRandom.cxx:83
double Double_t
Definition: RtypesCore.h:55
static RooQuasiRandomGenerator * _theQuasiGenerator
Definition: RooRandom.h:44
const Int_t n
Definition: legend1.C:16