39 #ifndef __CINT__ // need to exclude to avoid CINT re-defining them
59 TH1D *
h1 =
new TH1D(
"h1G",
"gaussian distribution from Unuran",100,-10,10);
60 TH1D *
h2 =
new TH1D(
"h2G",
"gaussian distribution from TRandom",100,-10,10);
62 cout <<
"\nTest using UNURAN string API \n\n";
66 if (! unr.
Init(
"normal()",
"method=arou") ) {
67 cout <<
"Error initializing unuran" << endl;
75 for (
int i = 0; i <
n; ++i) {
81 cout <<
"Time using Unuran method " << unr.
MethodName() <<
"\t=\t " << w.
CpuTime() << endl;
86 for (
int i = 0; i <
n; ++i) {
92 cout <<
"Time using TRandom::Gaus \t=\t " << w.
CpuTime() << endl;
108 double cdf(
double *
x,
double *p) {
115 cout <<
"\nTest 1D Continous distributions\n\n";
117 TH1D *
h1 =
new TH1D(
"h1BW",
"Breit-Wigner distribution from Unuran",100,-10,10);
118 TH1D *
h2 =
new TH1D(
"h2BW",
"Breit-Wigner distribution from GetRandom",100,-10,10);
123 double par[2] = {1,0};
137 std::string method =
"tdr";
145 if (!unr.
Init(dist,method) ) {
146 cout <<
"Error initializing unuran" << endl;
156 for (
int i = 0; i <
n; ++i) {
162 cout <<
"Time using Unuran method " << unr.
MethodName() <<
"\t=\t " << w.
CpuTime() << endl;
165 for (
int i = 0; i <
n; ++i) {
171 cout <<
"Time using TF1::GetRandom() \t=\t " << w.
CpuTime() << endl;
179 std::cout <<
" chi2 test of UNURAN vs GetRandom generated histograms: " << std::endl;
187 double sigma_x = p[0];
188 double sigma_y = p[1];
189 double sigma_z = p[2];
191 double u = x[0] / sigma_x ;
192 double v = x[1] / sigma_y ;
193 double w = x[2] / sigma_z ;
194 double c = 1 - rho*rho ;
196 *
exp (-(u * u - 2 * rho * u * v + v * v + w*w) / (2 * c));
203 cout <<
"\nTest Multidimensional distributions\n\n";
205 TH3D *
h1 =
new TH3D(
"h13D",
"gaussian 3D distribution from Unuran",50,-10,10,50,-10,10,50,-10,10);
206 TH3D *
h2 =
new TH3D(
"h23D",
"gaussian 3D distribution from GetRandom",50,-10,10,50,-10,10,50,-10,10);
211 double par[3] = {2,2,0.5};
221 std::string method =
"hitro";
222 if ( ! unr.
Init(dist,method) ) {
223 cout <<
"Error initializing unuran" << endl;
231 for (
int i = 0; i <
NGEN; ++i) {
233 h1->
Fill(x[0],x[1],x[2]);
237 cout <<
"Time using Unuran method " << unr.
MethodName() <<
"\t=\t\t " << w.
CpuTime() << endl;
251 for (
int i = 0; i <
NGEN; ++i) {
253 h2->
Fill(x[0],x[1],x[2]);
257 cout <<
"Time using TF1::GetRandom \t\t=\t " << w.
CpuTime() << endl;
263 std::cout <<
" chi2 test of UNURAN vs GetRandom generated histograms: " << std::endl;
277 cout <<
"\nTest Discrete distributions\n\n";
279 TH1D *
h1 =
new TH1D(
"h1PS",
"Unuran Poisson prob",20,0,20);
280 TH1D *
h2 =
new TH1D(
"h2PS",
"Poisson dist from TRandom",20,0,20);
293 bool ret = unr.
Init(dist2,
"dari");
300 for (
int i = 0; i <
n; ++i) {
302 h1->
Fill(
double(k) );
306 cout <<
"Time using Unuran method " << unr.
MethodName() <<
"\t=\t\t " << w.
CpuTime() << endl;
309 for (
int i = 0; i <
n; ++i) {
312 cout <<
"Time using TRandom::Poisson " <<
"\t=\t\t " << w.
CpuTime() << endl;
319 std::cout <<
" chi2 test of UNURAN vs TRandom generated histograms: " << std::endl;
331 cout <<
"\nTest Empirical distributions using smoothing\n\n";
335 const int Ndata = 1000;
337 for (
int i = 0; i < Ndata; ++i) {
344 TH1D * h0 =
new TH1D(
"h0Ref",
"Starting data",100,-10,10);
345 TH1D *
h1 =
new TH1D(
"h1Unr",
"Unuran unbin Generated data",100,-10,10);
346 TH1D * h1b =
new TH1D(
"h1bUnr",
"Unuran bin Generated data",100,-10,10);
347 TH1D *
h2 =
new TH1D(
"h2GR",
"Data from TH1::GetRandom",100,-10,10);
349 h0->
FillN(Ndata,x,0,1);
359 if (!unr.
Init(dist))
return;
360 for (
int i = 0; i <
n; ++i) {
365 cout <<
"Time using Unuran unbin " << unr.
MethodName() <<
"\t=\t\t " << w.
CpuTime() << endl;
370 if (!unr.
Init(binDist))
return;
371 for (
int i = 0; i <
n; ++i) {
375 cout <<
"Time using Unuran bin " << unr.
MethodName() <<
"\t=\t\t " << w.
CpuTime() << endl;
378 for (
int i = 0; i <
n; ++i) {
381 cout <<
"Time using TH1::GetRandom " <<
"\t=\t\t " << w.
CpuTime() << endl;
406 c1 =
new TCanvas(
"c1_unuranMulti",
"Multidimensional distribution",10,10,1000,1000);
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
double dist(Rotation3D const &r1, Rotation3D const &r2)
virtual void SetParameters(const Double_t *params)
virtual Double_t GetRandom()
Return a random number following this function shape.
void SetProbSum(double sum)
set the value of the sum of the probabilities in the given domain
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
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 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...
virtual Double_t Chi2Test(const TH1 *h2, Option_t *option="UU", Double_t *res=0) const
chi^{2} test for comparing weighted and unweighted histograms
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
R__EXTERN TStyle * gStyle
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
void SetMode(int mode)
set the mode of the distribution (location of maximum probability)
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
int SampleDiscr()
Sample discrete distributions User is responsible for having previously correctly initialized with TU...
bool SampleMulti(double *x)
Sample multidimensional distributions User is responsible for having previously correctly initialized...
double gaus3d(double *x, double *p)
double distr(double *x, double *p)
static struct mg_connection * fc(struct mg_context *ctx)
virtual Double_t GetRandom() const
return a random number distributed according the histogram bin contents.
void Stop()
Stop the stopwatch.
TUnuranDiscrDist class for one dimensional discrete distribution.
double breitwigner_pdf(double x, double gamma, double x0=0)
Probability density function of Breit-Wigner distribution, which is similar, just a different definit...
TUnuranEmpDist class for describing empiral distributions.
double breitwigner_cdf(double x, double gamma, double x0=0)
Cumulative distribution function (lower tail) of the Breit_Wigner distribution and it is similar (jus...
virtual void SetLineColor(Color_t lcolor)
R__EXTERN TSystem * gSystem
virtual void Draw(Option_t *option="")
Draw this histogram with options.
3-D histogram with a double per channel (see TH1 documentation)}
A 3-Dim function with parameters.
double poisson(double *x, double *p)
void SetOptFit(Int_t fit=1)
The type of information about fit parameters printed in the histogram statistics box can be selected ...
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
virtual void GetRandom3(Double_t &xrandom, Double_t &yrandom, Double_t &zrandom)
Return 3 random numbers following this function shape.
const std::string & MethodName() const
used Unuran method
virtual void SetMarkerStyle(Style_t mstyle=1)
Int_t Fill(Double_t)
Invalid Fill method.
TUnuranMultiContDist class describing multi dimensional continuous distributions. ...
R__EXTERN TRandom * gRandom
1-D histogram with a double per channel (see TH1 documentation)}
double poisson_pdf(unsigned int n, double mu)
Probability density function of the Poisson distribution.
TUnuranContDist class describing one dimensional continuous distribution.
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
double cdf(double *x, double *p)
virtual void FillN(Int_t ntimes, const Double_t *x, const Double_t *w, Int_t stride=1)
Fill this histogram with an array x and weights w.
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
virtual void SetParameter(Int_t param, Double_t value)
virtual Int_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
virtual void Update()
Update canvas pad buffers.
virtual void SetNpz(Int_t npz=30)
Set the number of points used to draw the function.