Program Listing for File PDFSegmentDelta.hpp
↰ Return to documentation for file (src/pdfs/PDFSegmentDelta.hpp)
#ifndef PDFSEGMENTDELTA_HPP
#define PDFSEGMENTDELTA_HPP
#include "PDFCommons.hpp"
#include "PDFSegment.hpp"
#include <fstream>
#include <stdexcept>
#include <toml.hpp>
namespace pdfs {
class PDFSegmentDelta : public PDFSegment {
public:
// Constructor and destructor
PDFSegmentDelta(double sValue) :
PDFSegment(sValue, sValue) {}
PDFSegmentDelta(std::ifstream& file,
FileFormats fmt,
double &sMin,
double &sMax,
double &wgt);
PDFSegmentDelta(toml::node_view<const toml::node> node,
FileFormats fmt,
double &sMin,
double &sMax,
double &wgt);
PDFSegmentDelta(const PDFSegmentDelta&) = default;
auto operator=(const PDFSegmentDelta&) -> PDFSegmentDelta& = default;
PDFSegmentDelta(PDFSegmentDelta&&) = default;
auto operator=(PDFSegmentDelta&&) -> PDFSegmentDelta& = default;
~PDFSegmentDelta() override = default;
// Evaluation functions
[[nodiscard]] auto operator()(double x) const -> double override {
(void)x;
throw std::runtime_error("PDFSegmentDelta: a delta function cannot be evaluated at a point.");
}
[[nodiscard]] auto expectationValue(const double a, const double b) const -> double override {
if (a > b || a > sMax_ || b < sMin_) {
return 0.0; // Invalid range for expectation value calculation
}
return sMin_; // The expectation value of a delta function is just the value at which it is centered
}
[[nodiscard]] auto expectationValue() const -> double override {
return sMin_; // The expectation value of a delta function is just the value at which it is centered
}
[[nodiscard]] auto integral(const double a, const double b) const -> double override {
if (a <= sMin_ && b >= sMin_) {
return 1.0; // The integral of a delta function over a range that includes its center is 1
}
return 0.0; // The integral of a delta function over a range that does not include its center is 0
}
// Drawing functions
[[nodiscard]] auto draw(const double a, const double b) const -> double override {
if (a >= b || a > sMax_ || b < sMin_) {
return 0.0; // Invalid range for expectation value calculation
}
return sMin_; // Sampling from a delta function always returns the same value
}
[[nodiscard]] auto draw() const -> double override {
return sMin_; // Sampling from a delta function always returns the same value
}
// Serialization
void toToml(toml::table& tbl) const override;
};
} // namespace pdfs
#endif // PDFSEGMENTDELTA_HPP