15 using namespace ROOT::Math;
23 if (!sampler)
return -1;
24 TF1 *
f =
new TF1(
"pdf",
"gaus");
25 f->SetParameters(1,0,1);
28 TH1D * hr =
new TH1D(
"hr",
"h2",100,-3,3);
31 bool ret = sampler->
Init(
"AUTO");
37 for (
int i = 0; i <
n; ++i) {
42 std::cout <<
"Unuran sampling - (ns)/call = " << c*w.
RealTime() <<
" " << c*w.
CpuTime() << std::endl;
43 new TCanvas(
"Continous test");
49 for (
int i = 0; i <
n; ++i) {
53 std::cout <<
"TRandom::Gauss sampling - (ns)/call = " << c*w.
RealTime() <<
" " << c*w.
CpuTime() << std::endl;
62 std::cerr <<
"Chi2 test of generated histogram failed" << std::endl;
77 if (!sampler)
return -1;
78 TF1 *
f =
new TF1(
"pdf",
"TMath::Poisson(x,[0])");
80 f->SetParameter(0,mu);
83 TH1D * hr =
new TH1D(
"hd",
"h2",50,0,50);
88 bool ret = sampler->
Init(
"DARI");
94 for (
int i = 0; i <
n; ++i) {
99 std::cout <<
"Unuran sampling - (ns)/call = " << c*w.
RealTime() <<
" " << c*w.
CpuTime() << std::endl;
100 new TCanvas(
"Discrete test");
106 for (
int i = 0; i <
n; ++i) {
110 std::cout <<
"TRandom::Poisson sampling - (ns)/call = " << c*w.
RealTime() <<
" " << c*w.
CpuTime() << std::endl;
117 double prob = h1->
Chi2Test(hr,
"UU");
119 std::cerr <<
"Chi2 test of generated histogram failed" << std::endl;
136 if (iret) std::cerr <<
"\ntestDistSampler: .... FAILED!" << std::endl;
137 else std::cerr <<
"\ntestDistSampler: .... OK" << std::endl;
virtual void SetMode(double)
set the mode of the distribution (could be useful to some methods) implemented by derived classes if ...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
R__EXTERN Int_t gErrorIgnoreLevel
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
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
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
void SetFunction(Function &func, unsigned int dim)
set the parent function distribution to use for sampling (generic case)
virtual void SetLineColor(Color_t lcolor)
virtual void Draw(Option_t *option="")
Draw this histogram with options.
static ROOT::Math::DistSampler * CreateDistSampler(const std::string &samplerType="")
static method to create the distribution sampler class given a string specifying the type Supported s...
R__EXTERN TRandom * gRandom
1-D histogram with a double per channel (see TH1 documentation)}
virtual double Sample1D()
sample one event in one dimension better implementation could be provided by the derived classes ...
virtual void SetArea(double)
set the normalization area of distribution implemented by derived classes if needed ...
Interface class for generic sampling of a distribution, i.e.
int testDistSampler(int n=10000)
virtual bool Init(const char *="")
initialize the generators with the given algorithm Implemented by derived classes who needs it (like ...
virtual Int_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.