List of all members | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes
utl::RandomSamplerFromPDF Class Reference

#include "utl/RandomSamplerFromPDF.h"

Inheritance diagram for utl::RandomSamplerFromPDF:
Inheritance graph
[legend]

Public Types

enum  InterpolationType { eLinear, eDiscrete, eStep }
 

Public Member Functions

engine flatArray (size, rand)
 
double GetInverseCDF (const double y) const
 
 RandomSamplerFromPDF (const std::vector< double > &x, const std::vector< double > &y, const InterpolationType intType=eStep)
 Construct using a PDF defined by an X and Y vectors. More...
 
 RandomSamplerFromPDF (const TabulatedFunction &pdf, const InterpolationType intType=eStep)
 Construct using a PDF defined by a Tabulated Function. More...
 
 RandomSamplerFromPDF (const std::vector< double > &pdf, const InterpolationType intType=eStep)
 Construct using a PDF defined by an std::vector<double>, the old CLHEP behaviour. More...
 
 RandomSamplerFromPDF (const std::map< double, double > &pdf, const InterpolationType intType=eDiscrete)
 
 RandomSamplerFromPDF (const std::string &function, const std::string &independentVariableName, const double min, const double max, const int bins=100)
 Construct the PDF from a function defined by a string. More...
 
 RandomSamplerFromPDF (const std::string &function, const double min, const double max, const int bins=100)
 Construct the PDF from a function defined by a string. More...
 
double shoot (HepEngine &engine) const
 Method to shoot random values using a given engine by-passing the static generator. More...
 
virtual ~RandomSamplerFromPDF ()
 

Public Attributes

void const
 Method to shoot random values using a given engine by-passing the static generator. More...
 
 vect [i] = MapRandom(rand[i])
 

Protected Member Functions

virtual double MapRandom (const double rand) const
 

Private Member Functions

void Init (const std::vector< double > &x, const std::vector< double > &y, const InterpolationType intType)
 
void Init (const std::vector< double > &y, const InterpolationType intType)
 
void InitDiscrete (const std::vector< double > &x, const std::vector< double > &y)
 
void InitLinear (const std::vector< double > &x, const std::vector< double > &y)
 
void InitStep (const std::vector< double > &x, const std::vector< double > &y)
 
void SetFunction (const std::string &function, const std::string &independentVariableName, const double min, const double max, const int bins)
 

Private Attributes

RandomSamplerFromCDFfCDF
 
ShadowPtr< std::vector< double > > fPDF
 

Detailed Description

This class is based on a re-write of CLHEP's randGeneral class with a couple of additions and changes.

It can be constructed using a TabulatedFunction as the probability distribution function. It can also be constructed giving a string formula (as in ROOT).

If you construct the distribution with an std::vector<double> as the PDF it will behave the same way RandGeneral does (changing double* by std::vector<double>, of course). In this case it will give numbers in [0,1) dividing the interval in subintervals of equal length.

In all cases, there are different InterpolationTypes that specify whether the distribution will be discrete (only the values specified in the TabulatedFunction), a step function or linerly interpolated.

Input does not have to be normalized.

Author
Darko Veberic
Date
29 Aug 2009

Definition at line 42 of file RandomSamplerFromPDF.h.

Member Enumeration Documentation

Interpolation types Depending on the interpolation type chosen at construction, the distribution of values will conform to:

  • a discrete pdf over the values in the x axis of the TabulatedFunction, with relative probabilities given by the y values of the TabulatedFunction,
  • a step pdf, constant in between consecutive x values and relative probability densities given by the y values (note that in this case the y value in the last point of the TabulatedFunction is discarded), or
  • a linearly interpolated, continuous function.

The behaviour when creating with a vector is the same except the range of the function is [0, 1], equally subdivided.

Enumerator
eLinear 
eDiscrete 
eStep 

Definition at line 58 of file RandomSamplerFromPDF.h.

Constructor & Destructor Documentation

utl::RandomSamplerFromPDF::RandomSamplerFromPDF ( const std::vector< double > &  x,
const std::vector< double > &  y,
const InterpolationType  intType = eStep 
)
inline

Construct using a PDF defined by an X and Y vectors.

Definition at line 65 of file RandomSamplerFromPDF.h.

