Histograms

Core types

template<typename NT = util::num_traits_t<>>
class HistogramRegistry

Manages the lifecycle and registration of multiple histograms.

The HistogramRegistry serves as a facade over HistogramData and AxisData. It manages:

  1. Global bin storage (HistogramData)

  2. Global axis definition storage (AxisData)

  3. Registered Axes (list of AxisViewVariant)

  4. Registered Histograms (mapping of Name -> HistogramView + AxisId)

This class provides a centralized point for booking and filling histograms, ensuring that memory allocation and multi-dimensional axis mapping are handled consistently.

Template Parameters:

NT – The numeric traits defining coordinate, index, and count types.

Filling

template<typename Buffer>
inline void fill_by_index(Buffer &buffer, Id id, std::span<const T> values, S local_bin_idx) const

Fills a registered histogram with a span of values using a local bin index.

Template Parameters:

Buffer – The type of the histogram buffer.

Parameters:
  • buffer – The thread-local buffer to fill.

  • id – The ID of the histogram.

  • values – The span of values to accumulate.

  • local_bin_idx – The index of the bin within the histogram.

template<typename Buffer>
inline void fill_by_index(Buffer &buffer, Id id, const T &value, S local_bin_idx) const

Fills a registered histogram with a single value using a local bin index.

Template Parameters:

Buffer – The type of the histogram buffer.

Parameters:
  • buffer – The thread-local buffer to fill.

  • id – The ID of the histogram.

  • value – The value to accumulate.

  • local_bin_idx – The index of the bin within the histogram.

template<typename Buffer, typename ...Coords>
inline void fill(Buffer &buffer, Id id, std::span<const T> values, Coords&&... x) const

Fills a registered histogram by mapping multi-dimensional coordinates to a bin index, providing a span of values.

Template Parameters:
  • Buffer – The type of the histogram buffer.

  • Coords – Coordinate types.

Parameters:
  • buffer – The thread-local buffer to fill.

  • id – The ID of the histogram.

  • values – The span of values to accumulate.

  • x – Coordinates for each dimension.

template<typename Buffer, typename ...Coords>
inline void fill(Buffer &buffer, Id id, const T &value, Coords&&... x) const

Fills a registered histogram by mapping multi-dimensional coordinates to a bin index, providing a single value.

Template Parameters:
  • Buffer – The type of the histogram buffer.

  • Coords – Coordinate types.

Parameters:
  • buffer – The thread-local buffer to fill.

  • id – The ID of the histogram.

  • value – The value to accumulate.

  • x – Coordinates for each dimension.

template<typename Buffer>
inline void flush(Buffer &buffer) noexcept(noexcept(buffer.flush(data_)))

Flushes a buffer into the registry’s global data storage.

Template Parameters:

Buffer – The type of the histogram buffer.

Parameters:

buffer – The buffer to flush.

Accessors

inline HistogramData<NT> &data() noexcept

Access the underlying global bin storage.

inline const HistogramData<NT> &data() const noexcept

Access the underlying global bin storage (const).

inline AxisData<T, S> &axis_data() noexcept

Access the underlying axis parameter storage.

inline const AxisData<T, S> &axis_data() const noexcept

Access the underlying axis parameter storage (const).

inline S num_entries() const noexcept

Returns the total number of registered histograms.

inline std::vector<Id> ids() const

Retrieve the list of all registered histogram IDs.

inline Id get_id(std::string_view name) const

Look up a histogram’s unique ID by its registered name.

Parameters:

name – The name of the histogram.

Throws:

std::runtime_error – If the name is not found.

Returns:

A HistogramId handle.

inline std::string_view get_name(Id id) const noexcept

Retrieve the human-readable name for a specific histogram.

Parameters:

id – The histogram ID.

Returns:

The registered name.

inline View get_view(Id id) const noexcept

Retrieve the view handle for a specific histogram.

Parameters:

id – The histogram ID.

Returns:

The HistogramView for this histogram.

inline S get_ndim(Id id) const noexcept

