AdBin

class hep_spt.AdBin(arr, range=None, weights=None)[source]

Bases: object

Represent a n-dimensional adaptive bin. This class is meant so serve as interface between the user and matplotlib to plot adaptive binned histograms.

Parameters

Methods Summary

contains(arr)

Return whether the values in the input array are inside this bin or not.

dens(arr[, weights])

Return the density of this bin.

divide([ndiv])

Divide this bin in two, using the median in each dimension.

free_memory()

Remove the pointers to the arrays of data and weights.

size()

Return the size of the bin.

sw(arr[, weights])

Compute and return the sum of weights.

sw_unc(arr[, weights])

Calculate and return the uncertainty on the sum of weights.

Methods Documentation

contains(arr)[source]

Return whether the values in the input array are inside this bin or not.

Parameters

arr (numpy.ndarray) – input data.

Returns

Whether the values in the input array are inside this bin or not.

Return type

bool or numpy.ndarray(bool)

dens(arr, weights=None)[source]

Return the density of this bin.

Parameters
Returns

Density of this bin.

Return type

float

divide(ndiv=2)[source]

Divide this bin in two, using the median in each dimension. The dimension used to make the division is taken as that which generates the smallest bin.

Parameters

ndiv (int) – number of divisions to create. For large values, this algorithm will ask for having a low sum of weights for the first bin, which will translate in having a long thin bin.

Returns

Two new bins, supposed to contain half the sum of weights of the parent.

Return type

AdBin, AdBin

Raises

RuntimeError – If called after the data pointers have been freed.

Warning

This method can not be called after AdBin.free_memory(), since it destroys the arrays of data and weights.

free_memory()[source]

Remove the pointers to the arrays of data and weights.

Warning

The method AdBin.divide() will become unavailable after this.

size()[source]

Return the size of the bin.

Returns

Size of this bin calculated as the product of the individual sizes in each dimension.

Return type

float

sw(arr, weights=None)[source]

Compute and return the sum of weights.

Parameters
Returns

Sum of weights for this bin.

Return type

float

sw_unc(arr, weights=None)[source]

Calculate and return the uncertainty on the sum of weights.

Parameters
Returns

Uncertainty of the sum of weights in the bin. If “weights” is provided, this magnitude is equal to the square root of the sum of weights in the bin. Otherwise poissonian errors are considered.

Return type

float