BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Distribution1DTriangleSampler Class Reference

Description

Definition at line 69 of file IDistribution1DSampler.h.

Inheritance diagram for Distribution1DTriangleSampler:
[legend]
Collaboration diagram for Distribution1DTriangleSampler:
[legend]

Public Member Functions

 Distribution1DTriangleSampler (double omega)
 
double randomSample () const override
 

Private Attributes

double m_omega
 

Constructor & Destructor Documentation

◆ Distribution1DTriangleSampler()

Distribution1DTriangleSampler::Distribution1DTriangleSampler ( double  omega)
inline

Definition at line 71 of file IDistribution1DSampler.h.

72  : m_omega(omega)
73  {
74  }

Member Function Documentation

◆ randomSample()

double Distribution1DTriangleSampler::randomSample ( ) const
overridevirtual

Implements IDistribution1DSampler.

Definition at line 54 of file IDistribution1DSampler.cpp.

55 {
56  std::random_device rd;
57  std::mt19937 gen(rd());
58 
59  // generate a cdf value between 0 and 1
60  std::uniform_real_distribution<> uniformDist(0.0, 1.0);
61  double cdf_value = uniformDist(gen);
62 
63  // solve for x by inverting the cdf of Triangle Distribution
64  if (cdf_value <= 0.5)
65  return (-m_omega + m_omega * std::sqrt(2 * cdf_value));
66  return (m_omega - m_omega * std::sqrt(2 * (1 - cdf_value)));
67 }

References m_omega.

Member Data Documentation

◆ m_omega

double Distribution1DTriangleSampler::m_omega
private

Definition at line 78 of file IDistribution1DSampler.h.

Referenced by randomSample().


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