Get the number of dimensions for a specific histogram.

Parameters:

id – The histogram ID.

Returns:

The number of dimensions.

inline S get_nbins(Id id) const noexcept

Get the total number of bins for a specific histogram.

Parameters:

id – The histogram ID.

Returns:

The bin count (including UF/OF).

inline S get_nvalues(Id id) const noexcept

Get the number of values stored per bin for a specific histogram.

Parameters:

id – The histogram ID.

Returns:

The number of values per bin (stride).

inline std::vector<S> get_bin_indices(Id id, S flat_idx) const

Decomposes a flattened bin index into multi-dimensional bin indices.

Parameters:
  • id – The histogram ID.

  • flat_idx – The local flattened index.

Returns:

A vector containing the bin index for each dimension.

inline std::vector<std::vector<BinRange<T>>> get_bin_ranges(Id id) const

Get the bin ranges for all axes of a specific histogram.

Parameters:

id – The histogram ID.

Returns:

A vector of vectors, each containing BinRange objects for one dimension.

inline std::vector<std::vector<T>> get_edges(Id id) const

Get the regular bin edges for all dimensions of a histogram.

Parameters:

id – The histogram ID.

Returns:

A vector of edge vectors for each dimension.

inline std::vector<std::pair<T, T>> get_bin_bounds(Id id, S bin_idx) const

Get the physical boundaries for all dimensions of a specific bin.

Parameters:
  • id – The histogram ID.

  • bin_idx – The local flattened bin index.

Returns:

A vector of pairs (low, high) for each dimension.

inline std::vector<std::pair<T, T>> get_bin_bounds(Id id, S bin_idx, const std::vector<std::vector<T>> &edges_cache) const

Optimized version of get_bin_bounds using pre-calculated edges.

Parameters:
  • id – The histogram ID.

  • bin_idx – The local bin index.

  • edges_cache – Result of get_edges(id).

Returns:

A vector of pairs (low, high) for each dimension.

inline const auto &get_bin(Id id, S bin_idx, S value_idx = 0) const

Access the accumulator for a specific bin in a registered histogram.

Parameters:
  • id – The histogram ID.

  • bin_idx – The local flattened bin index.

  • value_idx – The value index within the bin (default 0).

Throws:

std::out_of_range – If the ID or indices are invalid.

Returns:

A const reference to the bin accumulator.

inline T get_bin_value(Id id, S bin_idx, S value_idx = 0) const noexcept

Get the mean value (sum of weights / N) for a specific bin.

Parameters:
  • id – Histogram ID.

  • bin_idx – Local bin index.

  • value_idx – Value index within the bin.

Returns:

The mean value.

inline T get_bin_variance(Id id, S bin_idx, S value_idx = 0) const noexcept

Get the variance of the mean value for a specific bin.

Parameters:
  • id – Histogram ID.

  • bin_idx – Local bin index.

  • value_idx – Value index within the bin.

Returns:

The variance of the mean.

inline T get_bin_error(Id id, S bin_idx, S value_idx = 0) const noexcept

Get the statistical error (standard deviation of the mean) for a specific bin.

Parameters:
  • id – Histogram ID.

  • bin_idx – Local bin index.

  • value_idx – Value index within the bin.

Returns:

The statistical error.

Serialization

inline void serialize(std::ostream &out, bool with_type = true) const noexcept

Serializes the entire registry state to an output stream.

Parameters:
  • out – The destination output stream.

  • with_type – Whether to prepend type identifiers for verification.

inline void deserialize(std::istream &in, bool with_type = true)

Deserializes the entire registry state from an input stream.

Parameters:
  • in – The source input stream.

  • with_type – Whether to verify type identifiers.

Throws:

std::runtime_error – If type mismatch or stream corruption occurs.

Public Functions

inline Id book(std::string_view name, S n_values_per_bin, S n_bins)

Books a new histogram without an associated axis (view only).

