UnuRanDist.h

Go to the documentation of this file.
00001 // class to test unuran dist
00002 
00003 #include "TUnuran.h"
00004 #include "Math/Util.h"
00005 
00006 #include <iostream> 
00007 #include <cassert> 
00008 
00009 class UnuRanDist { 
00010 public:
00011 
00012 
00013    UnuRanDist() : first(true) {
00014       // use default grandom
00015    }
00016    
00017 
00018       //~UnuRanDist() { if (fUnuran) delete fUnuran; }                                               
00019 
00020    void SetSeed(int seed) {
00021       gRandom->SetSeed(seed);
00022       first = true; 
00023    }
00024    
00025    double Gaus(double mu, double sigma) {
00026       if (first) { 
00027          //if (!fUnuran.Init("normal()", "method=cstd;variant=0") ) { // acr method (default)
00028          if (!fUnuran.Init("normal()", "method=cstd;variant=6") ) {
00029             assert(0);
00030          }
00031          first = false;
00032       }
00033       return mu + sigma* fUnuran.Sample();
00034    }
00035 
00036    int Poisson(double mu) { 
00037       if (first) { 
00038 //          std::string smu = ROOT::Math::Util::ToString(mu);
00039 //          std::string dist = "poisson(" + smu + ")";
00040 //          if (!fUnuran.Init(dist, "method=dstd") ) {
00041 //             assert(0);
00042 //          }
00043           if (!fUnuran.InitPoisson(mu,"method=dstd") ) {
00044              assert(0);
00045           }
00046          
00047          first = false;
00048       }
00049       else { 
00050          par[0] = mu; 
00051          fUnuran.ReInitDiscrDist(1,par);
00052       }
00053       return fUnuran.SampleDiscr();
00054    }
00055 
00056    int Binomial(int n, double p) { 
00057       if (first) { 
00058 //          std::string sn = ROOT::Math::Util::ToString(n);
00059 //          std::string sp = ROOT::Math::Util::ToString(p);
00060 //          std::string dist = "binomial(" + sn + "," + sp + ")";
00061 //          std::cout << dist << std::endl;
00062          if (!fUnuran.InitBinomial(n,p,"method=dstd") ) {
00063              assert(0);
00064           }
00065          first = false;
00066       }
00067       else { 
00068          par[0] = n; 
00069          par[1] = p; 
00070          fUnuran.ReInitDiscrDist(2,par);
00071       }
00072       return fUnuran.SampleDiscr();
00073    }
00074 
00075 
00076 
00077 private:
00078    TUnuran fUnuran; 
00079    bool  first;
00080    double par[2]; 
00081 };

Generated on Tue Jul 5 14:35:00 2011 for ROOT_528-00b_version by  doxygen 1.5.1