Histogram#

Array helpers for constructing and comparing histograms.

Histogram construction, accumulation, and comparison.

class simtools.histogram.histogram.Histogram(edges, values=None, metadata=None, axis_names=None, axis_units=None)[source]#

N-dimensional numpy histogram with bin edges and optional metadata.

Parameters:
edgeslist of numpy.ndarray

One bin-edge array per axis.

valuesarray-like, optional

Bin values. Defaults to zeros of the shape defined by edges.

metadatadict, optional

Metadata associated with the histogram.

axis_nameslist[str], optional

One name per histogram axis.

axis_unitslist[str | None], optional

One unit per histogram axis, or None for unitless axes.

cumulative(axis=0, reverse=False, normalize=False)[source]#

Return cumulative bin values along an axis.

Parameters:
axisint, optional

Axis along which to accumulate counts.

reversebool, optional

Accumulate from high to low coordinates.

normalizebool, optional

Divide by the original total of each slice along the axis.

Returns:
Histogram

Cumulative values with the same edges and metadata.

efficiency(simulated)[source]#

Return triggered counts divided by simulated counts.

Parameters:
simulatedHistogram

Simulated event counts with the same binning.

Returns:
Histogram

Efficiency, with zero where the simulated count is zero.

fill(*columns)[source]#

Add event counts from one array of coordinates per axis.

Parameters:
*columnsarray-like

Coordinate arrays of equal length, one for each axis.

classmethod from_edges(edges, values=None, metadata=None, axis_names=None, axis_units=None)[source]#

Create a histogram from one bin-edge array per axis.

Parameters:
edgeslist of numpy.ndarray

Bin edges for each axis.

valuesarray-like, optional

Initial bin values, defaulting to zeros.

metadatadict, optional

Histogram metadata.

axis_nameslist[str], optional

One name per histogram axis.

axis_unitslist[str | None], optional

One unit per histogram axis.

Returns:
Histogram

Histogram with the supplied binning and values.

property ndim#

Return the number of histogram axes.

property shape#

Return the number of bins along each axis.

simtools.histogram.histogram.compute_bin_edges(values, bins, scale='linear')[source]#

Return robust bin edges for the given values.

simtools.histogram.histogram.normalized_counts(counts, cumulative=False)[source]#

Return normalized bin values and Poisson errors for histogram counts.

simtools.histogram.histogram.rebin_counts(counts, source_edges, target_edges)[source]#

Rebin counts by distributing each source bin over overlapping target bins.

Counts are assumed to be uniformly distributed within each source bin. This preserves the total count and avoids assigning a complete source bin to one target bin when the target edges split it.

HDF5 storage for histograms.

HDF5 storage for histogram payloads.

simtools.histogram.hdf5.read_histograms(group)[source]#

Read named histograms from an HDF5 group.

Parameters:
grouph5py.Group

Group containing histogram subgroups.

Returns:
dict[str, Histogram]

Histograms keyed by their stored names.

simtools.histogram.hdf5.write_histograms(group, histograms)[source]#

Write named histograms to an HDF5 group.

Parameters:
grouph5py.Group

Group in which to store histogram subgroups.

histogramsdict[str, Histogram]

Histograms keyed by their stored names.