Parameters:
  • name – A unique identifier for the histogram.

  • n_values_per_bin – The number of values per bin (default 1).

  • n_bins – The number of bins to allocate.

Throws:

std::invalid_argument – If the name is already in use.

Returns:

A HistogramId handle.

template<typename FirstAxis, typename ...AxisTypes>
inline Id book(std::string_view name, S n_values_per_bin, const FirstAxis &first, const AxisTypes&... rest)

Books a new histogram by providing one or more self-contained Axis objects.

The provided axis objects are duplicated into the registry’s internal storage, and strides are automatically calculated for multi-dimensional indexing.

Template Parameters:
  • FirstAxis – Type of the first Axis object.

  • AxisTypes – Types of the subsequent Axis objects.

Parameters:
  • name – Unique name for the histogram.

  • n_values_per_bin – Number of values per bin.

  • first – The first Axis object.

  • rest – Subsequent Axis objects.

Throws:

std::invalid_argument – If the name is already in use.

Returns:

A HistogramId handle.

template<typename Acc = kakuhen::util::accumulator::Accumulator<T>>
inline auto create_buffer() const

Creates and initializes a thread-local buffer for filling histograms.

Template Parameters:

Acc – The accumulator type to use (default: TwoSum via kakuhen::util::accumulator::Accumulator).

Returns:

A newly initialized HistogramBuffer.

template<typename Writer>
inline void write(Writer &wrt) const

Writes a summary of all registered histograms using the provided writer.

Template Parameters:

Writer – The type of the histogram writer (e.g., NNLOJETWriter).

Parameters:

wrt – The writer instance to use.

inline void clear() noexcept

Resets the registry, clearing all histograms, axes, and data.

template<typename NT = util::num_traits_t<>, typename Acc = kakuhen::util::accumulator::Accumulator<typename NT::value_type>>
class HistogramBuffer

A high-performance thread-local buffer for histogram filling.

This class implements a sparse-dense buffering strategy to efficiently accumulate weights into a global histogram storage. It is designed to minimize memory contention and numerical errors during high-frequency filling in Monte Carlo simulations.

Key Features:

  • TwoSum Compensation (Default): Uses compensated summation internally via the Acc type to handle large cancellations (e.g., +W and -W) before they touch global memory. This is configurable for performance.

  • Packed Generation Index: Uses a “Sparse Set” approach with a packed generation index to perform O(1) validity checks without zeroing memory between events.

  • Event-Level Consolidation: Accumulates all weights for a specific bin within a single event linearly. This ensures that large cancellations (e.g., +10.0 and -9.9) result in a small net weight (0.1) which is then squared for error estimation (0.01), rather than summing squares independently.

Template Parameters:
  • NT – The numeric traits defining value type and index type.

  • Acc – The accumulator type for intra-event summation. Defaults to TwoSum. Use NaiveAccumulator for maximum speed if cancellations are not expected.

Public Functions

inline void init(S n_total_bins, std::size_t reserve_size = 1024)

Initializes and configures the buffer for a specific global storage size.

This method must be called once before any filling occurs. It calculates the optimal bit allocation for the packed generation index based on the total number of global bins to maximize the time between mandatory map clears.

Note

The sparse_map_ is initialized with zeros. A value of 0 in the map indicates that the bin has never been touched in the current generation.

Parameters:
  • n_total_bins – The total number of bins in the global HistogramData storage.

  • reserve_size – Initial capacity for the thread-local dense buffers to avoid reallocations.

Throws:

std::runtime_error – If the index type S is too small to accommodate the bin index and the minimum required generation counter bits (4).

inline void fill(S global_idx, const T &w) noexcept

Accumulates a weight into a global bin index.

This is the performance-critical hot path function. It updates the thread-local buffer using a sparse-set inspired O(1) validity check. Weights are summed linearly within an event to ensure correct error propagation during flushes.

Note

If the bin was already touched in the current event (generation), the weight is added to the existing accumulator. Otherwise, a new entry is created in the dense buffer.

