BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Distribution1DTriangleSampler Class Reference
Inheritance diagram for Distribution1DTriangleSampler:
Collaboration diagram for Distribution1DTriangleSampler:

Public Member Functions

 Distribution1DTriangleSampler (double omega)
 
double randomSample () const final
 

Private Attributes

double m_omega
 

Detailed Description

Definition at line 57 of file IDistribution1DSampler.h.

Constructor & Destructor Documentation

◆ Distribution1DTriangleSampler()

Distribution1DTriangleSampler::Distribution1DTriangleSampler ( double  omega)
inline

Definition at line 60 of file IDistribution1DSampler.h.

Member Function Documentation

◆ randomSample()

double Distribution1DTriangleSampler::randomSample ( ) const
finalvirtual

Implements IDistribution1DSampler.

Definition at line 57 of file IDistribution1DSampler.cpp.

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

References m_omega.

Member Data Documentation

◆ m_omega

double Distribution1DTriangleSampler::m_omega
private

Definition at line 64 of file IDistribution1DSampler.h.

Referenced by randomSample().


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