20 #include "CLHEP/Random/RandFlat.h"
21 #include "CLHEP/Random/RandPoissonT.h"
22 #include "CLHEP/Random/RandPoisson.h"
23 #include "CLHEP/Random/RandGauss.h"
24 #include "CLHEP/Random/RandGaussQ.h"
25 #include "CLHEP/Random/RandGaussT.h"
26 #include "CLHEP/Random/RandBinomial.h"
27 #include "CLHEP/Random/JamesRandom.h"
32 #define PI 3.14159265358979323846264338328
43 using namespace ROOT::Math;
45 using namespace CLHEP;
58 double prob = h1.
Chi2TestX(&h2,chi2,ndf,igood,
"UU");
59 std::cout <<
"\nTest " <<
name <<
" chi2 = " << chi2 <<
" ndf " << ndf <<
" prob = " << prob;
60 if (igood) std::cout <<
" \t\t" <<
" igood = " << igood;
61 std::cout << std::endl;
63 std::string cname=
"c1_" +
name;
64 std::string ctitle=
"Test of " +
name;
65 TCanvas *
c1 =
new TCanvas(cname.c_str(), ctitle.c_str(),200,10,800,600);
77 if (type.find(
"GSL") != std::string::npos )
78 return "ROOT::Math::Random";
79 else if (type.find(
"TRandom") != std::string::npos )
81 else if (type.find(
"UnuRan") != std::string::npos )
83 else if (type.find(
"Rand") != std::string::npos )
99 for (
int i = 0; i <
n; ++i) {
100 int n = r.Poisson(mu );
106 std::cout <<
"Poisson - mu = " << mu <<
"\t\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
108 <<
"\t(ns/call)" << std::endl;
127 const double alpha = 0.875;
128 unsigned int m =
static_cast<unsigned int> ((alpha*mu) );
137 x = sqm * y + m - 1.;
142 while ( v > (1 + y * y) *
std::exp ( (m - 1) *
std::log (x / (m - 1)) - sqm * y));
147 return k + r.Binomial( m-1, mu/x);
208 t = 0.9*(1.0 + y*
y)*
std::exp(em*alxm - TMath::LnGamma(em + 1.0) -
g);
209 }
while( r.Rndm() >
t );
211 return static_cast<unsigned int> (em);
227 for (
int i = 0; i <
n; ++i) {
229 int n = r.PoissonD(mu);
237 <<
"\t(ns/call)" << std::endl;
245 void testPoissonCLHEP(
R & r,
double mu,
TH1D & h) {
253 for (
int i = 0; i <
n; ++i) {
255 int n =
static_cast<unsigned int> (
r(mu) ) ;
261 std::cout <<
"Poisson - mu = " << mu <<
"\t\t" <<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
263 <<
"\t(ns/call)" << std::endl;
266 testPoissonCLHEP(r,mu,h);
270 void testGausCLHEP(
R & r,
double mu,
double sigma,
TH1D & h) {
278 for (
int i = 0; i < n2; ++i) {
279 for (
int j = 0; j < n1; ++j) {
280 double x =
r(mu,sigma );
287 std::cout <<
"Gaussian - mu,sigma = " << mu <<
" , " << sigma <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
289 <<
"\t(ns/call)" << std::endl;
292 testGausCLHEP(r,mu,sigma,h);
296 void testFlatCLHEP(
R & r,
TH1D & h) {
303 for (
int i = 0; i <
n; ++i) {
313 <<
"\t(ns/call)" << std::endl;
332 for (
int i = 0; i <
n; ++i) {
342 <<
"\t(ns/call)" << std::endl;
359 for (
int i = 0; i <
n; ++i) {
360 double x = r.Gaus(mu,sigma );
367 std::cout <<
"Gaussian - mu,sigma = " << mu <<
" , " << sigma <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
369 <<
"\t(ns/call)" << std::endl;
386 for (
int i = 0; i <
n; ++i) {
387 double x = r.Landau();
394 std::cout <<
"Landau " <<
"\t\t\t\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
396 <<
"\t(ns/call)" << std::endl;
414 for (
int i = 0; i <
n; ++i) {
415 double x = r.BreitWigner(mu,gamma );
421 std::cout <<
"Breit-Wigner - m,g = " << mu <<
" , " << gamma <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
423 <<
"\t(ns/call)" << std::endl;
440 for (
int i = 0; i <
n; ++i) {
441 double x =
double( r.Binomial(ntot,p ) );
447 std::cout <<
"Binomial - ntot,p = " << ntot <<
" , " << p <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
449 <<
"\t(ns/call)" << std::endl;
465 for (
int i = 0; i <
n; ++i) {
466 double x =
double(
r(ntot,p ) );
472 std::cout <<
"Binomial - ntot,p = " << ntot <<
" , " << p <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
474 <<
"\t(ns/call)" << std::endl;
486 std::vector<double> p(nbins);
488 for (
int i = 0; i <
nbins; ++i) {
500 for (
int i = 0; i <
n; ++i) {
501 std::vector<unsigned int> multDist = r.Multinomial(ntot,p);
509 std::cout <<
"Multinomial - nb, ntot = " << nbins <<
" , " << ntot <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/n <<
" \t"
511 <<
"\t(ns/call)" << std::endl;
517 for (
int i = 0; i <
n; ++i) {
518 for (
int j = 0; j <
nbins; ++j) {
519 double y = r.Poisson(ntot*p[j]);
525 std::cout <<
"Multi-Poisson - nb, ntot = " << nbins <<
" , " << ntot <<
"\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/n <<
" \t"
527 <<
"\t(ns/call)" << std::endl;
548 for (
int i = 0; i <
n; ++i) {
549 double x = r.Exp(1.);
555 std::cout <<
"Exponential " <<
"\t\t\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
557 <<
"\t(ns/call)" << std::endl;
574 for (
int i = 0; i <
n; ++i) {
583 std::cout <<
"Circle " <<
"\t\t\t\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
585 <<
"\t(ns/call)" << std::endl;
598 TH2D hxy(
"hxy",
"xy",100,-1.1,1.1,100,-1.1,1.1);
599 TH3D h3d(
"h3d",
"sphere",100,-1.1,1.1,100,-1.1,1.1,100,-1.1,1.1);
600 TH1D hz(
"hz",
"z",100,-1.1,1.1);
611 for (
int i = 0; i <
n; ++i) {
632 TCanvas *
c1 =
new TCanvas(
"c1_xyz",
"sphere",220,20,800,900);
646 std::cout <<
"Sphere " <<
"\t\t\t\t"<<
findName(r) <<
"\tTime = " << w.
RealTime()*1.0E9/
NEVT <<
" \t"
648 <<
"\t(ns/call)" << std::endl;
659 std::cout <<
"***************************************************\n";
660 std::cout <<
" TEST RANDOM DISTRIBUTIONS NEVT = " <<
NEVT << std::endl;
661 std::cout <<
"***************************************************\n\n";
677 TH1D hf1(
"hf1",
"FLAT ROOT",nch,xmin,xmax);
678 TH1D hf2(
"hf2",
"Flat GSL",nch,xmin,xmax);
687 TH1D hf3(
"hf3",
"Flat CLHEP",nch,xmin,xmax);
688 testFlatCLHEP(crf,hf3);
695 std::cout << std::endl;
700 nch =
std::min(
int(xmax-xmin),1000);
701 TH1D hp1(
"hp1",
"Poisson ROOT",nch,xmin,xmax);
702 TH1D hp2(
"hp2",
"Poisson GSL",nch,xmin,xmax);
703 TH1D hp3(
"hp3",
"Poisson UNR",nch,xmin,xmax);
709 RandPoissonT crp(eng);
710 TH1D hp4(
"hp4",
"Poisson CLHEP",nch,xmin,xmax);
711 testPoissonCLHEP(crp,mu,hp4);
715 testDiff(hp1,hp2,
"Poisson ROOT-GSL");
716 testDiff(hp1,hp3,
"Poisson ROOT-UNR");
718 testDiff(hp1,hp4,
"Poisson ROOT-CLHEP");
722 std::cout << std::endl;
724 TH1D hg1(
"hg1",
"Gaussian ROOT",nch,xmin,xmax);
725 TH1D hg2(
"hg2",
"Gaussian GSL",nch,xmin,xmax);
726 TH1D hg3(
"hg3",
"Gaussian UNURAN",nch,xmin,xmax);
735 TH1D hg4(
"hg4",
"Gauss CLHEP",nch,xmin,xmax);
736 testGausCLHEP(crg,mu,
sqrt(mu),hg4);
737 RandGaussQ crgQ(eng);
738 testGausCLHEP(crgQ,mu,
sqrt(mu),hg4);
739 RandGaussT crgT(eng);
740 testGausCLHEP(crgT,mu,
sqrt(mu),hg4);
744 testDiff(hg1,hg2,
"Gaussian ROOT-GSL");
745 testDiff(hg1,hg3,
"Gaussian ROOT_UNR");
748 std::cout << std::endl;
750 TH1D hl1(
"hl1",
"Landau ROOT",300,0,50);
751 TH1D hl2(
"hl2",
"Landau GSL",300,0,50);
758 std::cout << std::endl;
760 TH1D hbw1(
"hbw1",
"BreitWigner ROOT",nch,xmin,xmax);
761 TH1D hbw2(
"hbw2",
"BreitWigner GSL",nch,xmin,xmax);
769 std::cout << std::endl;
776 TH1D hb1(
"hb1",
"Binomial ROOT",nch,xmin,xmax);
777 TH1D hb2(
"hb2",
"Binomial GSL",nch,xmin,xmax);
778 TH1D hb3(
"hb3",
"Binomial UNR",nch,xmin,xmax);
785 RandBinomial crb(eng);
786 TH1D hb4(
"hb4",
"Binomial CLHEP",nch,xmin,xmax);
791 testDiff(hb1,hb2,
"Binomial ROOT-GSL");
792 testDiff(hb1,hb3,
"Binomial ROOT-UNR");
795 std::cout << std::endl;
797 TH1D hmt1(
"hmt1",
"Multinomial GSL",30,-3,3);
798 TH1D hmt2(
"hmt2",
"Multi-Poisson GSL",30,-3,3);
799 TH1D hmt3(
"hmt3",
"Gaus",30,-3,3);
803 testDiff(hmt1,hmt2,
"Multinomial-Poisson");
804 testDiff(hmt1,hmt3,
"Multinomial-gaus");
808 std::cout << std::endl;
810 TH1D he1(
"he1",
"Exp ROOT",300,0,20);
811 TH1D he2(
"he2",
"Exp GSL",300,0,20);
818 std::cout << std::endl;
820 TH1D hc1(
"hc1",
"Circle ROOT",300,-
PI,
PI);
821 TH1D hc2(
"hc2",
"Circle GSL",300,-
PI,
PI);
829 std::cout << std::endl;
831 TH1D hs1(
"hs1",
"Sphere-Phi ROOT",300,-
PI,
PI);
832 TH1D hs2(
"hs2",
"Sphere-Phi GSL ",300,-
PI,
PI);
833 TH1D hs3(
"hs3",
"Sphere-Theta ROOT",300,0,
PI);
834 TH1D hs4(
"hs4",
"Sphere-Theta GSL ",300,0,
PI);
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Random number generator class based on M.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
virtual Double_t Chi2TestX(const TH1 *h2, Double_t &chi2, Int_t &ndf, Int_t &igood, Option_t *option="UU", Double_t *res=0) const
The computation routine of the Chisquare test.
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
void testPoisson(R &r, double mu, TH1D &h)
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
virtual Int_t GetNbinsX() const
void testSphere(R &r, TH1D &h1, TH1D &h2)
virtual Double_t GetEntries() const
return the current number of entries
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
void testExp(R &r, TH1D &h)
virtual Double_t GetBinWidth(Int_t bin) const
return bin width for 1D historam Better to use h1.GetXaxis().GetBinWidth(bin)
static const double x2[5]
void Stop()
Stop the stopwatch.
void testBinomialCLHEP(R &r, int ntot, double p, TH1D &h)
unsigned int genPoisson2(R &r, double mu)
virtual Double_t GetBinLowEdge(Int_t bin) const
return bin lower edge for 1D historam Better to use h1.GetXaxis().GetBinLowEdge(bin) ...
void testGaus(R &r, double mu, double sigma, TH1D &h)
double normal_cdf(double x, double sigma=1, double x0=0)
Cumulative distribution function of the normal (Gaussian) distribution (lower tail).
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
void testBinomial(R &r, int ntot, double p, TH1D &h)
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
3-D histogram with a double per channel (see TH1 documentation)}
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
void testMultinomial(R &r, int ntot, TH1D &h1, TH1D &h2)
Int_t Fill(Double_t)
Invalid Fill method.
1-D histogram with a double per channel (see TH1 documentation)}
static const double x1[5]
void testDiff(TH1D &h1, TH1D &h2, const std::string &name="")
double atan2(double, double)
void testBreitWigner(R &r, double mu, double gamma, TH1D &h)
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
void testLandau(R &r, TH1D &h)
void testCircle(R &r, TH1D &h)
void testPoisson2(R &r, double mu, TH1D &h)
std::string findName(const R &r)
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Int_t Fill(Double_t)
Invalid Fill method.
Documentation for the Random class.
2-D histogram with a double per channel (see TH1 documentation)}
unsigned int genPoisson(R &r, double mu)
void testFlat(R &r, TH1D &h)