Parameters:
  • global_idx – The flattened global index of the bin in HistogramData.

  • w – The weight to accumulate.

inline void flush(HistogramData<NT> &hist_data)

Flushes the buffered results to the global storage.

This must be called at the end of each event (or whenever event-level consolidation is required). It computes the net weight for each bin touched in the event and adds it to the global storage.

The variance contribution is calculated as the square of the net weight accumulated within the event, which is the standard procedure for handling correlated weights or cancellations in Monte Carlo event generation.

Parameters:

hist_data – The global histogram data storage to receive the results.

template<typename NT = util::num_traits_t<>>
class HistogramView

A view over a slice of the global histogram data.

HistogramView acts as a handle to a specific histogram within the global HistogramData storage. It manages the registration (allocation) of bins and provides a convenient interface for filling multi-valued bins.

It is designed to be lightweight and copyable.

Template Parameters:

NT – The numeric traits defining value type and index type.

Public Functions

inline HistogramView()

Constructs an empty HistogramView.

inline HistogramView(S offset, S n_bins, S stride)

Constructs a HistogramView from raw metadata.

Parameters:
  • offset – The starting global index.

  • n_bins – The number of bins.

  • stride – The number of values per bin.

inline HistogramView(HistogramData<NT> &data, S n_bins, S n_values_per_bin)

Registers a new histogram view and allocates storage.

Parameters:
  • data – The global histogram data storage.

  • n_bins – The number of bins in this histogram.

  • n_values_per_bin – The number of values (observables) per bin.

template<typename Buffer>
inline void fill_by_index(Buffer &buffer, std::span<const T> values, S local_bin_idx) const

Fills the histogram buffer with a span of values for a specific bin.

This method maps the local bin index and the span of values to the corresponding global indices in the histogram buffer.

Note

If local_bin_idx or the size of values is incorrect, this will assert in debug builds.

Template Parameters:

Buffer – The type of the histogram buffer (e.g., HistogramBuffer).

Parameters:
  • buffer – The thread-local histogram buffer to fill.

  • values – The values to accumulate into the bin. Must have size == n_values_per_bin.

  • local_bin_idx – The local index of the bin (0 to n_bins - 1).

template<typename Buffer>
inline void fill_by_index(Buffer &buffer, const T &value, S local_bin_idx) const

Fills the histogram buffer with a single value (scalar).

Optimized path for histograms with 1 value per bin (stride == 1).

Template Parameters:

Buffer – The type of the histogram buffer.

Parameters:
  • buffer – The thread-local histogram buffer.

  • value – The value to accumulate.

  • local_bin_idx – The local index of the bin.

inline const auto &get_bin(const HistogramData<NT> &data, S bin_idx, S value_idx = 0) const noexcept

Access the accumulator for a specific bin in this histogram view.

Parameters:
  • data – The global histogram data storage.

  • bin_idx – The local bin index.

  • value_idx – The value index within the bin (default 0).

Throws:

std::out_of_range – If indices are out of bounds.

Returns:

A const reference to the bin accumulator.

inline void serialize(std::ostream &out, bool with_type = false) const noexcept

Serializes the histogram view metadata.

Parameters:
  • out – The output stream to write to.

  • with_type – If true, prepends type identifiers for T and S to the stream.

inline void deserialize(std::istream &in, bool with_type = false)

Deserializes the histogram view metadata.

Parameters:
  • in – The input stream to read from.

  • with_type – If true, expects and verifies type identifiers for T and S.

Throws:

std::runtime_error – If type verification fails or the stream is corrupted.

inline S offset() const noexcept

Get the global offset for this view in HistogramData.

Returns:

Starting index.

inline S n_bins() const noexcept

Get the number of bins in this view.

Returns:

Bin count.

inline S stride() const noexcept

Get the number of values per bin (stride).

Returns:

Values per bin.

template<typename Derived, typename NT = util::num_traits_t<>>
class HistogramWriter

Base class for writers using CRTP.

Subclassed by kakuhen::histogram::NNLOJETWriter< NT >

