#include "utl/RandomSamplerFromPDF.h"
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 | |
RandomSamplerFromCDF * | fCDF |
ShadowPtr< std::vector< double > > | fPDF |
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.
Definition at line 42 of file RandomSamplerFromPDF.h.
Interpolation types Depending on the interpolation type chosen at construction, the distribution of values will conform to:
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.
|
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 |
||
) |
Construct using a PDF defined by a Tabulated Function.
Definition at line 15 of file RandomSamplerFromPDF.cc.
References fwk::CoordinateSystemRegistry::Init(), utl::TabulatedFunction::XBegin(), utl::TabulatedFunction::XEnd(), utl::TabulatedFunction::YBegin(), and utl::TabulatedFunction::YEnd().
|
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 |
||
) |
|
inline |
Construct the PDF from a function defined by a string.
Definition at line 82 of file RandomSamplerFromPDF.h.
References SetFunction().
|
inline |
Construct the PDF from a function defined by a string.
Definition at line 88 of file RandomSamplerFromPDF.h.
References SetFunction().
|
virtual |
Definition at line 38 of file RandomSamplerFromPDF.cc.
|
inherited |
double RandomSamplerFromPDF::GetInverseCDF | ( | const double | y | ) | const |
Definition at line 45 of file RandomSamplerFromPDF.cc.
References sqrt().
Referenced by MapRandom(), and TestRandomSamplerFromPDF::TestTabulatedFunction().
|
private |
Definition at line 91 of file RandomSamplerFromPDF.cc.
Referenced by RandomSamplerFromPDF().
|
private |
Definition at line 119 of file RandomSamplerFromPDF.cc.
References fwk::CoordinateSystemRegistry::Init(), and UniformFill().
|
private |
Definition at line 159 of file RandomSamplerFromPDF.cc.
References Normalize().
|
private |
Definition at line 211 of file RandomSamplerFromPDF.cc.
References Normalize().
|
private |
Definition at line 187 of file RandomSamplerFromPDF.cc.
References Normalize().
|
inlineprotectedvirtual |
Implements utl::VRandomSampler.
Definition at line 97 of file RandomSamplerFromPDF.h.
References GetInverseCDF().
|
private |
Definition at line 71 of file RandomSamplerFromPDF.cc.
Referenced by RandomSamplerFromPDF().
|
inlineinherited |
Method to shoot random values using a given engine by-passing the static generator.
Definition at line 38 of file VRandomSampler.h.
References utl::VRandomSampler::MapRandom().
Referenced by ParticleInjectorNEU::ParticleInjector::GenerateAzimuth(), ParticleInjectorNEU::ParticleInjector::GenerateEnergy(), ParticleInjectorNEU::ParticleInjector::GeneratePosition(), ParticleInjectorNEU::ParticleInjector::GenerateZenith(), utl::MuonTimeModel::GetFirstAndMeanTime(), utl::MuonTimeModel::GetFirstTime(), utl::MuonTimeModel::GetLastTime(), utl::MuonTimeModel::GetMeanTime(), utl::MuonTimeModel::GetTimes(), ShowerPhotonGeneratorOG::ShowerPhotonGenerator::LateralDistributionScatteredCherenkov(), ShowerPhotonGeneratorOG::ShowerPhotonGenerator::Run(), TestRandomSamplerFromCDF::TestFunction(), TestRandomSamplerFromCDF::TestMap(), TestRandomSamplerFromCDF::TestTabulatedFunction(), TestRandomSamplerFromPDF::TestTabulatedFunction(), TestRandomSamplerFromCDF::TestVectorAndNormalization(), and TestRandomSamplerFromCDF::TestVectors().
|
inherited |
Method to shoot random values using a given engine by-passing the static generator.
Definition at line 45 of file VRandomSampler.h.
|
private |
Definition at line 117 of file RandomSamplerFromPDF.h.
|
private |
Definition at line 118 of file RandomSamplerFromPDF.h.
|
inherited |
Definition at line 49 of file VRandomSampler.h.