66 for (
int i = 0; i <
n; ++i)
77 for (
int i = 0; i<n2; ++i) {
79 h1->
Fill(
double( x) );
86 std::string s =
"Time using Unuran " + unr.
MethodName();
87 std::cout << std::left << std::setw(40) << s <<
"\t=\t " << time <<
"\tns/call \t\tChi2 Prob = "<< prob << std::endl;
89 std::cout <<
"Chi2 Test failed for method " << unr.
MethodName() << std::endl;
104 for (
int i = 0; i <
n; ++i)
112 for (
int i = 0; i< n2; ++i) {
116 std::string s =
"Time using TRandom::Poisson";
117 std::cout << std::left << std::setw(40) << s <<
"\t=\t " << time << std::endl;
126 for (
int i = 0; i <
n; ++i)
134 for (
int i = 0; i< n2; ++i) {
138 std::string s =
"Time using TRandom::Binomial";
139 std::cout << std::left << std::setw(40) << s <<
"\t=\t " << time << std::endl;
147 TH1D * h0 =
new TH1D(
"h0",
"reference prob",10,-0.5,9.5);
148 TH1D *
h1 =
new TH1D(
"h1",
"UNURAN gen prob",10,-0.5,9.5);
151 double p[10] = {1.,2.,3.,5.,3.,2.,1.,0.5,0.3,0.5 };
152 for (
int i = 0; i< 10; ++i) {
157 std::cout <<
" prob sum = " << sum << std::endl;
166 std::cout <<
"Test generation with a PV :\n\n";
170 bool ret = unr.
Init(dist,
"method=dau");
174 ret = unr.
Init(dist,
"method=dgt");
180 ret = unr.
Init(dist,
"method=dss");
204 std::cout <<
"\nTest generation with a Probability function (Poisson) :\n\n";
211 double muVal[Nmu] = {5,10,20,50,100};
219 for (
int imu = 0; imu < Nmu; ++imu) {
221 const double mu = muVal[imu];
223 int nmax =
static_cast<int>(mu*3);
224 TH1D * h2 =
new TH1D(
"h2",
"reference Poisson prob",nmax,0,nmax);
225 TH1D * h3 =
new TH1D(
"h3",
"UNURAN gen prob",nmax,0,nmax);
226 TH1D * h4 =
new TH1D(
"h4",
"UNURAN gen prob 2",nmax,0,nmax);
229 std::cout <<
"\nPoisson mu = " << mu << std::endl << std::endl;
243 double p[1]; p[0] = mu;
245 for (
int i = 0; i <
n; ++i) {
248 if (n % 10 == 0) h4->
Fill(k);
252 double prob = h2->
Chi2Test(h4,
"UU");
253 std::string s =
"Time using Unuran w/ re-init method=" + unr.
MethodName();
254 std::cout << std::left << std::setw(40) << s <<
"\t=\t " << time
255 <<
"\tns/call \t\tChi2 Prob = "<< prob << std::endl;
258 std::cout <<
"Chi2 Test failed for re-init " << std::endl;
274 ret = unr.
Init(dist2,
"method=dari");
282 ret = unr.
Init(dist2,
"method=dsrou");
301 TFile * file =
new TFile(
"unuranPoisson.root",
"RECREATE");
322 std::cout <<
"\nTest generation with a Probability function (Binomimal) :\n\n";
329 double pVal[NBin] = {0.5,0.1,0.01};
330 double NVal[NBin] = {20,100,1000};
334 double tUdsrou[NBin];
340 for (
int ib = 0; ib < NBin; ++ib) {
347 int nmax =
static_cast<int>(par[0]*par[1]*3);
348 TH1D * h2 =
new TH1D(
"h2",
"reference Binomial prob",nmax,0,nmax);
349 TH1D * h3 =
new TH1D(
"h3",
"UNURAN gen prob",nmax,0,nmax);
350 TH1D * h4 =
new TH1D(
"h4",
"UNURAN gen prob 2",nmax,0,nmax);
353 std::cout <<
"\nBinomial n = " << par[0] <<
" " << par[1] << std::endl;
359 bool ret = unr.
InitBinomial(static_cast<int>(par[0]),par[1]);
368 unr.
InitBinomial(static_cast<int>(par[0]), par[1],
"dstd");
370 for (
int i = 0; i <
n; ++i) {
373 if (n % 10 == 0) h4->
Fill(k);
377 double prob = h2->
Chi2Test(h4,
"UU");
378 std::string s =
"Time using Unuran w/ re-init method=" + unr.
MethodName();
379 std::cout << std::left << std::setw(40) << s <<
"\t=\t " << time
380 <<
"\tns/call \t\tChi2 Prob = "<< prob << std::endl;
383 std::cout <<
"Chi2 Test failed for re-init " << std::endl;
393 dist.
SetMode(
int(par[0]*par[1]) );
395 ret = unr.
Init(dist,
"method=dari");
402 ret = unr.
Init(dist,
"method=dsrou");
427 c1 =
new TCanvas(
"c1_unuranDiscr_PV",
"Discrete distribution from PV",10,10,800,800);
441 std::cerr <<
"\n\nUnuRan Discrete Distribution Test:\t Failed !!!!!!!" << std::endl;
443 std::cerr <<
"\n\nUnuRan Discrete Distribution Test:\t OK" << std::endl;
451 int main(
int argc,
char **argv)
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
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 SetProbSum(double sum)
set the value of the sum of the probabilities in the given domain
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
int testUnuran(TUnuran &unr, double &time, TH1 *h1, const TH1 *href, bool weightHist=false)
R__EXTERN Int_t gErrorIgnoreLevel
bool InitBinomial(unsigned int ntot, double prob, const std::string &method="dstd")
Initialize method for the Binomial distribution Used to generate poisson numbers for a constant param...
virtual Int_t Binomial(Int_t ntot, Double_t prob)
Generates a random integer N according to the binomial law.
bool ReInitDiscrDist(unsigned int npar, double *params)
Reinitialize UNURAN by changing the distribution parameters but mantaining same distribution and meth...
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
void SetMode(int mode)
set the mode of the distribution (location of maximum probability)
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...
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
int testRootPoisson(double mu, double &time, TH1 *h2)
void Stop()
Stop the stopwatch.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
bool InitPoisson(double mu, const std::string &method="dstd")
Initialize method for the Poisson distribution Used to generate poisson numbers for a constant parame...
TUnuranDiscrDist class for one dimensional discrete distribution.
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
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 SetBinError(Int_t bin, Double_t error)
see convention for numbering bins in TH1::GetBin
virtual void SetLineColor(Color_t lcolor)
virtual void Draw(Option_t *option="")
Draw this histogram with options.
double binomial_pdf(unsigned int k, double p, unsigned int n)
Probability density function of the binomial distribution.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
const std::string & MethodName() const
used Unuran method
R__EXTERN TRandom * gRandom
1-D histogram with a double per channel (see TH1 documentation)}
double poisson_pmf(double *x, double *p)
int main(int argc, char **argv)
double binomial_pmf(double *x, double *p)
double poisson_pdf(unsigned int n, double mu)
Probability density function of the Poisson distribution.
int testRootBinomial(int m, double p, double &time, TH1 *h2)
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
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
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...
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.
Functor1D class for one-dimensional functions.
virtual void Update()
Update canvas pad buffers.
virtual void Close(Option_t *option="")
Close a file.