Public Functions

template<typename Registry>
inline void global_header(const Registry &reg)

Write the global header.

Template Parameters:

Registry – The type of the histogram registry.

Parameters:

reg – The histogram registry.

inline void histogram_header(size_type i, const std::string_view name, size_type nbins, size_type nvalues, size_type ndim, const std::vector<std::vector<BinRange<value_type>>> &ranges, count_type neval)

Write the header for a specific histogram.

Parameters:
  • i – The index of the histogram.

  • name – The name of the histogram.

  • nbins – The total number of bins.

  • nvalues – The number of values per bin.

  • ndim – The number of dimensions.

  • ranges – The bin ranges for each dimension.

  • neval – The number of evaluations.

inline void histogram_row(size_type ibin, const std::vector<BinRange<value_type>> &bin_range, const std::vector<value_type> &values, const std::vector<value_type> &errors)

Write a row of data for a specific bin.

Parameters:
  • ibin – The flat index of the bin.

  • bin_range – The range of the bin in each dimension.

  • values – The values in the bin.

  • errors – The errors in the bin.

inline void histogram_footer()

Write the footer for a specific histogram.

inline void global_footer()

Write the global footer.

Axes

template<template<typename, typename> class ConcreteAxis, typename T, typename S>
class Axis

A self-contained axis that owns its data.

Unlike AxisView which points to shared storage, Axis manages its own parameter/edge storage internally. It wraps a concrete AxisView type (UniformAxisView or VariableAxisView) and provides a simplified interface.

This class is ideal for use as a building block for defining histograms before they are registered in a shared HistogramRegistry.

Template Parameters:

Public Functions

inline explicit Axis(std::initializer_list<T> list)

Constructs an Axis from an initializer list (e.g. for VariableAxisView).

Parameters:

list – Initializer list of values (e.g. bin edges).

template<std::integral I>
inline explicit Axis(I n_bins, const T &min, const T &max)

Constructs a uniform axis with an integral bin-count argument.

This overload avoids signed/unsigned conversion warnings at call sites where literals like 10 are passed for an unsigned size type.

Template Parameters:

I – Integral type of the bin-count argument.

Parameters:
  • n_bins – Number of regular bins.

  • min – Lower axis boundary.

  • max – Upper axis boundary.

template<typename ...Args>
inline explicit Axis(Args&&... args)

Constructs an Axis by forwarding arguments to the concrete axis view.

The arguments are used to populate the internal AxisData and initialize the view.

Template Parameters:

Args – Constructor arguments for the concrete axis (excluding AxisData).

Parameters:

args – Arguments forwarded to the ConcreteAxis constructor.

inline S index(const T &x) const noexcept

Maps a coordinate to a bin index.

Parameters:

x – The coordinate value.

Returns:

The bin index (including UF/OF).

inline std::vector<T> edges() const

Returns the bin edges of the regular bins.

Returns:

A vector containing the regular bin boundaries.

inline std::vector<BinRange<T>> bin_ranges() const

Returns the full set of bin ranges for this axis.

Returns:

A vector of BinRange objects for each bin in the axis.

inline const view_type &view() const noexcept

Get the underlying axis view.

Returns:

A const reference to the view.

inline S n_bins() const noexcept

Get the total number of bins.

Returns:

Bin count (including UF/OF).

inline const AxisData<T, S> &data() const noexcept

Get the internal data storage.

Returns:

A const reference to the AxisData.

inline view_type duplicate(AxisData<T, S> &target_data) const

Duplicates the axis into an external AxisData storage.

This facilitates transferring a self-contained axis definition into shared registry storage.

Parameters:

target_data – The external storage to receive the parameters/edges.

Returns:

A new AxisView pointing to the duplicated data in target_data.

template<typename Derived, typename T, typename S>
class AxisView

CRTP base class for histogram axis views.

AxisView provides the interface for mapping coordinates to bin indices. It stores metadata describing where its parameters are located in a shared AxisData storage.

