42 double sigma_x = p[0];
43 double sigma_y = p[1];
44 double sigma_z = p[2];
46 double u = x[0] / sigma_x ;
47 double v = x[1] / sigma_y ;
48 double w = x[2] / sigma_z ;
49 double c = 1 - rho*rho ;
51 *
exp (-(u * u - 2 * rho * u * v + v * v + w*w) / (2 * c));
80 bool ret = unr.
Init(dist,method);
82 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
93 std::vector<double>
x(dim);
94 for (
int i = 0; i <
n; ++i) {
96 h1->
Fill(x[0],x[1],x[2]);
102 std::cout <<
"Time using Unuran " << unr.
MethodName() <<
" \t=\t " << time <<
"\tns/call\t";
104 double prob = href->Chi2Test(h1,
"UU");
105 double ksprob = href->KolmogorovTest(h1);
106 std::cout <<
"\tChi2 Prob = "<< prob <<
"\tKS Prob = " << ksprob << std::endl;
109 if (unr.
MethodName() ==
"hitro") prob = ksprob;
111 std::cout <<
"\nChi2 Test failed ! " << std::endl;
112 href->Chi2Test(h1,
"UUP");
117 std::cout << std::endl;
130 double x[3] = {0,0,0};
131 for (
int i = 0; i <
n; ++i) {
133 h1->
Fill(x[0],x[1],x[2]);
141 double prob = href->Chi2Test(h1,
"UU");
142 double ksprob = href->KolmogorovTest(h1);
143 std::cout <<
"Time using TF1::GetRandom() \t=\t " << time <<
"\tns/call \t\tChi2 Prob = "<< prob
144 <<
"\tKS Prob = " << ksprob << std::endl;
146 std::cout <<
"\tChi2 Test failed ! " << std::endl;
147 href->Chi2Test(h1,
"UUP");
152 std::cout <<
"Time using TF1::GetRandom() \t=\t " << time <<
"\tns/call\n";
173 TH3D *
h1 =
new TH3D(
"h1",
"UNURAN gaussian 3D distribution",50,-10,10,50,-10,10,50,-10,10);
174 TH3D *
h2 =
new TH3D(
"h2",
"TF1::GetRandom gaussian 3D distribution",50,-10,10,50,-10,10,50,-10,10);
177 TH3D * h3 =
new TH3D(
"h3",
"UNURAN truncated gaussian 3D distribution",50,-1,1,50,-1,1,50,-1,1);
178 TH3D * h4 =
new TH3D(
"h4",
"TF1::GetRandom truncated gaussian 3D distribution",50,-1,1,50,-1,1,50,-1,1);
182 double par[4] = {2,2,2,0.5};
189 std::cout <<
"Test using an undefined domain :\n\n";
191 std::cout <<
"Function Points used in GetRandom: [ " << f->
GetNpx() <<
" , "
192 << f->
GetNpy() <<
" , " << f->
GetNpz() <<
" ]" << std::endl;
199 std::cout <<
"Function Points used in GetRandom: [ " << f->
GetNpx() <<
" , "
200 << f->
GetNpy() <<
" , " << f->
GetNpz() <<
" ]" << std::endl;
207 std::cout <<
"Function Points used in GetRandom: [ " << f->
GetNpx() <<
" , "
208 << f->
GetNpy() <<
" , " << f->
GetNpz() <<
" ]" << std::endl;
223 std::string method =
"vnrou";
224 iret |=
testUnuran(unr, method, dist, h1, href);
229 iret |=
testUnuran(unr, method, dist, h1, href);
236 iret |=
testUnuran(unr, method, logdist, h1, href);
240 std::cout <<
"\nTest setting the mode in Unuran distribution:\n\n";
241 double m[3] = {0,0,0};
245 iret |=
testUnuran(unr, method, dist, h1, href);
248 iret |=
testUnuran(unr, method, dist, h1, href);
253 iret |=
testUnuran(unr, method, logdist, h1, href);
256 std::cout <<
"\nTest truncated distribution:\n\n";
258 double xmin[3] = { -1, -1, -1 };
259 double xmax[3] = { 1, 1, 1 };
261 f->
SetRange(xmin[0],xmin[1],xmin[2],xmax[0],xmax[1],xmax[2]);
267 std::cout <<
"Function Points used in GetRandom: [ " << f->
GetNpx() <<
" , "
268 << f->
GetNpy() <<
" , " << f->
GetNpz() <<
" ]" << std::endl;
274 std::cout <<
"Function Points used in GetRandom: [ " << f->
GetNpx() <<
" , "
275 << f->
GetNpy() <<
" , " << f->
GetNpz() <<
" ]" << std::endl;
280 iret |=
testUnuran(unr, method, dist, h3, href);
282 iret |=
testUnuran(unr, method, dist, h3, href);
288 iret |=
testUnuran(unr, method, logdist, h3, href);
292 TCanvas *
c1 =
new TCanvas(
"c1_unuranMulti",
"Multidimensional distribution",10,10,900,900);
305 TH3D * hrefN =
new TH3D(
"hrefN",
"UNURAN gaussian ref N-Dim distribution (first 3 dim)",30,-3,3,30,-3,3,30,-3,3);
306 TH3D * h10v =
new TH3D(
"h10v",
"UNURAN gaussian N-Dim distribution (first 3 dim)",30,-3,3,30,-3,3,30,-3,3);
307 TH3D * h10h =
new TH3D(
"h10h",
"UNURAN gaussian N-Dim distribution (first 3 dim)",30,-3,3,30,-3,3,30,-3,3);
308 TH3D * h100 =
new TH3D(
"h100",
"UNURAN gaussian N-Dim distribution (first 3 dim)",30,-3,3,30,-3,3,30,-3,3);
312 double par2[4] = {1,1,1,0.};
317 iret |=
testUnuran(unr, method, dist3, hrefN);
319 std::cout <<
"\nTest 10 dimension: (be patient , it takes time....)\n\n";
325 TCanvas *
c2 =
new TCanvas(
"c2_unuranMulti",
"Multidimensional distribution",100,10,900,900);
332 iret |=
testUnuran(unr, method, dist10, h10v, hrefN,10);
337 method =
"hitro;thinning=20";
338 iret |=
testUnuran(unr, method, dist10, h10h, hrefN,10);
344 std::cout <<
"\nTest 100 dimension: ( be patient , it takes time....)\n\n";
350 std::cout <<
"number of events to be generated = " <<
n << std::endl;
351 method =
"hitro;thinning=200";
352 iret |=
testUnuran(unr, method, dist100, h100, hrefN,100);
363 std::cerr <<
"\n\nUnuRan MultiDim Continous Distribution Test:\t Failed !!!!!!!\n" << std::endl;
365 std::cerr <<
"\n\nUnuRan MultiDim Continous Distribution Test:\t OK\n" << std::endl;
371 int main(
int argc,
char **argv)
double dist(Rotation3D const &r1, Rotation3D const &r2)
virtual void SetParameters(const Double_t *params)
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.
R__EXTERN Int_t gErrorIgnoreLevel
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
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 testGetRandom(TF3 *f, TH3 *h1, const TH3 *href=0)
bool SampleMulti(double *x)
Sample multidimensional distributions User is responsible for having previously correctly initialized...
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
double gaus100d(double *x, double *)
void Stop()
Stop the stopwatch.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
The 3-D histogram classes derived from the 1-D histogram classes.
double gaus3d(double *x, double *p)
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)}
double log_gaus3d(double *x, double *p)
A 3-Dim function with parameters.
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
void SetDomain(const double *xmin, const double *xmax)
set the domain of the distribution giving an array of minimum and maximum values By default otherwise...
Int_t Fill(Double_t)
Invalid Fill method.
TUnuranMultiContDist class describing multi dimensional continuous distributions. ...
R__EXTERN TRandom * gRandom
int testUnuran(TUnuran &unr, const std::string &method, const TUnuranMultiContDist &dist, TH3 *h1, const TH3 *href=0, const int dim=3)
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
virtual Int_t GetNpx() const
double gaus10d(double *x, double *)
int main(int argc, char **argv)
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.
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
void SetMode(const double *x)
set the mode of the distribution (coordinates of the distribution maximum values) ...
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void Update()
Update canvas pad buffers.
virtual void SetNpz(Int_t npz=30)
Set the number of points used to draw the function.