34 Double_t sqr(Double_t x){
return x*x;};
39 Double_t Camel2(Int_t nDim, Double_t *Xarg){
43 Double_t GamSq= sqr(0.100e0);
45 Dist +=exp(-(sqr(x-1./3) +sqr(y-1./3))/GamSq)/GamSq/TMath::Pi();
46 Dist +=exp(-(sqr(x-2./3) +sqr(y-2./3))/GamSq)/GamSq/TMath::Pi();
50 class FoamFunction :
public TFoamIntegrand {
52 virtual ~FoamFunction() {}
53 double Density(
int nDim,
double * x) {
54 return Camel2(nDim,x);
56 ClassDef(FoamFunction,1);
64 Int_t run_foam(
int nev){
65 cout<<
"--- kanwa started ---"<<endl;
66 gSystem->Load(
"libFoam.so");
67 TH2D *hst_xy =
new TH2D(
"foam_hst_xy" ,
"FOAM x-y plot", 50,0,1.0, 50,0,1.0);
70 Double_t *MCvect =
new Double_t[2];
72 TRandom *PseRan =
new TRandom3();
73 PseRan->SetSeed(4357);
74 TFoam *FoamX =
new TFoam(
"FoamX");
76 FoamX->SetnCells(500);
77 FoamX->SetRho(
new FoamFunction() );
78 FoamX->SetPseRan(PseRan);
91 for(
long loop=0; loop<nev; loop++){
93 FoamX->GetMCvect( MCvect);
101 hst_xy->Draw(
"lego2");
107 double time = w.CpuTime()*1.E9/nev;
108 cout <<
"Time using FOAM \t\t " <<
" \t=\t " << time <<
"\tns/call" << endl;
111 hst_xy->Draw(
"lego2");
113 Double_t MCresult, MCerror;
114 FoamX->GetIntegMC( MCresult, MCerror);
115 cout <<
" MCresult= " << MCresult <<
" +- " << MCerror <<endl;
116 cout<<
"--- kanwa ended ---"<<endl;
123 double UCamel2(
double * x,
double *) {
127 int run_unuran(
int nev, std::string method =
"hitro") {
130 std::cout <<
"run unuran " << std::endl;
132 gSystem->Load(
"libUnuran.so");
134 TH2D *h1 =
new TH2D(
"unr_hst_xy" ,
"UNURAN x-y plot", 50,0,1.0, 50,0,1.0);
137 TF2 * f =
new TF2(
"f",UCamel2,0,1,0,1,0);
139 TUnuranMultiContDist dist(f);
152 bool ret = unr.Init(dist,method);
154 std::cerr <<
"Error initializing unuran with method " << unr.MethodName() << endl;
159 for (
int i = 0; i < nev; ++i) {
167 double time = w.CpuTime()*1.E9/nev;
168 cout <<
"Time using Unuran " << unr.MethodName() <<
" \t=\t " << time <<
"\tns/call" << endl;
173 Int_t unuranFoamTest(){
176 TCanvas *cKanwa =
new TCanvas(
"cKanwa",
"Canvas for plotting",600,1000);
182 run_unuran(n,
"hitro");
191 std::cout <<
"\nChi2 Test Results (UNURAN-FOAM):\t";
193 hFoam->Chi2Test(hUnr,
"UUP");