Class PDFSegment

Inheritance Relationships

Derived Types

Class Documentation

class PDFSegment

Abstract base class representing a segment of a PDF.

This class defines the interface for a PDF segment, which includes methods to evaluate the PDF at a given point and to sample a random value from the PDF segment. Derived classes must implement these methods according to the specific functional form of the PDF segment they represent.

Subclassed by pdfs::PDFSegmentDelta, pdfs::PDFSegmentExponential, pdfs::PDFSegmentLognormal, pdfs::PDFSegmentNormal, pdfs::PDFSegmentPowerlaw, pdfs::PDFSegmentSchechter

Public Functions

inline PDFSegment(double sMin, double sMax)

Constructor for PDFSegment.

Parameters:
  • lower – The lower limit of the segment.

  • upper – The upper limit of the segment.

PDFSegment(const PDFSegment&) = default
auto operator=(const PDFSegment&) -> PDFSegment& = default
PDFSegment(PDFSegment&&) = default
auto operator=(PDFSegment&&) -> PDFSegment& = default
virtual ~PDFSegment() = default
inline auto getMin() const -> double

Get the lower limit of the segment.

Returns:

The lower limit of the segment.

inline auto getMax() const -> double

Get the upper limit of the segment.

Returns:

The upper limit of the segment.

virtual auto operator()(double x) const -> double = 0

Evaluate the PDF segment at a given point.

Parameters:

x – The point at which to evaluate the PDF segment.

Returns:

The value of the PDF segment at the given point.

virtual auto expectationValue(double a, double b) const -> double = 0

Calculate the expectation value of the PDF segment.

Parameters:
  • a – The lower limit of the range for expectation value calculation; if set to a value <= sMin, will be set to sMin_.

  • b – The upper limit of the range for expectation value calculation; if set to a value >= sMax, will be set to sMax_.

Returns:

The expectation value of the PDF segment.

virtual auto expectationValue() const -> double = 0

Calculate the expectation value of the PDF segment over its entire range.

Returns:

The expectation value of the PDF segment.

virtual auto integral(double a, double b) const -> double = 0

Calculate the integral of the PDF segment over a specified range.

Parameters:
  • a – The lower limit of the range for integral calculation; if set to a value <= sMin, will be set to sMin_.

  • b – The upper limit of the range for integral calculation; if set to a value >= sMax, will be set to sMax_.

Returns:

The integral of the PDF segment over the specified range.

virtual auto draw(double a, double b) const -> double = 0

Sample a random value from the PDF segment within a specified range.

Parameters:
  • a – The lower limit of the sampling range (should be >= sMin_).

  • b – The upper limit of the sampling range (should be <= sMax_).

Returns:

A random value drawn from the PDF segment within the specified range.

virtual auto draw() const -> double = 0

Sample a random value from the PDF segment.

Returns:

A random value drawn from the PDF segment.

virtual void toToml(toml::table &tbl) const = 0

Write this segment’s parameters into a toml table.

The inverse of this segment type’s toml-based constructor in advanced format (see parsePDFToml): inserts a “type” key naming this segment type, plus every key that constructor reads except “weight”, which belongs to the PDF rather than the segment and is written by PDF::toToml(). Reading the result back reproduces this segment exactly.

Parameters:

tbl – The table to write into, i.e., this segment’s own segmentN table in an advanced-format toml PDF descriptor

Protected Attributes

double sMin_

The lower limit of the segment

double sMax_

The upper limit of the segment

Protected Static Functions

static auto segmentParser(std::ifstream &file, std::vector<std::string> &tok) -> std::map<std::string, double>

Parse a segment declaration in a PDF file.

Parameters:
  • file – File stream to parse

  • tok – List of expected tokens for that segment

Returns:

Map of token values

static auto segmentParserToml(toml::node_view<const toml::node> node, std::vector<std::string> &tok) -> std::map<std::string, double>

Parse a segment declaration in a toml-format PDF descriptor.

Parameters:
  • node – Toml node view onto this segment’s own segmentN table

  • tok – List of expected keys for that segment

Returns:

Map of key values