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
arr (numpy.ndarray) – array of data.
range (None or numpy.ndarray(float, float)) – range of the histogram in each dimension. As [(xmin, ymin), (xmax, ymax)].
weights (numpy.ndarray) – possible weights.
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.
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
arr (numpy.ndarray) – array of data to process.
weights (numpy.ndarray) – possible weights.
- Returns
Density of this bin.
- Return type
-
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
- 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.See also
-
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
-
sw
(arr, weights=None)[source]¶ Compute and return the sum of weights.
- Parameters
arr (numpy.ndarray) – array of data to process.
weights (numpy.ndarray) – possible weights.
- Returns
Sum of weights for this bin.
- Return type
-
sw_unc
(arr, weights=None)[source]¶ Calculate and return the uncertainty on the sum of weights.
- Parameters
arr (numpy.ndarray) – array of data to process.
weights (numpy.ndarray) – possible weights.
- 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