35 #include "CLHEP/Random/RandFlat.h"
36 #include "CLHEP/Random/RandGauss.h"
37 #include "CLHEP/Random/MTwistEngine.h"
38 #include "CLHEP/Random/JamesRandom.h"
39 #include "CLHEP/Random/RanluxEngine.h"
40 #include "CLHEP/Random/Ranlux64Engine.h"
41 #include "CLHEP/Random/RanecuEngine.h"
42 #include "CLHEP/Random/Hurd160Engine.h"
43 #include "CLHEP/Random/Hurd288Engine.h"
44 #include "CLHEP/Random/RanshiEngine.h"
45 #include "CLHEP/Random/DualRand.h"
46 #include "CLHEP/Random/TripleRand.h"
48 using namespace CLHEP;
60 std::cout <<
"Test Generation of Gaussian Numbers \n\n";
63 if (! unr.
Init(
"normal()",
"method=arou") ) {
64 std::cout <<
"Error initializing unuran" << std::endl;
75 for (
int i = 0; i <
n; ++i)
80 std::cout <<
"Time using Unuran method arou =\t " << time <<
"\tns/call" << std::endl;
83 if (! unr.
Init(
"normal()",
"method=tdr") ) {
84 std::cout <<
"Error initializing unuran" << std::endl;
88 for (
int i = 0; i <
n; ++i)
93 std::cout <<
"Time using Unuran method tdr =\t " << time <<
"\tns/call" << std::endl;
95 if (! unr.
Init(
"normal()",
"method=hinv") ) {
96 std::cout <<
"Error initializing unuran" << std::endl;
100 for (
int i = 0; i <
n; ++i)
105 std::cout <<
"Time using Unuran method hinv =\t " << time <<
"\tns/call" << std::endl;
108 for (
int i = 0; i <
n; ++i)
112 std::cout <<
"Time using TRandom::Gaus =\t " << time <<
"\tns/call" << std::endl;
117 for (
int i = 0; i < n/2; ++i)
121 std::cout <<
"Time using TRandom::Rannor =\t " << time <<
"\tns/call" << std::endl;
127 for (
int i = 0; i <
n; ++i)
131 std::cout <<
"Time using GSL::Gaus =\t\t " << time <<
"\tns/call" << std::endl;
135 for (
int i = 0; i <
n; ++i)
139 std::cout <<
"Time using GSL::GausBM = \t " << time <<
"\tns/call" << std::endl;
143 for (
int i = 0; i <
n; ++i)
147 std::cout <<
"Time using GSL::GausR =\t " << time <<
"\tns/call" << std::endl;
153 if (! unr.
Init(
"normal()",
"method=cstd;variant=2") ) {
154 std::cout <<
"Error initializing unuran" << std::endl;
158 for (
int i = 0; i <
n; ++i)
163 std::cout <<
"Time using Unuran GausPolarR =\t " << time <<
"\tns/call" << std::endl;
167 if (! unr.
Init(
"normal()",
"method=cstd;variant=3") ) {
168 std::cout <<
"Error initializing unuran" << std::endl;
172 for (
int i = 0; i <
n; ++i)
177 std::cout <<
"Time using Unuran Gaus K-R =\t " << time <<
"\tns/call" << std::endl;
179 if (! unr.
Init(
"normal()",
"method=cstd;variant=6") ) {
180 std::cout <<
"Error initializing unuran" << std::endl;
184 for (
int i = 0; i <
n; ++i)
189 std::cout <<
"Time using Unuran Gaus exp6 =\t " << time <<
"\tns/call" << std::endl;
200 MTwistEngine eng(111);
203 for (
int i = 0; i <
n; ++i)
207 std::cout <<
"Time using CLHEP::Gaus =\t " << time <<
"\tns/call" << std::endl;
210 std::cout <<
"\nTest uniform generator\n" << std::endl;
212 for (
int i = 0; i <
n; ++i)
216 std::cout <<
"Time using gRandom::Rndm =\t " << time <<
"\tns/call" << std::endl;
220 for (
int i = 0; i <
n; ++i)
224 std::cout <<
"Time using TRandom1::Rndm =\t " << time <<
"\tns/call" << std::endl;
228 for (
int i = 0; i <
n; ++i)
232 std::cout <<
"Time using TRandom2::Rndm =\t " << time <<
"\tns/call" << std::endl;
237 for (
int i = 0; i <
n; ++i)
241 std::cout <<
"Time using CLHEP::MT =\t\t " << time <<
"\tns/call" << std::endl;
247 for (
int i = 0; i <
n; ++i)
251 std::cout <<
"Time using CLHEP::Ranecu =\t " << time <<
"\tns/call" << std::endl;
257 for (
int i = 0; i <
n; ++i)
261 std::cout <<
"Time using CLHEP::Hard160 =\t " << time <<
"\tns/call" << std::endl;
267 for (
int i = 0; i <
n; ++i)
272 std::cout <<
"Time using CLHEP::Hard288 =\t " << time <<
"\tns/call" << std::endl;
278 for (
int i = 0; i <
n; ++i)
283 std::cout <<
"Time using CLHEP::DualRand =\t " << time <<
"\tns/call" << std::endl;
289 for (
int i = 0; i <
n; ++i)
294 std::cout <<
"Time using CLHEP::TripleRand =\t " << time <<
"\tns/call" << std::endl;
300 for (
int i = 0; i <
n; ++i)
305 std::cout <<
"Time using CLHEP::Runshi =\t " << time <<
"\tns/call" << std::endl;
311 for (
int i = 0; i <
n; ++i)
316 std::cout <<
"Time using CLHEP::RunLux =\t " << time <<
"\tns/call" << std::endl;
322 for (
int i = 0; i <
n; ++i)
326 std::cout <<
"Time using CLHEP::RunLux64 =\t " << time <<
"\tns/call" << std::endl;
332 for (
int i = 0; i <
n; ++i)
337 std::cout <<
"Time using CLHEP::HepJames =\t " << time <<
"\tns/call" << std::endl;
344 std::cout <<
"\n\nTest quality of Unuran arou" << std::endl;
345 if (! unr.
Init(
"normal()",
"method=arou") ) {
346 std::cout <<
"Error initializing unuran" << std::endl;
350 TH1D *
h1 =
new TH1D(
"h1",
"cdf on the data ",1000,0,1);
351 for (
int i = 0; i < 1000000; ++i) {
356 new TCanvas(
"c1_unuranGaus",
"unuran Gaus CDF");
361 std::cout <<
"CDF Uniform Fit: chi2 = " << f->
GetChisquare() <<
" ndf = " << f->
GetNDF() << std::endl;
362 std::cout <<
"Fit Prob = " << f->
GetProb() << std::endl;
366 std::cerr <<
"\nERROR: UnuranSimple Test:\t Failed !!!!";
369 std::cerr <<
"\nUnuranSimple Test:\t OK !" << std::endl;
376 int main(
int argc,
char **argv)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
double Sample()
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::...
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
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...
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
int main(int argc, char **argv)
virtual Double_t Rndm(Int_t i=0)
TausWorth generator from L'Ecuyer, uses as seed 3x32bits integers Use a mask of 0xffffffffUL to make ...
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
virtual Int_t GetNDF() const
Return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
static const double x2[5]
void Stop()
Stop the stopwatch.
The Ranlux Random number generator class.
Double_t GetChisquare() const
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
double normal_cdf(double x, double sigma=1, double x0=0)
Cumulative distribution function of the normal (Gaussian) distribution (lower tail).
double Gaus(double mean=0, double sigma=1)
virtual void Draw(Option_t *option="")
Draw this histogram with options.
unsigned int r1[N_CITIES]
virtual Double_t GetProb() const
Return the fit probability.
R__EXTERN TRandom * gRandom
1-D histogram with a double per channel (see TH1 documentation)}
static const double x1[5]
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
virtual TF1 * GetFunction(const char *name) const
Return pointer to function with name.
unsigned int r2[N_CITIES]
Documentation for the Random class.
virtual Double_t Rndm(Int_t i=0)
return a random number in ]0,1]