OMSim
Geant4 for IceCube optical module studies
Loading...
Searching...
No Matches
DistributionSampler Class Reference

Utility class for sampling from a given distribution using the inverse cumulative function and interpolating with TGraph.

Public Member Functions

G4double sampleFromDistribution ()
 Samples values from a given distribution using the Inverse CDF algorithm.
 
void setData (const std::vector< G4double > &pX, const std::vector< G4double > &pY, G4String pName)
 Sets data for the distribution.
 
void makeInterpolator ()
 Initializes the interpolator using TGraph.
 
void setUnits (G4double pX, G4double pY)
 Sets units for the x and y data points of the distribution.
 
G4double interpolate (G4double pX)
 Interpolates distribution using TGraph (ROOT)
 

Private Member Functions

void calculateSlopesAndCDF ()
 Calculates the slopes and cumulative function of a dataset for the inverse cumulative algorithm.
 

Private Attributes

G4double m_XUnit
 
G4double m_YUnit
 
std::vector< G4double > m_X
 
std::vector< G4double > m_Y
 
std::vector< G4double > m_slopes
 
std::vector< G4double > m_CDF
 
G4String m_distName
 
TGraph * m_interpolator = nullptr
 

Member Function Documentation

◆ calculateSlopesAndCDF()

void DistributionSampler::calculateSlopesAndCDF ( )
private

This function computes the slopes and cumulative function values for the given dataset. These results are often used in the inverse cumulative algorithm.

◆ interpolate()

G4double DistributionSampler::interpolate ( G4double  p_x)
Parameters
x-p_value
Returns
The interpolated y-p_value for the given x.

◆ makeInterpolator()

void DistributionSampler::makeInterpolator ( )

This method creates a new TGraph instance with the stored data points and sets its name to the name of the distribution.

◆ sampleFromDistribution()

G4double DistributionSampler::sampleFromDistribution ( )

This method employs the inverse cumulative distribution function (Inverse CDF) technique to derive samples from a specified distribution. It's useful for generating random values in accordance with the underlying distribution shape.

Returns
A randomly selected x-p_value sampled in line with the provided distribution.

◆ setData()

void DistributionSampler::setData ( const std::vector< G4double > &  p_x,
const std::vector< G4double > &  p_y,
G4String  p_name 
)

This method sets the x and y data points for the distribution and assigns a name to it for the TGraph (if used).

Parameters
p_xVector containing x-values of the data.
p_yVector containing y-values of the data.
p_nameName for the distribution, used for debugging and TGraph name assignment.

◆ setUnits()

void DistributionSampler::setUnits ( G4double  p_x,
G4double  p_y 
)
Parameters
p_xUnit for x-values.
p_yUnit for y-values.

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