36 fHasMode(false), fHasArea(false),
58 Error(
"TUnuranSampler::Init",
59 "Unuran initialization string is invalid or the Distribution function has not been set and one needs to call SetFunction first.");
82 if (method.
First(
"D") == 0) {
83 if (
fLevel>1)
Info(
"TUnuranSampler::Init",
"Initialize one-dim discrete distribution with method %s",method.
Data());
87 if (
fLevel>1)
Info(
"TUnuranSampler::Init",
"Initialize one-dim continuous distribution with method %s",method.
Data());
92 if (
fLevel>1)
Info(
"TUnuranSampler::Init",
"Initialize multi-dim continuous distribution with method %s",method.
Data());
98 if (ret)
Info(
"TUnuranSampler::Init",
"Successfully initailized Unuran with method %s",method.
Data() );
99 else Error(
"TUnuranSampler::Init",
"Failed to initailize Unuran with method %s",method.
Data() );
114 auto appendOption = [&](
const std::string & key,
const std::string & val) {
123 for (
auto &
name : names) {
125 appendOption(
name,value);
128 for (
auto &
name : names) {
130 appendOption(
name,value);
133 for (
auto &
name : names) {
135 appendOption(
name,value);
138 Info(
"Init",
"Initialize UNU.RAN with Method option string: %s",optionStr.c_str());
139 return Init(optionStr.c_str() );
157 Error(
"DoInit1D",
"No PDF, CDF or DPDF function has been set");
168 if (range.
Size(0) > 0) {
190 Error(
"DoInitDiscrete1D",
"No PMF has been defined");
206 if (range.
Size(0) > 0) {
210 Warning(
"DoInitDiscrete1D",
"range starts from negative values - set minimum to zero");
213 dist->SetDomain(
int(
xmin+0.1),
int(
xmax+0.1));
227 Error(
"DoInitND",
"No PDF has been defined");
234 std::vector<double>
xmin(range.
NDim() );
235 std::vector<double>
xmax(range.
NDim() );
237 dist.SetDomain(&
xmin.front(),&
xmax.front());
254 SetFunction<TF1>(*pdf, pdf->
GetNdim());
288 if (!
r)
return false;
289 value =
r->Poisson(prob);
290 if (error) *error = std::sqrt(prob);
298 if (mode.size() == 1)
306 Error(
"SetMode",
"modes vector is not compatible with function dimension of %d", (
int)
ParentPdf().
NDim());
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
class describing the range in the coordinates it supports multiple range in a coordinate.
bool IsSet() const
return true if a range has been set in any of the coordinates i.e.
unsigned int NDim() const
get range dimension
unsigned int Size(unsigned int icoord=0) const
return range size for coordinate icoord (starts from zero) Size == 0 indicates no range is present [-...
void GetRange(unsigned int irange, unsigned int icoord, double &xmin, double &xmax) const
get the i-th range for given coordinate.
DistSampler options class.
int PrintLevel() const
non-static methods for retrivieng options
static int DefaultPrintLevel()
const std::string & Algorithm() const
type of algorithm (method)
IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
static const std::string & DefaultAlgorithmND()
static const std::string & DefaultAlgorithm1D()
const double * Sample()
Sample one event and return an array x with sample coordinates values.
const ROOT::Math::IMultiGenFunction & ParentPdf() const
Get the parent distribution function (must be called after setting the function).
unsigned int NDim() const
return the dimension of the parent distribution (and the data)
const ROOT::Fit::DataRange & PdfRange() const
return the data range of the Pdf . Must be called after setting the function
virtual void DoSetDimension(unsigned int ndim)
bool HasParentPdf() const
Check if there is a parent distribution defined.
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
std::vector< std::string > GetAllRealKeys()
std::vector< std::string > GetAllIntKeys()
std::vector< std::string > GetAllNamedKeys()
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
double RValue(const char *name) const
std::string NamedValue(const char *name) const
int IValue(const char *name) const
OneDimMultiFunctionAdapter class to wrap a multidimensional function in one dimensional one.
virtual Int_t GetNdim() const
This is the base class for the ROOT Random number generators.
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
void ToUpper()
Change string to upper case.
TUnuranContDist class describing one dimensional continuous distribution.
TUnuranDiscrDist class for one dimensional discrete distribution.
TUnuranMultiContDist class describing multi dimensional continuous distributions.
TUnuranSampler class class implementing the ROOT::Math::DistSampler interface using the UNU....
const ROOT::Math::IGenFunction * fDPDF
CDF function pointer.
double fArea
mode of dist (1D)
TRandom * GetRandom()
Get the random engine used by the sampler.
const ROOT::Math::IGenFunction * fCDF
1D function pointer (pdf)
void SetRandom(TRandom *r)
Set the random engine to be used Needs to be called before Init to have effect.
virtual ~TUnuranSampler()
virtual destructor
bool fHasMode
flag to indicate if the function is discrete
bool fHasArea
flag to indicate if a mode is set
bool SampleBin(double prob, double &value, double *error=0)
sample one bin given an estimated of the pdf in the bin (this can be function value at the center or ...
void SetPrintLevel(int level)
Set the print level (if level=-1 use default)
bool DoInitND(const char *algo)
Initialization for multi-dim distributions.
void SetSeed(unsigned int seed)
Set the random seed for the TRandom instances used by the sampler classes Needs to be called before I...
TUnuran * fUnuran
1D Derivative function pointer
const ROOT::Math::IGenFunction * fFunc1D
mode of the multi-dim distribution
void SetCdf(const ROOT::Math::IGenFunction &cdf)
set the cumulative distribution function of the PDF used for random sampling (one dim case)
bool DoInit1D(const char *algo)
Initialization for 1D distributions.
bool fUseLogPdf
flag to indicate if a area is set
void SetMode(double mode)
Set the mode of the distribution (1D case).
bool Init(const char *algo="")
initialize the generators with the given algorithm If no algorithm is passed used the default one for...
TUnuranSampler()
default constructor
bool fDiscrete
flag to indicate if the function is 1 dimension
void SetFunction(const ROOT::Math::IGenFunction &func)
Set the parent function distribution to use for random sampling (one dim case).
double Sample1D()
sample one event in one dimension better implementation could be provided by the derived classes
std::vector< double > fNDMode
area of dist
int fLevel
flag to indicate if we use the log of the PDF
bool DoInitDiscrete1D(const char *algo)
Initialization for 1D discrete distributions.
void SetDPdf(const ROOT::Math::IGenFunction &dpdf)
set the Derivative of the PDF used for random sampling (one dim continous case)
int SampleDiscr()
Sample discrete distributions.
bool SampleMulti(double *x)
Sample multidimensional distributions.
bool Init(const std::string &distr, const std::string &method)
Initialize with Unuran string API interface.
double Sample()
Sample 1D distribution.
TRandom * GetRandom()
Return instance of the random engine used.
int GetDimension() const
Return the dimension of unuran generator method.
void SetSeed(unsigned int seed)
set the seed for the random number generator
void SetRandom(TRandom *r)
Set the random engine.
bool IsDistDiscrete() const
Return true for a discrete distribution.
Namespace for new Math classes and functions.
std::string ToString(const T &val)
Utility function for conversion to strings.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...