00001 #include "Math/Random.h"
00002 #include "Math/GSLRndmEngines.h"
00003 #include "Math/DistFunc.h"
00004 #include "TStopwatch.h"
00005 #include "TRandom3.h"
00006 #include "TRandom2.h"
00007 #include "TCanvas.h"
00008 #include "TH1D.h"
00009 #include "TH2D.h"
00010 #include "TH3D.h"
00011 #include "TMath.h"
00012 #include <iostream>
00013 #include <cmath>
00014 #include <typeinfo>
00015 #define HAVE_UNURAN
00016 #ifdef HAVE_UNURAN
00017 #include "UnuRanDist.h"
00018 #endif
00019
00020 #ifdef HAVE_CLHEP
00021 #include "CLHEP/Random/RandFlat.h"
00022 #include "CLHEP/Random/RandPoissonT.h"
00023 #include "CLHEP/Random/RandPoisson.h"
00024 #include "CLHEP/Random/RandGauss.h"
00025 #include "CLHEP/Random/RandGaussQ.h"
00026 #include "CLHEP/Random/RandGaussT.h"
00027 #include "CLHEP/Random/RandBinomial.h"
00028 #include "CLHEP/Random/JamesRandom.h"
00029 #endif
00030
00031
00032 #ifndef PI
00033 #define PI 3.14159265358979323846264338328
00034 #endif
00035
00036
00037
00038 #ifndef NEVT
00039 #define NEVT 1000000
00040 #endif
00041
00042
00043
00044 using namespace ROOT::Math;
00045 #ifdef HAVE_CLHEP
00046 using namespace CLHEP;
00047 #endif
00048
00049 static bool fillHist = false;
00050
00051
00052
00053 void testDiff(TH1D & h1, TH1D & h2, const std::string & name="") {
00054
00055 double chi2;
00056 int ndf;
00057 if (h1.GetEntries() == 0 && h2.GetEntries() == 0) return;
00058 int igood = 0;
00059 double prob = h1.Chi2TestX(&h2,chi2,ndf,igood,"UU");
00060 std::cout << "\nTest " << name << " chi2 = " << chi2 << " ndf " << ndf << " prob = " << prob;
00061 if (igood) std::cout << " \t\t" << " igood = " << igood;
00062 std::cout << std::endl;
00063
00064 std::string cname="c1_" + name;
00065 std::string ctitle="Test of " + name;
00066 TCanvas *c1 = new TCanvas(cname.c_str(), ctitle.c_str(),200,10,800,600);
00067 h1.DrawCopy();
00068 h2.DrawCopy("Esame");
00069 c1->Update();
00070
00071
00072 }
00073
00074 template <class R>
00075 std::string findName( const R & r) {
00076
00077 std::string type = typeid(r).name();
00078 if (type.find("GSL") != std::string::npos )
00079 return "ROOT::Math::Random";
00080 else if (type.find("TRandom") != std::string::npos )
00081 return "TRandom ";
00082 else if (type.find("UnuRan") != std::string::npos )
00083 return "UnuRan ";
00084 else if (type.find("Rand") != std::string::npos )
00085 return "CLHEP ";
00086
00087 return "????????? ";
00088 }
00089
00090
00091 template <class R>
00092 void testPoisson( R & r,double mu,TH1D & h) {
00093
00094 TStopwatch w;
00095
00096 int n = NEVT;
00097
00098 w.Start();
00099 r.SetSeed(0);
00100 for (int i = 0; i < n; ++i) {
00101 int n = r.Poisson(mu );
00102 if (fillHist)
00103 h.Fill( double(n) );
00104 }
00105 w.Stop();
00106 if (fillHist) { fillHist=false; return; }
00107 std::cout << "Poisson - mu = " << mu << "\t\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00108 << w.CpuTime()*1.0E9/NEVT
00109 << "\t(ns/call)" << std::endl;
00110
00111 fillHist = true;
00112 testPoisson(r,mu,h);
00113 }
00114
00115
00116
00117
00118 template <class R>
00119 unsigned int genPoisson( R & r, double mu) {
00120
00121
00122
00123
00124 unsigned int k = 0;
00125
00126 while (mu > 20) {
00127
00128 const double alpha = 0.875;
00129 unsigned int m = static_cast<unsigned int> ((alpha*mu) );
00130
00131
00132 double sqm = std::sqrt( 2.*m -1.);
00133 double pi = TMath::Pi();
00134 double x,y,v;
00135 do {
00136 do {
00137 y = std::tan( pi * r.Rndm() );
00138 x = sqm * y + m - 1.;
00139 }
00140 while (x <= 0);
00141 v = r.Rndm();
00142 }
00143 while ( v > (1 + y * y) * std::exp ( (m - 1) * std::log (x / (m - 1)) - sqm * y));
00144
00145
00146
00147 if ( x >= mu )
00148 return k + r.Binomial( m-1, mu/x);
00149
00150 else {
00151
00152 mu -= x;
00153 k += m;
00154 }
00155 }
00156
00157 double expmu = TMath::Exp(-mu);
00158 double pir = 1.0;
00159 do {
00160 pir *= r.Rndm();
00161 k++;
00162 }
00163 while (pir > expmu);
00164 return k -1;
00165
00166 }
00167
00168
00169
00170
00171 template <class R>
00172 unsigned int genPoisson2( R & r, double mu) {
00173
00174
00175
00176
00177
00178
00179 if( mu < 12.0 ) {
00180
00181 double expmu = TMath::Exp(-mu);
00182 double pir = 1.0;
00183 unsigned int k = 0;
00184 do {
00185 pir *= r.Rndm();
00186 k++;
00187 }
00188 while (pir > expmu);
00189 return k-1;
00190 }
00191
00192 else {
00193
00194 double em, t, y;
00195 double sq, alxm, g;
00196 double pi = TMath::Pi();
00197
00198 sq = std::sqrt(2.0*mu);
00199 alxm = std::log(mu);
00200 g = mu*alxm - TMath::LnGamma(mu + 1.0);
00201
00202 do {
00203 do {
00204 y = std::tan(pi*r.Rndm());
00205 em = sq*y + mu;
00206 } while( em < 0.0 );
00207
00208 em = std::floor(em);
00209 t = 0.9*(1.0 + y*y)* std::exp(em*alxm - TMath::LnGamma(em + 1.0) - g);
00210 } while( r.Rndm() > t );
00211
00212 return static_cast<unsigned int> (em);
00213
00214 }
00215
00216 }
00217
00218
00219 template <class R>
00220 void testPoisson2( R & r,double mu,TH1D & h) {
00221
00222 TStopwatch w;
00223
00224 int n = NEVT;
00225
00226 w.Start();
00227 r.SetSeed(0);
00228 for (int i = 0; i < n; ++i) {
00229
00230 int n = r.PoissonD(mu);
00231 if (fillHist)
00232 h.Fill( double(n) );
00233 }
00234 w.Stop();
00235 if (fillHist) { fillHist=false; return; }
00236 std::cout << "Poisson \t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00237 << w.CpuTime()*1.0E9/NEVT
00238 << "\t(ns/call)" << std::endl;
00239
00240 fillHist = true;
00241 testPoisson2(r,mu,h);
00242 }
00243
00244 #ifdef HAVE_CLHEP
00245 template<class R>
00246 void testPoissonCLHEP( R & r, double mu,TH1D & h) {
00247
00248 TStopwatch w;
00249
00250 int n = NEVT;
00251
00252 w.Start();
00253
00254 for (int i = 0; i < n; ++i) {
00255
00256 int n = static_cast<unsigned int> ( r(mu) ) ;
00257 if (fillHist)
00258 h.Fill( double(n) );
00259 }
00260 w.Stop();
00261 if (fillHist) { fillHist=false; return; }
00262 std::cout << "Poisson - mu = " << mu << "\t\t" << findName(r) <<"\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00263 << w.CpuTime()*1.0E9/NEVT
00264 << "\t(ns/call)" << std::endl;
00265
00266 fillHist = true;
00267 testPoissonCLHEP(r,mu,h);
00268 }
00269
00270 template<class R>
00271 void testGausCLHEP( R & r,double mu,double sigma,TH1D & h) {
00272
00273 TStopwatch w;
00274
00275 int n = NEVT;
00276 int n1 = 100;
00277 int n2 = n/n1;
00278 w.Start();
00279 for (int i = 0; i < n2; ++i) {
00280 for (int j = 0; j < n1; ++j) {
00281 double x = r(mu,sigma );
00282 if (fillHist)
00283 h.Fill( x );
00284
00285 }
00286 w.Stop();
00287 if (fillHist) { fillHist=false; return; }
00288 std::cout << "Gaussian - mu,sigma = " << mu << " , " << sigma << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00289 << w.CpuTime()*1.0E9/NEVT
00290 << "\t(ns/call)" << std::endl;
00291
00292 fillHist = true;
00293 testGausCLHEP(r,mu,sigma,h);
00294 }
00295
00296 template <class R>
00297 void testFlatCLHEP( R & r,TH1D & h) {
00298
00299 TStopwatch w;
00300
00301 int n = NEVT;
00302 w.Start();
00303
00304 for (int i = 0; i < n; ++i) {
00305 double x = r();
00306 if (fillHist)
00307 h.Fill( x );
00308
00309 }
00310 w.Stop();
00311 if (fillHist) { fillHist=false; return; }
00312 std::cout << "Flat - [0,1] \t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00313 << w.CpuTime()*1.0E9/NEVT
00314 << "\t(ns/call)" << std::endl;
00315
00316 fillHist = true;
00317 testFlatCLHEP(r,h);
00318 }
00319
00320
00321 #endif
00322
00323
00324
00325 template <class R>
00326 void testFlat( R & r,TH1D & h) {
00327
00328 TStopwatch w;
00329
00330 int n = NEVT;
00331 w.Start();
00332 r.SetSeed(0);
00333 for (int i = 0; i < n; ++i) {
00334 double x = r.Rndm();
00335 if (fillHist)
00336 h.Fill( x );
00337
00338 }
00339 w.Stop();
00340 if (fillHist) { fillHist=false; return; }
00341 std::cout << "Flat - [0,1] \t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00342 << w.CpuTime()*1.0E9/NEVT
00343 << "\t(ns/call)" << std::endl;
00344
00345 fillHist = true;
00346 testFlat(r,h);
00347 }
00348
00349
00350
00351 template <class R>
00352 void testGaus( R & r,double mu,double sigma,TH1D & h) {
00353
00354 TStopwatch w;
00355
00356 int n = NEVT;
00357
00358 w.Start();
00359 r.SetSeed(0);
00360 for (int i = 0; i < n; ++i) {
00361 double x = r.Gaus(mu,sigma );
00362 if (fillHist)
00363 h.Fill( x );
00364
00365 }
00366 w.Stop();
00367 if (fillHist) { fillHist=false; return; }
00368 std::cout << "Gaussian - mu,sigma = " << mu << " , " << sigma << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00369 << w.CpuTime()*1.0E9/NEVT
00370 << "\t(ns/call)" << std::endl;
00371
00372 fillHist = true;
00373 testGaus(r,mu,sigma,h);
00374 }
00375
00376
00377
00378 template <class R>
00379 void testLandau( R & r,TH1D & h) {
00380
00381 TStopwatch w;
00382
00383 int n = NEVT;
00384
00385 w.Start();
00386 r.SetSeed(0);
00387 for (int i = 0; i < n; ++i) {
00388 double x = r.Landau();
00389 if (fillHist)
00390 h.Fill( x );
00391
00392 }
00393 w.Stop();
00394 if (fillHist) { fillHist=false; return; }
00395 std::cout << "Landau " << "\t\t\t\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00396 << w.CpuTime()*1.0E9/NEVT
00397 << "\t(ns/call)" << std::endl;
00398
00399 fillHist = true;
00400 testLandau(r,h);
00401 }
00402
00403
00404
00405
00406 template <class R>
00407 void testBreitWigner( R & r,double mu,double gamma,TH1D & h) {
00408
00409 TStopwatch w;
00410
00411 int n = NEVT;
00412
00413 w.Start();
00414 r.SetSeed(0);
00415 for (int i = 0; i < n; ++i) {
00416 double x = r.BreitWigner(mu,gamma );
00417 if (fillHist)
00418 h.Fill( x );
00419 }
00420 w.Stop();
00421 if (fillHist) { fillHist=false; return; }
00422 std::cout << "Breit-Wigner - m,g = " << mu << " , " << gamma << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00423 << w.CpuTime()*1.0E9/NEVT
00424 << "\t(ns/call)" << std::endl;
00425
00426 fillHist = true;
00427 testBreitWigner(r,mu,gamma,h);
00428 }
00429
00430
00431
00432 template <class R>
00433 void testBinomial( R & r,int ntot,double p,TH1D & h) {
00434
00435 TStopwatch w;
00436
00437 int n = NEVT;
00438
00439 w.Start();
00440 r.SetSeed(0);
00441 for (int i = 0; i < n; ++i) {
00442 double x = double( r.Binomial(ntot,p ) );
00443 if (fillHist)
00444 h.Fill( x );
00445 }
00446 w.Stop();
00447 if (fillHist) { fillHist=false; return; }
00448 std::cout << "Binomial - ntot,p = " << ntot << " , " << p << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00449 << w.CpuTime()*1.0E9/NEVT
00450 << "\t(ns/call)" << std::endl;
00451
00452 fillHist = true;
00453 testBinomial(r,ntot,p,h);
00454 }
00455
00456
00457 template<class R>
00458 void testBinomialCLHEP( R & r,int ntot,double p,TH1D & h) {
00459
00460 TStopwatch w;
00461
00462 int n = NEVT;
00463
00464 w.Start();
00465
00466 for (int i = 0; i < n; ++i) {
00467 double x = double( r(ntot,p ) );
00468 if (fillHist)
00469 h.Fill( x );
00470 }
00471 w.Stop();
00472 if (fillHist) { fillHist=false; return; }
00473 std::cout << "Binomial - ntot,p = " << ntot << " , " << p << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00474 << w.CpuTime()*1.0E9/NEVT
00475 << "\t(ns/call)" << std::endl;
00476
00477 fillHist = true;
00478 testBinomialCLHEP(r,ntot,p,h);
00479 }
00480
00481
00482 template <class R>
00483 void testMultinomial( R & r,int ntot, TH1D & h1, TH1D & h2) {
00484
00485
00486 const int nbins = h1.GetNbinsX();
00487 std::vector<double> p(nbins);
00488 double psum = 0;
00489 for (int i = 0; i < nbins; ++i) {
00490 double x1 = h1.GetBinLowEdge(i+1);
00491 double x2 = x1 + h1.GetBinWidth(i+1);
00492 p[i] = ROOT::Math::normal_cdf(x2) - ROOT::Math::normal_cdf(x1);
00493 psum += p[i];
00494 }
00495
00496
00497 TStopwatch w;
00498 int n = NEVT/10;
00499 if (fillHist) n = 1;
00500
00501 for (int i = 0; i < n; ++i) {
00502 std::vector<unsigned int> multDist = r.Multinomial(ntot,p);
00503 if (fillHist) {
00504 for (int j = 0; j < nbins; ++j) h1.SetBinContent(j+1,multDist[j]);
00505 }
00506 }
00507 w.Stop();
00508
00509 if (!fillHist) {
00510 std::cout << "Multinomial - nb, ntot = " << nbins << " , " << ntot << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/n << " \t"
00511 << w.CpuTime()*1.0E9/n
00512 << "\t(ns/call)" << std::endl;
00513 }
00514
00515
00516
00517 w.Start();
00518 for (int i = 0; i < n; ++i) {
00519 for (int j = 0; j < nbins; ++j) {
00520 double y = r.Poisson(ntot*p[j]);
00521 if (fillHist) h2.SetBinContent(j+1,y);
00522 }
00523 }
00524 w.Stop();
00525 if (!fillHist) {
00526 std::cout << "Multi-Poisson - nb, ntot = " << nbins << " , " << ntot << "\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/n << " \t"
00527 << w.CpuTime()*1.0E9/n
00528 << "\t(ns/call)" << std::endl;
00529 }
00530
00531 if (fillHist) { fillHist=false; return; }
00532
00533
00534 fillHist = true;
00535 testMultinomial(r,ntot,h1,h2);
00536
00537 }
00538
00539
00540 template <class R>
00541 void testExp( R & r,TH1D & h) {
00542
00543 TStopwatch w;
00544
00545 int n = NEVT;
00546
00547 w.Start();
00548 r.SetSeed(0);
00549 for (int i = 0; i < n; ++i) {
00550 double x = r.Exp(1.);
00551 if (fillHist)
00552 h.Fill( x );
00553 }
00554 w.Stop();
00555 if (fillHist) { fillHist=false; return; }
00556 std::cout << "Exponential " << "\t\t\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00557 << w.CpuTime()*1.0E9/NEVT
00558 << "\t(ns/call)" << std::endl;
00559
00560 fillHist = true;
00561 testExp(r,h);
00562 }
00563
00564
00565 template <class R>
00566 void testCircle( R & r,TH1D & h) {
00567
00568 TStopwatch w;
00569
00570 int n = NEVT;
00571
00572 w.Start();
00573 r.SetSeed(0);
00574 double x,y;
00575 for (int i = 0; i < n; ++i) {
00576 r.Circle(x,y,1.0);
00577 if (fillHist)
00578 h.Fill( std::atan2(x,y) );
00579
00580 }
00581 w.Stop();
00582 if (fillHist) { fillHist=false; return; }
00583
00584 std::cout << "Circle " << "\t\t\t\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00585 << w.CpuTime()*1.0E9/NEVT
00586 << "\t(ns/call)" << std::endl;
00587
00588 fillHist = true;
00589 testCircle(r,h);
00590
00591 }
00592
00593
00594 template <class R>
00595 void testSphere( R & r,TH1D & h1, TH1D & h2 ) {
00596
00597
00598 #ifdef PLOT_SPHERE
00599 TH2D hxy("hxy","xy",100,-1.1,1.1,100,-1.1,1.1);
00600 TH3D h3d("h3d","sphere",100,-1.1,1.1,100,-1.1,1.1,100,-1.1,1.1);
00601 TH1D hz("hz","z",100,-1.1,1.1);
00602 #endif
00603
00604 TStopwatch w;
00605
00606
00607 int n = NEVT;
00608
00609 w.Start();
00610 r.SetSeed(0);
00611 double x,y,z;
00612 for (int i = 0; i < n; ++i) {
00613 r.Sphere(x,y,z,1.0);
00614 if (fillHist) {
00615
00616 h1.Fill( std::atan2(x,y) );
00617 h2.Fill( std::atan2( std::sqrt(x*x+y*y), z ) );
00618
00619 #ifdef PLOT_SPHERE
00620 hxy.Fill(x,y);
00621 hz.Fill(z);
00622 h3d.Fill(x,y,z);
00623 #endif
00624
00625 }
00626
00627 }
00628
00629 w.Stop();
00630
00631 #ifdef PLOT_SPHERE
00632 if (fillHist) {
00633 TCanvas *c1 = new TCanvas("c1_xyz","sphere",220,20,800,900);
00634 c1->Divide(2,2);
00635 c1->cd(1);
00636 hxy.DrawCopy();
00637 c1->cd(2);
00638 hz.DrawCopy();
00639 c1->cd(3);
00640 h3d.DrawCopy();
00641 c1->Update();
00642 }
00643 #endif
00644
00645 if (fillHist) { fillHist=false; return; }
00646
00647 std::cout << "Sphere " << "\t\t\t\t"<< findName(r) << "\tTime = " << w.RealTime()*1.0E9/NEVT << " \t"
00648 << w.CpuTime()*1.0E9/NEVT
00649 << "\t(ns/call)" << std::endl;
00650
00651
00652 fillHist = true;
00653 testSphere(r,h1,h2);
00654
00655 }
00656
00657
00658 int testRandomDist() {
00659
00660 std::cout << "***************************************************\n";
00661 std::cout << " TEST RANDOM DISTRIBUTIONS NEVT = " << NEVT << std::endl;
00662 std::cout << "***************************************************\n\n";
00663
00664
00665
00666 Random<GSLRngMT> r;
00667 TRandom3 tr;
00668 #ifdef HAVE_UNURAN
00669 UnuRanDist ur;
00670 #else
00671 TRandom2 ur;
00672 #endif
00673
00674
00675 double xmin = 0;
00676 double xmax = 1;
00677 int nch = 1000;
00678 TH1D hf1("hf1","FLAT ROOT",nch,xmin,xmax);
00679 TH1D hf2("hf2","Flat GSL",nch,xmin,xmax);
00680
00681 testFlat(r,hf1);
00682 testFlat(tr,hf2);
00683 testDiff(hf1,hf2,"Flat ROOT-GSL");
00684
00685 #ifdef HAVE_CLHEP
00686 HepJamesRandom eng;
00687 RandFlat crf(eng);
00688 TH1D hf3("hf3","Flat CLHEP",nch,xmin,xmax);
00689 testFlatCLHEP(crf,hf3);
00690 testDiff(hf3,hf1,"Flat CLHEP-GSL");
00691 #endif
00692
00693
00694
00695
00696 std::cout << std::endl;
00697
00698 double mu = 25;
00699 xmin = std::floor(std::max(0.0,mu-5*std::sqrt(mu) ) );
00700 xmax = std::floor( mu+5*std::sqrt(mu) );
00701 nch = std::min( int(xmax-xmin),1000);
00702 TH1D hp1("hp1","Poisson ROOT",nch,xmin,xmax);
00703 TH1D hp2("hp2","Poisson GSL",nch,xmin,xmax);
00704 TH1D hp3("hp3","Poisson UNR",nch,xmin,xmax);
00705
00706 testPoisson(r,mu,hp1);
00707 testPoisson(tr,mu,hp2);
00708 testPoisson(ur,mu,hp3);
00709 #ifdef HAVE_CLHEP
00710 RandPoissonT crp(eng);
00711 TH1D hp4("hp4","Poisson CLHEP",nch,xmin,xmax);
00712 testPoissonCLHEP(crp,mu,hp4);
00713 #endif
00714
00715
00716 testDiff(hp1,hp2,"Poisson ROOT-GSL");
00717 testDiff(hp1,hp3,"Poisson ROOT-UNR");
00718 #ifdef HAVE_CLHEP
00719 testDiff(hp1,hp4,"Poisson ROOT-CLHEP");
00720 #endif
00721
00722
00723 std::cout << std::endl;
00724
00725 TH1D hg1("hg1","Gaussian ROOT",nch,xmin,xmax);
00726 TH1D hg2("hg2","Gaussian GSL",nch,xmin,xmax);
00727 TH1D hg3("hg3","Gaussian UNURAN",nch,xmin,xmax);
00728
00729
00730 testGaus(r,mu,sqrt(mu),hg1);
00731 testGaus(tr,mu,sqrt(mu),hg2);
00732
00733 testGaus(ur,mu,sqrt(mu),hg3);
00734 #ifdef HAVE_CLHEP
00735 RandGauss crg(eng);
00736 TH1D hg4("hg4","Gauss CLHEP",nch,xmin,xmax);
00737 testGausCLHEP(crg,mu,sqrt(mu),hg4);
00738 RandGaussQ crgQ(eng);
00739 testGausCLHEP(crgQ,mu,sqrt(mu),hg4);
00740 RandGaussT crgT(eng);
00741 testGausCLHEP(crgT,mu,sqrt(mu),hg4);
00742 #endif
00743
00744
00745 testDiff(hg1,hg2,"Gaussian ROOT-GSL");
00746 testDiff(hg1,hg3,"Gaussian ROOT_UNR");
00747
00748
00749 std::cout << std::endl;
00750
00751 TH1D hl1("hl1","Landau ROOT",300,0,50);
00752 TH1D hl2("hl2","Landau GSL",300,0,50);
00753
00754 testLandau(r,hl1);
00755 testLandau(tr,hl2);
00756 testDiff(hl1,hl2,"Landau");
00757
00758
00759 std::cout << std::endl;
00760
00761 TH1D hbw1("hbw1","BreitWigner ROOT",nch,xmin,xmax);
00762 TH1D hbw2("hbw2","BreitWigner GSL",nch,xmin,xmax);
00763
00764
00765 testBreitWigner(r,mu,sqrt(mu),hbw1);
00766 testBreitWigner(tr,mu,sqrt(mu),hbw2);
00767 testDiff(hbw1,hbw2,"Breit-Wigner");
00768
00769
00770 std::cout << std::endl;
00771
00772 int ntot = 100;
00773 double p =0.1;
00774 xmin = 0;
00775 xmax = ntot+1;
00776 nch = std::min(1000,ntot+1);
00777 TH1D hb1("hb1","Binomial ROOT",nch,xmin,xmax);
00778 TH1D hb2("hb2","Binomial GSL",nch,xmin,xmax);
00779 TH1D hb3("hb3","Binomial UNR",nch,xmin,xmax);
00780
00781
00782 testBinomial(r,ntot,p,hb1);
00783 testBinomial(tr,ntot,p,hb2);
00784 testBinomial(ur,ntot,p,hb3);
00785 #ifdef HAVE_CLHEP
00786 RandBinomial crb(eng);
00787 TH1D hb4("hb4","Binomial CLHEP",nch,xmin,xmax);
00788 testBinomialCLHEP(crb,ntot,p,hp4);
00789 #endif
00790
00791
00792 testDiff(hb1,hb2,"Binomial ROOT-GSL");
00793 testDiff(hb1,hb3,"Binomial ROOT-UNR");
00794
00795
00796 std::cout << std::endl;
00797
00798 TH1D hmt1("hmt1","Multinomial GSL",30,-3,3);
00799 TH1D hmt2("hmt2","Multi-Poisson GSL",30,-3,3);
00800 TH1D hmt3("hmt3","Gaus",30,-3,3);
00801 ntot = 10000;
00802 testMultinomial(r,ntot,hmt1,hmt2);
00803 hmt3.FillRandom("gaus",ntot);
00804 testDiff(hmt1,hmt2,"Multinomial-Poisson");
00805 testDiff(hmt1,hmt3,"Multinomial-gaus");
00806
00807
00808
00809 std::cout << std::endl;
00810
00811 TH1D he1("he1","Exp ROOT",300,0,20);
00812 TH1D he2("he2","Exp GSL",300,0,20);
00813
00814 testExp(r,he1);
00815 testExp(tr,he2);
00816 testDiff(he1,he2,"Exponential");
00817
00818
00819 std::cout << std::endl;
00820
00821 TH1D hc1("hc1","Circle ROOT",300,-PI,PI);
00822 TH1D hc2("hc2","Circle GSL",300,-PI,PI);
00823
00824 testCircle(r,hc1);
00825 testCircle(tr,hc2);
00826 testDiff(hc1,hc2,"Circle");
00827
00828
00829
00830 std::cout << std::endl;
00831
00832 TH1D hs1("hs1","Sphere-Phi ROOT",300,-PI,PI);
00833 TH1D hs2("hs2","Sphere-Phi GSL ",300,-PI,PI);
00834 TH1D hs3("hs3","Sphere-Theta ROOT",300,0,PI);
00835 TH1D hs4("hs4","Sphere-Theta GSL ",300,0,PI);
00836
00837 testSphere(r,hs1,hs3);
00838 testSphere(tr,hs2,hs4);
00839 testDiff(hs1,hs2,"Sphere-phi");
00840 testDiff(hs3,hs4,"Sphere-theta");
00841
00842
00843 return 0;
00844
00845 }
00846
00847 int main() {
00848 return testRandomDist();
00849 }