References Init().

RandomSamplerFromPDF::RandomSamplerFromPDF ( const TabulatedFunction pdf,
const InterpolationType  intType = eStep 
)
utl::RandomSamplerFromPDF::RandomSamplerFromPDF ( const std::vector< double > &  pdf,
const InterpolationType  intType = eStep 
)
inline

Construct using a PDF defined by an std::vector<double>, the old CLHEP behaviour.

Definition at line 74 of file RandomSamplerFromPDF.h.

References Init().

utl::RandomSamplerFromPDF::RandomSamplerFromPDF ( const std::map< double, double > &  pdf,
const InterpolationType  intType = eDiscrete 
)
utl::RandomSamplerFromPDF::RandomSamplerFromPDF ( const std::string &  function,
const std::string &  independentVariableName,
const double  min,
const double  max,
const int  bins = 100 
)
inline

Construct the PDF from a function defined by a string.

Definition at line 82 of file RandomSamplerFromPDF.h.

References SetFunction().

utl::RandomSamplerFromPDF::RandomSamplerFromPDF ( const std::string &  function,
const double  min,
const double  max,
const int  bins = 100 
)
inline

Construct the PDF from a function defined by a string.

Definition at line 88 of file RandomSamplerFromPDF.h.

References SetFunction().

RandomSamplerFromPDF::~RandomSamplerFromPDF ( )
virtual

Definition at line 38 of file RandomSamplerFromPDF.cc.

Member Function Documentation

engine utl::VRandomSampler::flatArray ( size  ,
rand   
)
inherited
double RandomSamplerFromPDF::GetInverseCDF ( const double  y) const

Definition at line 45 of file RandomSamplerFromPDF.cc.

References sqrt().

Referenced by MapRandom(), and TestRandomSamplerFromPDF::TestTabulatedFunction().

void RandomSamplerFromPDF::Init ( const std::vector< double > &  x,
const std::vector< double > &  y,
const InterpolationType  intType 
)
private

Definition at line 91 of file RandomSamplerFromPDF.cc.

Referenced by RandomSamplerFromPDF().

void RandomSamplerFromPDF::Init ( const std::vector< double > &  y,
const InterpolationType  intType 
)
private
void RandomSamplerFromPDF::InitDiscrete ( const std::vector< double > &  x,
const std::vector< double > &  y 
)
private

Definition at line 159 of file RandomSamplerFromPDF.cc.

References Normalize().

void RandomSamplerFromPDF::InitLinear ( const std::vector< double > &  x,
const std::vector< double > &  y 
)
private

Definition at line 211 of file RandomSamplerFromPDF.cc.

References Normalize().

void RandomSamplerFromPDF::InitStep ( const std::vector< double > &  x,
const std::vector< double > &  y 
)
private

Definition at line 187 of file RandomSamplerFromPDF.cc.

References Normalize().

virtual double utl::RandomSamplerFromPDF::MapRandom ( const double  rand) const
inlineprotectedvirtual

Implements utl::VRandomSampler.

Definition at line 97 of file RandomSamplerFromPDF.h.

References GetInverseCDF().

void RandomSamplerFromPDF::SetFunction ( const std::string &  function,
const std::string &  independentVariableName,
const double  min,
const double  max,
const int  bins 
)
private

Definition at line 71 of file RandomSamplerFromPDF.cc.

Referenced by RandomSamplerFromPDF().

double utl::VRandomSampler::shoot ( HepEngine engine) const
inlineinherited

Member Data Documentation

void utl::VRandomSampler::const
inherited
Initial value:
{
double rand[size]

Method to shoot random values using a given engine by-passing the static generator.

Definition at line 45 of file VRandomSampler.h.

RandomSamplerFromCDF* utl::RandomSamplerFromPDF::fCDF
private

Definition at line 117 of file RandomSamplerFromPDF.h.

ShadowPtr<std::vector<double> > utl::RandomSamplerFromPDF::fPDF
private

Definition at line 118 of file RandomSamplerFromPDF.h.

utl::VRandomSampler::vect[i] = MapRandom(rand[i])
inherited

Definition at line 49 of file VRandomSampler.h.


The documentation for this class was generated from the following files:

, generated on Tue Sep 26 2023.