57 Error(
"TUnuranSampler::Init",
58 "Unuran initialization string is invalid or the Distribution function has not been set and one needs to call SetFunction first.");
61 int ndim =
fUnuran->GetDimension();
81 if (method.
First(
"D") == 0) {
82 if (
fLevel>1)
Info(
"TUnuranSampler::Init",
"Initialize one-dim discrete distribution with method %s",method.
Data());
86 if (
fLevel>1)
Info(
"TUnuranSampler::Init",
"Initialize one-dim continuous distribution with method %s",method.
Data());
91 if (
fLevel>1)
Info(
"TUnuranSampler::Init",
"Initialize multi-dim continuous distribution with method %s",method.
Data());
97 if (
ret)
Info(
"TUnuranSampler::Init",
"Successfully initialize Unuran with method %s",method.
Data() );
98 else Error(
"TUnuranSampler::Init",
"Failed to initialize Unuran with method %s",method.
Data() );
113 auto appendOption = [&](
const std::string & key,
const std::string & val) {
122 for (
auto &
name : names) {
124 appendOption(
name,value);
127 for (
auto &
name : names) {
129 appendOption(
name,value);
132 for (
auto &
name : names) {
134 appendOption(
name,value);
137 Info(
"Init",
"Initialize UNU.RAN with Method option string: %s",optionStr.c_str());
138 return Init(optionStr.c_str() );
156 Error(
"DoInit1D",
"No PDF, CDF or DPDF function has been set");
167 if (range.
Size(0) > 0) {
176 if (method)
ret =
fUnuran->Init(*dist, method);
189 Error(
"DoInitDiscrete1D",
"No PMF has been defined");
205 if (range.
Size(0) > 0) {
209 Warning(
"DoInitDiscrete1D",
"range starts from negative values - set minimum to zero");
212 dist->SetDomain(
int(
xmin+0.1),
int(
xmax+0.1));
226 Error(
"DoInitND",
"No PDF has been defined");
233 std::vector<double>
xmin(range.
NDim() );
234 std::vector<double>
xmax(range.
NDim() );
236 dist.SetDomain(&
xmin.front(),&
xmax.front());
242 if (method)
return fUnuran->Init(dist, method);
282 if (!
r)
return false;
283 value =
r->Poisson(prob);
284 if (error) *error = std::sqrt(prob);
292 if (mode.size() == 1)
300 Error(
"SetMode",
"modes vector is not compatible with function dimension of %d", (
int)
ParentPdf().
NDim());
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
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 retrieving 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()
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.
const ROOT::Math::IGenFunction * fDPDF
1D Derivative function pointer
bool Init(const char *algo="") override
initialize the generators with the given algorithm If no algorithm is passed used the default one for...
const ROOT::Math::IGenFunction * fCDF
CDF function pointer.
void SetRandom(TRandom *r) override
Set the random engine to be used Needs to be called before Init to have effect.
void SetFunction(const ROOT::Math::IGenFunction &func) override
Set the parent function distribution to use for random sampling (one dim case).
TRandom * GetRandom() override
Get the random engine used by the sampler.
bool fHasMode
flag to indicate if a mode is set
bool fHasArea
flag to indicate if a area is set
void SetSeed(unsigned int seed) override
Set the random seed for the TRandom instances used by the sampler classes Needs to be called before I...
void SetPrintLevel(int level)
Set the print level (if level=-1 use default).
bool DoInitND(const char *algo)
Initialization for multi-dim distributions.
TUnuran * fUnuran
unuran engine class
const ROOT::Math::IGenFunction * fFunc1D
1D function pointer (pdf)
bool DoInit1D(const char *algo)
Initialization for 1D distributions.
void SetMode(double mode) override
Set the mode of the distribution (1D case).
bool fUseLogPdf
flag to indicate if we use the log of the PDF
double Sample1D() override
sample one event in one dimension better implementation could be provided by the derived classes
void SetDPdf(const ROOT::Math::IGenFunction &dpdf) override
set the Derivative of the PDF used for random sampling (one dim continuous case)
TUnuranSampler()
default constructor
bool fDiscrete
flag to indicate if the function is discrete
bool fOneDim
flag to indicate if the function is 1 dimension
void SetCdf(const ROOT::Math::IGenFunction &cdf) override
set the cumulative distribution function of the PDF used for random sampling (one dim case)
double fMode
mode of dist (1D)
std::vector< double > fNDMode
mode of the multi-dim distribution
~TUnuranSampler() override
virtual destructor
bool SampleBin(double prob, double &value, double *error=nullptr) override
sample one bin given an estimated of the pdf in the bin (this can be function value at the center or ...
bool DoInitDiscrete1D(const char *algo)
Initialization for 1D discrete distributions.
std::string ToString(const T &val)
Utility function for conversion to strings.
IBaseFunctionOneDim IGenFunction