40 double norm(
double *
x,
double *p) {
44 double cdf(
double *
x,
double *p) {
63 fHref =
new TH1D(
"Href",
"uniform ref histo",100,0,1);
88 TH1D htmp(
"htmp",
"gaussian generated cdf",100,0,1.);
90 int n2 = sampleSize/100;
92 for (
int i = 0; i<n2; ++i) {
94 htmp.
Fill( fCdf->Eval(x) );
96 double prob = fHref->Chi2Test(&htmp,
"UU");
97 std::cout <<
"Time using Unuran " << unr.
MethodName() <<
" \t=\t " << time <<
"\tns/call \t\tChi2 Prob = "<< prob << std::endl;
99 std::cout <<
"Chi2 Test failed ! " << std::endl;
100 fHref->Chi2Test(&htmp,
"UUP");
123 TH1D htmp(
"htmp",
"gaussian generated cdf",100,0,1.);
125 int n2 = sampleSize/100;
126 for (
int i = 0; i<n2; ++i) {
128 htmp.
Fill( fCdf->Eval(x) );
130 double prob = fHref->Chi2Test(&htmp,
"UU");
131 std::cout <<
"Time using TF1::GetRandom() \t=\t " << time <<
"\tns/call \t\tChi2 Prob = "<< prob << std::endl;
133 std::cout <<
"Chi2 Test failed ! " << std::endl;
134 fHref->Chi2Test(&htmp,
"UUP");
163 TH1D *
h1 =
new TH1D(
"h1",
"gaussian distribution",100,-10,10);
164 TH1D * h2 =
new TH1D(
"h2",
"gaussian distribution",100,-10,10);
166 TH1D * h1u =
new TH1D(
"h1u",
"test gaussian dist",100,0,1);
167 TH1D * h2u =
new TH1D(
"h2u",
"test gaussian dist",100,0,1);
193 ret = unr.
Init(dist,
"arou");
195 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
199 iret |= t.testUnuran(unr);
202 ret = unr.
Init(dist,
"nrou");
204 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
208 iret |= t.testUnuran(unr);
212 ret = unr.
Init(dist,
"tdr");
214 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
218 iret |= t.testUnuran(unr);
224 ret = unr.
Init(dist,
"hinv");
226 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
230 iret |= t.testUnuran(unr);
234 ret = unr.
Init(dist,
"ninv");
237 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
241 iret |= t.testUnuran(unr);
248 ret = unr.
Init(dist,
"srou");
250 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
254 iret |= t.testUnuran(unr);
257 ret = unr.
Init(dist,
"ssr");
259 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
263 iret |= t.testUnuran(unr);
266 ret = unr.
Init(dist,
"utdr");
268 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
272 iret |= t.testUnuran(unr);
277 iret |= t.testGetRandom(f);
279 std::cout <<
"\nTest truncated distribution:\n\n";
287 ret = unr.
Init(dist,
"auto");
289 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
293 iret |= t.testUnuran(unr);
296 iret |= t.testGetRandom(f);
300 TCanvas *
c1 =
new TCanvas(
"c1_unuran1D",
"Onedimensional distribution",10,10,1000,1000);
309 ret = unr.
Init(dist,
"auto");
311 std::cerr <<
"Error initializing unuran with method " << unr.
MethodName() << std::endl;
315 for (
int i = 0; i < n2; ++i) {
327 std::cout <<
"\nFit result on data with unuran: " << std::endl;
329 std::cout <<
"Gaus Fit chi2 = " << f1->
GetChisquare() <<
" ndf = " << f1->
GetNDF() << std::endl;
330 std::cout <<
"Gaus Fit Prob = " << f1->
GetProb() << std::endl;
331 if ( f1->
GetProb() < 1.E-6) iret = 11;
334 h1u->
Fit(
"pol0",
"Q");
336 std::cout <<
"CDF Fit chi2 = " << f1u->
GetChisquare() <<
" ndf = " << f1u->
GetNDF() << std::endl;
337 std::cout <<
"CDF Fit Prob = " << f1u->
GetProb() << std::endl;
338 if ( f1u->
GetProb() < 1.E-6) iret = 12;
346 std::cout <<
"\nFit result on data with GetRandom: " << std::endl;
348 std::cout <<
"Gaus Fit chi2 = " << f1->
GetChisquare() <<
" ndf = " << f1->
GetNDF() << std::endl;
349 std::cout <<
"Gaus Fit Prob = " << f1->
GetProb() << std::endl;
350 if ( f1->
GetProb() < 1.E-6) iret = 13;
354 h2u->
Fit(
"pol0",
"Q");
356 std::cout <<
"Fit chi2 = " << f1->
GetChisquare() <<
" ndf = " << f1->
GetNDF() << std::endl;
357 std::cout <<
"Fit Prob = " << f1->
GetProb() << std::endl;
358 if ( f1->
GetProb() < 1.E-6) iret = 14;
361 std::cout <<
"Chi2 test Gaussian histograms :\t";
363 std::cout <<
"Chi2 test Uniform histograms :\t";
367 std::cerr <<
"\n\nUnuRan Continous Distribution Test:\t Failed !!!!!!!\n" << std::endl;
369 std::cerr <<
"\n\nUnuRan Continous Distribution Test:\t OK\n" << std::endl;
378 int main(
int argc,
char **argv)
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)
virtual Double_t GetRandom()
Return a random number following this function shape.
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
double Sample()
Sample 1D distribution User is responsible for having previously correctly initialized with TUnuran::...
virtual TF1 * GetFunction(const char *name) const
Return pointer to function with name.
R__EXTERN TStyle * gStyle
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
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...
void SetCdf(TF1 *cdf)
set cdf distribution.
virtual Double_t GetProb() const
Return the fit probability.
double normal_pdf(double x, double sigma=1, double x0=0)
Probability density function of the normal (Gaussian) distribution.
virtual Int_t GetNDF() const
Return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
static struct mg_connection * fc(struct mg_context *ctx)
static const double x2[5]
void Stop()
Stop the stopwatch.
virtual Double_t Chi2Test(const TH1 *h2, Option_t *option="UU", Double_t *res=0) const
test for comparing weighted and unweighted histograms
double cdf(double *x, double *p)
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
double normal_cdf(double x, double sigma=1, double x0=0)
Cumulative distribution function of the normal (Gaussian) distribution (lower tail).
double cdf_trunc(double *x, double *p)
int testGetRandom(TF2 *f, TH1 *h1, const TH2 *href=0)
virtual Double_t Rndm()
Machine independent random number generator.
R__EXTERN TSystem * gSystem
virtual void Draw(Option_t *option="")
Draw this histogram with options.
void SetOptFit(Int_t fit=1)
The type of information about fit parameters printed in the histogram statistics box can be selected ...
int main(int argc, char **argv)
R__EXTERN TRandom * gRandom
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Double_t GetChisquare() const
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
void SetDomain(double xmin, double xmax)
Set the distribution domain.
static const double x1[5]
void SetPdfArea(double area)
set the area below the pdf
const std::string & MethodName() const
used Unuran method
TUnuranContDist class describing one dimensional continuous distribution.
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.
bool Init(const std::string &distr, const std::string &method)
initialize with Unuran string interface
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
void SetMode(double mode)
set the distribution mode (x position of its maximum)
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
double norm(double *x, double *p)