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 initialize Unuran with method %s",method.
Data() );
99 else Error(
"TUnuranSampler::Init",
"Failed to initialize Unuran with method %s",method.
Data() );
114 auto appendOption = [&](
const std::string & key,
const std::string & val) {
123 for (
auto &
name : names) {
128 for (
auto &
name : names) {
133 for (
auto &
name : names) {
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());
249 SetFunction<TF1>(*pdf, pdf->
GetNdim());
283 if (!
r)
return false;
285 if (error) *error = std::sqrt(prob);
293 if (
mode.size() == 1)
301 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.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char mode
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()
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
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.
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...