This program must be compiled and executed with Aclic as follows.
it is an extension of tutorials foam_kanwa.C to compare generation of a 2D distribution with unuran and Foam
#include <iostream>
Dist +=exp(-(sqr(
x-1./3) +sqr(
y-1./3))/GamSq)/GamSq/
TMath::Pi();
Dist +=exp(-(sqr(
x-2./3) +sqr(
y-2./3))/GamSq)/GamSq/
TMath::Pi();
return 0.5*Dist;
}
public:
virtual ~FoamFunction() {}
}
};
cout<<"--- kanwa started ---"<<endl;
TH2D *hst_xy =
new TH2D(
"foam_hst_xy" ,
"FOAM x-y plot", 50,0,1.0, 50,0,1.0);
hFoam = hst_xy;
FoamX->
SetRho(
new FoamFunction() );
w.Start();
int nshow=nev;
for(long loop=0; loop<nev; loop++){
if(loop == nshow){
nshow += 5000;
}
}
w.Stop();
double time = w.CpuTime()*1.E9/nev;
cout << "Time using FOAM \t\t " << " \t=\t " << time << "\tns/call" << endl;
cout << " MCresult= " << MCresult << " +- " << MCerror <<endl;
cout<<"--- kanwa ended ---"<<endl;
return 0;
}
double UCamel2(
double *
x,
double *) {
}
int run_unuran(int nev, std::string method = "hitro") {
std::cout << "run unuran " << std::endl;
TH2D *
h1 =
new TH2D(
"unr_hst_xy" ,
"UNURAN x-y plot", 50,0,1.0, 50,0,1.0);
TF2 *
f =
new TF2(
"f",UCamel2,0,1,0,1,0);
w.Start();
bool ret = unr.Init(dist,method);
std::cerr << "Error initializing unuran with method " << unr.MethodName() << endl;
return -1;
}
for (int i = 0; i < nev; ++i) {
}
w.Stop();
double time = w.CpuTime()*1.E9/nev;
cout << "Time using Unuran " << unr.MethodName() << " \t=\t " << time << "\tns/call" << endl;
return 0;
}
TCanvas *cKanwa =
new TCanvas(
"cKanwa",
"Canvas for plotting",600,1000);
std::cout <<"\nChi2 Test Results (UNURAN-FOAM):\t";
return 0;
}
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
#define ClassDef(name, id)
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
void Update() override
Update canvas pad buffers.
Abstract class representing n-dimensional real positive integrand function.
virtual Double_t Density(Int_t ndim, Double_t *)=0
virtual void GetIntegMC(Double_t &, Double_t &)
virtual void SetRho(TFoamIntegrand *Rho)
virtual void Initialize()
virtual void SetnCells(Long_t nCells)
virtual void SetPseRan(TRandom *PseRan)
virtual void SetkDim(Int_t kDim)
virtual void GetMCvect(Double_t *)
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual Double_t Chi2Test(const TH1 *h2, Option_t *option="UU", Double_t *res=nullptr) const
test for comparing weighted and unweighted histograms.
2-D histogram with a double per channel (see TH1 documentation)
Service class for 2-D histogram classes.
Int_t Fill(Double_t) override
Invalid Fill method.
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Random number generator class based on M.
This is the base class for the ROOT Random number generators.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
TUnuranMultiContDist class describing multi dimensional continuous distributions.
double dist(Rotation3D const &r1, Rotation3D const &r2)