Indexing Convention:

  • 0: Underflow (x < regular_range_min)

  • 1 .. N: Regular bins

  • N + 1: Overflow (x >= regular_range_max)

Template Parameters:

Public Functions

inline explicit AxisView(const metadata_type &meta) noexcept

Constructs an AxisView from metadata.

Parameters:

meta – The axis metadata.

inline S index(const AxisData<T, S> &axis_data, const T &x) const noexcept

Maps a coordinate to its corresponding bin index.

Parameters:
  • axis_data – Shared storage containing the axis parameters.

  • x – The coordinate value to map.

Returns:

The bin index (0 to n_bins - 1) multiplied by the stride.

inline std::vector<T> edges(const AxisData<T, S> &axis_data) const

Returns the bin edges of the regular bins.

Parameters:

axis_data – Shared storage containing the axis parameters.

Returns:

A vector containing the regular bin edges.

inline std::vector<BinRange<T>> bin_ranges(const AxisData<T, S> &axis_data) const

Returns the full set of bin ranges for this axis.

Parameters:

axis_data – Shared storage containing the axis parameters.

Returns:

A vector of BinRange objects for each bin in the axis.

inline const metadata_type &metadata() const noexcept

Access the underlying metadata.

inline S n_bins() const noexcept

Get the total number of bins.

inline S offset() const noexcept

Get the offset into the shared AxisData storage.

inline S size() const noexcept

Get the number of data points used by this axis in shared storage.

inline S stride() const noexcept

Get the stride multiplier for this axis.

inline void set_stride(S stride) noexcept

Sets the stride multiplier for this axis.

Parameters:

stride – The new stride value.

inline void serialize(std::ostream &out, bool with_type = false) const noexcept

Serializes the axis view metadata.

Parameters:
  • out – The destination output stream.

  • with_type – Whether to include type identifiers for verification.

inline void deserialize(std::istream &in, bool with_type = false)

Deserializes the axis view metadata.

Parameters:
  • in – The source input stream.

  • with_type – Whether to verify type identifiers.

template<typename T, typename S>
class AxisData

Centralized storage for axis binning parameters and edges.

Stores continuous arrays of bin edges (for variable axes) or parameters (for uniform axes) in a single contiguous block of memory. This design improves data locality and simplifies serialization of axis definitions.

Template Parameters:
  • T – The coordinate and parameter value type (e.g., double).

  • S – The size/index type (e.g., uint32_t).

Adding Data

template<typename Range>
inline S add_data(const Range &range)

Appends a range of data to the storage.

Supports any type that satisfies the range requirement (has std::begin/std::end), such as std::vector, std::span, std::array, etc.

Template Parameters:

Range – The range type.

Parameters:

range – The range of values to append.

Throws:

std::length_error – If the new size exceeds the capacity of the index type S.

Returns:

The starting offset index of the appended data.

inline S add_data(std::initializer_list<T> data)

Appends data from an initializer list.

Parameters:

data – The initializer list of values.

Returns:

The starting offset index of the appended data.

template<typename ...Args>
inline S add_data(Args&&... args)

Appends individual values to the storage (Variadic).

Template Parameters:

Args – Variadic argument types (must be convertible to T).

Parameters:

args – The values to append.

Throws:

std::length_error – If the new size exceeds the capacity of the index type S.

Returns:

The starting offset index of the appended data.

Accessors

inline const std::vector<T> &data() const noexcept

Access the global data vector.

Returns:

A const reference to the underlying storage vector.

inline const T &operator[](S index) const noexcept

Access data element at index.

Parameters:

index – The index of the element to access.

Returns:

A const reference to the element.

inline const T &at(S index) const

Access data element at index with bounds checking.

Parameters:

index – The index of the element to access.

Throws:

std::out_of_range – If index is invalid.

Returns:

A const reference to the element.

inline S size() const noexcept

Get the total number of stored elements.

Returns:

The number of elements currently in storage.

Serialization

inline void serialize(std::ostream &out, bool with_type = false) const noexcept

