Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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\file RooRandom.cxx
19\class RooRandom
20\ingroup Roofitcore
21
22This class provides a static interface for generating random numbers.
23By default a private copy of TRandom3 is used to generate all random numbers.
24**/
25#include <cassert>
26
27#include "RooRandom.h"
29
30#include "TRandom3.h"
31
32using namespace std;
33
35 ;
36
37
41
42////////////////////////////////////////////////////////////////////////////////
43
46
47////////////////////////////////////////////////////////////////////////////////
48/// Return a pointer to a singleton random-number generator
49/// implementation. Creates the object the first time it is called.
50
52{
54 return _theGenerator;
55}
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// set the random number generator; takes ownership of the object passed as parameter
60
62{
63 if (_theGenerator) delete _theGenerator;
64 _theGenerator = gen;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Return a pointer to a singleton quasi-random generator
69/// implementation. Creates the object the first time it is called.
70
72{
74 return _theQuasiGenerator;
75}
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// Return a number uniformly distributed from (0,1)
80
81double RooRandom::uniform(TRandom *generator)
82{
83 return generator->Rndm();
84}
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Fill the vector provided with random numbers uniformly distributed from (0,1)
89
90void RooRandom::uniform(UInt_t dimension, double vector[], TRandom *generator)
91{
92 generator->RndmArray(dimension, vector);
93}
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Return an integer uniformly distributed from [0,n-1]
98
100{
101 return generator->Integer(n);
102}
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// Return a Gaussian random variable with mean 0 and variance 1.
107
108double RooRandom::gaussian(TRandom *generator)
109{
110 return generator->Gaus();
111}
112
113
114////////////////////////////////////////////////////////////////////////////////
115/// Return a quasi-random number in the range (0,1) using the
116/// Niederreiter base 2 generator described in Bratley, Fox, Niederreiter,
117/// ACM Trans. Model. Comp. Sim. 2, 195 (1992).
118
119bool RooRandom::quasi(UInt_t dimension, double vector[], RooQuasiRandomGenerator *generator)
120{
121 return generator->generate(dimension,vector);
122}
#define ClassImp(name)
Definition Rtypes.h:377
This class generates the quasi-random (aka "low discrepancy") sequence for dimensions up to 12 using ...
bool generate(UInt_t dimension, double vector[])
Generate the next number in the sequence for the specified dimension.
This class provides a static interface for generating random numbers.
Definition RooRandom.h:24
static RooQuasiRandomGenerator * quasiGenerator()
Return a pointer to a singleton quasi-random generator implementation.
Definition RooRandom.cxx:71
static double uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Definition RooRandom.cxx:81
static double gaussian(TRandom *generator=randomGenerator())
Return a Gaussian random variable with mean 0 and variance 1.
static struct Guard guard
Definition RooRandom.h:48
static bool quasi(UInt_t dimension, double vector[], RooQuasiRandomGenerator *generator=quasiGenerator())
Return a quasi-random number in the range (0,1) using the Niederreiter base 2 generator described in ...
static TRandom * _theGenerator
random number generator
Definition RooRandom.h:43
static UInt_t integer(UInt_t max, TRandom *generator=randomGenerator())
Return an integer uniformly distributed from [0,n-1].
Definition RooRandom.cxx:99
static void setRandomGenerator(TRandom *gen)
set the random number generator; takes ownership of the object passed as parameter
Definition RooRandom.cxx:61
static RooQuasiRandomGenerator * _theQuasiGenerator
quasi random number sequence generator
Definition RooRandom.h:44
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:51
Random number generator class based on M.
Definition TRandom3.h:27
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
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:274
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition TRandom.cxx:588
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:552
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:360
const Int_t n
Definition legend1.C:16