47 TH1D * h0 =
new TH1D(
"h0",
"Landau ref data",nbin,xmin,xmax);
51 TH1D *
h1 =
new TH1D(
"h1",
"Landau source data",nbin,xmin,xmax);
64 std::cout <<
"Test Using 1D UnBinned data\n " << std::endl;
70 if (!unr.
Init(dist))
return -1;
74 TH1D * h2 =
new TH1D(
"h2",
"Landau from Unuran unbin generation",nbin,xmin,xmax);
75 for (
int i = 0; i <
n; ++i) {
80 std::cout <<
"Time using Unuran " << unr.
MethodName() <<
" \t=\t " << time <<
"\tns/call" << std::endl;
83 TH1D * h3 =
new TH1D(
"h3",
"h3",nbin,xmin,xmax);
84 for (
int i = 0; i <
n; ++i) {
89 std::cout <<
"Time using TH1::GetRandom() \t=\t " << time <<
"\tns/call" << std::endl;
92 std::cout <<
"\nTest quality UNURAN " << unr.
MethodName() <<
" (with h0)\t:\t";
93 double prob = h2->
Chi2Test(h1,
"UUP");
95 std::cerr <<
"Chi2 Test failed for UNURAN method " << unr.
MethodName() << std::endl;
98 std::cout <<
"\nTest quality UNURAN " << unr.
MethodName() <<
" (with ref)\t:\t";
101 std::cout <<
"Test quality TH1::GetRandom (with h1) \t:\t";
103 std::cout <<
"Test quality TH1::GetRandom (with ref) \t:\t";
105 std::cout <<
"Comparison UnuRan-TH1::GetRandom \t:\t";
110 TCanvas *
c1 =
new TCanvas(
"c1_unuranEmp",
"Empirical 1D distribution",10,10,800,800);
122 std::cout <<
"\nTest Using Binned data\n " << std::endl;
127 if (!unr.
Init(dist2) )
return -1;
132 TH1D * h4 =
new TH1D(
"h4",
"Landau from Unuran binned generation",nbin,xmin,xmax);
133 for (
int i = 0; i <
n; ++i) {
138 std::cout <<
"Time using Unuran " << unr.
MethodName() <<
" \t=\t " << time <<
"\tns/call" << std::endl;
140 std::cout <<
"\nTest quality UNURAN " << unr.
MethodName() <<
" (with h1)\t:\t";
141 double prob2 = h4->
Chi2Test(h1,
"UUP");
143 std::cerr <<
"Chi2 Test failed for UNURAN method " << unr.
MethodName() << std::endl;
146 std::cout <<
"\nTest quality UNURAN " << unr.
MethodName() <<
" (with ref)\t:\t";
159 double sigma_x = p[0];
160 double sigma_y = p[1];
162 double u = x[0] / sigma_x ;
163 double v = x[1] / sigma_y ;
164 double c = 1 - rho*rho ;
166 *
exp (-(u * u - 2 * rho * u * v + v * v ) / (2 * c));
172 double sigma_x = p[0];
173 double sigma_y = p[1];
174 double sigma_z = p[2];
176 double u = x[0] / sigma_x ;
177 double v = x[1] / sigma_y ;
178 double w = x[2] / sigma_z ;
179 double c = 1 - rho*rho ;
181 *
exp (-(u * u - 2 * rho * u * v + v * v + w*w) / (2 * c));
190 std::cout <<
"\nTest Using 2D UnBinned data\n " << std::endl;
193 const int Ndata = 100000;
194 const int n = 100000;
197 double p2[3] = {1,1,0.5};
205 TH2D * href =
new TH2D(
"href2d",
"UNURAN reference 2D gauss data",100,-5,5,100,-5,5);
206 for (
int i = 0; i <
n; ++i) {
208 href->
Fill(xx[0],xx[1]);
214 for (
int i = 0; i< Ndata; ++i) {
219 TH2D * h2 =
new TH2D(
"h2d",
"UNURAN generated 2D gauss data",100,-5,5,100,-5,5);
221 TH1D * hx =
new TH1D(
"hx",
"x gen variable",100,-5,5);
222 TH1D * hy =
new TH1D(
"hy",
"y gen variable",100,-5,5);
227 std::cerr <<
"Initialization failed for method " << unr.
MethodName() << std::endl;
234 for (
int i = 0; i <
n; ++i) {
236 h2->
Fill(xx[0],xx[1]);
242 std::cout <<
"Time using Unuran " << unr.
MethodName() <<
" \t=\t " << time <<
"\tns/call" << std::endl;
244 TCanvas *
c1 =
new TCanvas(
"c1_unuranEmp2D",
"Empirical Multidim distribution",300,10,800,400);
253 TCanvas *
c2 =
new TCanvas(
"c2d",
"Empirical Multidim distribution",300,100,800,400);
261 std::cout <<
"\nTest quality UNURAN " << unr.
MethodName() <<
"\t\t:\t";
262 double prob = href->
Chi2Test(h2,
"UUP");
264 std::cerr <<
"Chi2 Test failed for UNURAN method " << unr.
MethodName() << std::endl;
274 std::cout <<
"\nTest Using 3D UnBinned data\n " << std::endl;
277 const int Ndata = 100000;
278 const int n = 100000;
280 TF3 * f3 =
new TF3(
"g3d",
gaus3d,-10,10,-10,10,-10,10,4);
281 double p[4] = {1,1,1,0.5};
289 TH3D * href =
new TH3D(
"href3d",
"UNURAN reference 3D gauss data",50,-5,5,50,-5,5,50,-5,5);
291 for (
int i = 0; i <
n; ++i) {
293 href->
Fill(xx[0],xx[1],xx[2]);
298 for (
int i = 0; i< Ndata; ++i) {
303 TH3D * h3 =
new TH3D(
"h3d",
"UNURAN generated 3D gauss data",50,-5,5,50,-5,5,50,-5,5);
305 TH1D * hx =
new TH1D(
"hx3",
"x gen variable",100,-5,5);
306 TH1D * hy =
new TH1D(
"hy3",
"y gen variable",100,-5,5);
307 TH1D * hz =
new TH1D(
"hz3",
"z gen variable",100,-5,5);
312 std::cerr <<
"Initialization failed for method " << unr.
MethodName() << std::endl;
319 for (
int i = 0; i <
n; ++i) {
321 h3->
Fill(xx[0],xx[1],xx[2]);
328 std::cout <<
"Time using Unuran " << unr.
MethodName() <<
" \t=\t " << time <<
"\tns/call" << std::endl;
330 TCanvas *
c3 =
new TCanvas(
"c3d",
"Empirical Multidim distribution",300,600,800,400);
339 TCanvas *
c1 =
new TCanvas(
"c1_unuranEmp3D",
"Empirical Multidim distribution",400,500,900,400);
348 std::cout <<
"\nTest quality UNURAN " << unr.
MethodName() <<
"\t\t:\t";
349 double prob = href->
Chi2Test(h3,
"UUP");
351 std::cerr <<
"Chi2 Test failed for UNURAN method " << unr.
MethodName() << std::endl;
359 int main(
int argc,
char **argv)
376 std::cerr <<
"\n\nUnuRan Empirical Distribution Test:\t Failed !!!!!!!\n" << std::endl;
378 std::cout <<
"\n\nUnuRan Empirical Distribution Test:\t OK\n" << std::endl;
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)
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
R__EXTERN Int_t gErrorIgnoreLevel
virtual void Draw(Option_t *option="")
Specific drawing options can be used to paint a TGraph2D:
double Sample()
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::...
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
bool SampleMulti(double *x)
Sample multidimensional distributions User is responsible for having previously correctly initialized...
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
virtual void SetBuffer(Int_t buffersize, Option_t *option="")
set the maximum number of entries to be kept in the buffer
virtual Double_t GetRandom() const
return a random number distributed according the histogram bin contents.
void Stop()
Stop the stopwatch.
double gaus3d(double *x, double *p)
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
static double p2(double t, double a, double b, double c)
TUnuranEmpDist class for describing empiral distributions.
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
virtual void SetLineColor(Color_t lcolor)
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
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.
const std::string & MethodName() const
used Unuran method
double gaus2d(double *x, double *p)
Int_t Fill(Double_t)
Invalid Fill method.
TUnuranMultiContDist class describing multi dimensional continuous distributions. ...
A 2-Dim function with parameters.
R__EXTERN TRandom * gRandom
1-D histogram with a double per channel (see TH1 documentation)}
int main(int argc, char **argv)
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
Sets point number n.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
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 f2(const double *x)
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
A Graph is a graphics object made of two arrays X and Y with npoints each.
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Graphics object made of three arrays X, Y and Z with the same number of points each.
Int_t Fill(Double_t)
Invalid Fill method.
2-D histogram with a double per channel (see TH1 documentation)}