Serializes the axis data to an output stream.

Parameters:
  • out – The output stream to write to.

  • with_type – If true, prepends type identifiers for T and S to the stream.

inline void deserialize(std::istream &in, bool with_type = false)

Deserializes the axis data from an input stream.

Parameters:
  • in – The input stream to read from.

  • with_type – If true, expects and verifies type identifiers for T and S.

Throws:
  • std::runtime_error – If type verification fails or the stream is corrupted.

  • std::length_error – If the count exceeds the capacity of the index type S.

Management

inline void clear() noexcept

Clears all stored data.

This method resets the size to zero but typically preserves the capacity of the underlying storage to avoid reallocations.

inline void reserve(S capacity)

Reserves memory for at least the specified number of elements.

Parameters:

capacity – The number of elements to reserve space for.

Public Functions

inline bool operator==(const AxisData &other) const noexcept

Checks if two AxisData objects are identical.

inline bool operator!=(const AxisData &other) const noexcept

Checks if two AxisData objects are different.

template<typename T, typename S>
class UniformAxisView : public kakuhen::histogram::AxisView<UniformAxisView<T, S>, T, S>

Represents an axis with uniformly spaced bins.

Maps coordinates to indices in O(1) time using a linear transformation.

Template Parameters:
  • T – The coordinate value type.

  • S – The index type.

Public Functions

inline explicit UniformAxisView(const metadata_type &meta) noexcept

Constructs a UniformAxis from existing metadata.

Parameters:

meta – The axis metadata.

inline UniformAxisView(AxisData<T, S> &data, S n_bins, const T &min, const T &max)

Constructs a UniformAxisView and registers its parameters in AxisData.

Parameters:
  • data – Shared axis data storage.

  • n_bins – Number of regular bins.

  • min – The lower bound of the first regular bin.

  • max – The upper bound of the last regular bin.

Throws:

std::invalid_argument – if parameters are invalid.

inline S index_impl(const AxisData<T, S> &axis_data, const T &x) const noexcept

Maps a coordinate to a bin index using uniform mapping.

inline std::vector<T> edges_impl(const AxisData<T, S> &axis_data) const

Implementation for retrieving uniform bin edges.

inline std::vector<BinRange<T>> bin_ranges_impl(const AxisData<T, S> &axis_data) const

Implementation for retrieving uniform bin ranges.

template<typename T, typename S>
class VariableAxisView : public kakuhen::histogram::AxisView<VariableAxisView<T, S>, T, S>

Represents an axis with variable bin widths.

Maps coordinates to indices in O(log N) time using binary search over edges.

Template Parameters:
  • T – The coordinate value type.

  • S – The index type.

Public Functions

inline explicit VariableAxisView(const metadata_type &meta) noexcept

Constructs a VariableAxisView from existing metadata.

Parameters:

meta – The axis metadata.

inline VariableAxisView(AxisData<T, S> &data, const std::vector<T> &edges)

Constructs a VariableAxisView and registers its edges in AxisData.

Parameters:
  • data – The shared axis data storage.

  • edges – The bin edges (must be sorted).

Throws:

std::invalid_argument – if parameters are invalid.

inline S index_impl(const AxisData<T, S> &axis_data, const T &x) const noexcept

Maps a coordinate to a bin index using binary search.

inline std::vector<T> edges_impl(const AxisData<T, S> &axis_data) const

Implementation for retrieving variable bin edges.

inline std::vector<BinRange<T>> bin_ranges_impl(const AxisData<T, S> &axis_data) const

Implementation for retrieving variable bin ranges.

Typedefs

template<typename T = double, typename S = uint32_t>
using kakuhen::histogram::UniformAxis = Axis<UniformAxisView, T, S>

Convenience alias for a self-contained UniformAxisView.

template<typename T = double, typename S = uint32_t>
using kakuhen::histogram::VariableAxis = Axis<VariableAxisView, T, S>

Convenience alias for a self-contained VariableAxisView.