tdub.hist

A module for histogramming

Class Summary

SystematicComparison(nominal, up, down)

Systematic template histogram comparison.

Function Summary

bin_centers(bin_edges)

Get bin centers given bin edges.

edges_and_centers(bins[, range])

Create arrays for edges and bin centers.

to_uniform_bins(bin_edges)

Convert a set of variable width bins to arbitrary uniform bins.

Reference

class tdub.hist.SystematicComparison(nominal, up, down)[source]

Systematic template histogram comparison.

nominal

Nominal histogram bin counts.

Type

numpy.ndarray

up

Up variation histogram bin counts.

Type

numpy.ndarray

down

Down variation histogram bin counts.

Type

numpy.ndarray

percent_diff_up

Percent difference between nominal and up varation.

Type

numpy.ndarray

percent_diff_down

Percent difference between nominald and down variation.

Type

numpy.ndaray

static one_sided(nominal, up)[source]

Generate components of a systematic comparion plot.

Parameters
  • nominal (numpy.ndarray) – Histogram bin counts for the nominal template.

  • up (numpy.ndarray) – Histogram bin counts for the “up” variation.

Returns

The complete description of the comparison

Return type

SystematicComparison

property percent_diff_max

maximum for percent difference.

Type

float

property percent_diff_min

minimum for percent difference.

Type

float

property template_max

maximum height of a variation.

Type

float

tdub.hist.bin_centers(bin_edges)[source]

Get bin centers given bin edges.

Parameters

bin_edges (numpy.ndarray) – edges defining binning

Returns

the centers associated with the edges

Return type

numpy.ndarray

Examples

>>> import numpy as np
>>> from tdub.hist import bin_centers
>>> bin_edges = np.linspace(25, 225, 11)
>>> centers = bin_centers(bin_edges)
>>> bin_edges
array([ 25.,  45.,  65.,  85., 105., 125., 145., 165., 185., 205., 225.])
>>> centers
array([ 35.,  55.,  75.,  95., 115., 135., 155., 175., 195., 215.])
tdub.hist.edges_and_centers(bins, range=None)[source]

Create arrays for edges and bin centers.

Parameters
  • bins (int or sequence of scalers) – the number of bins or sequence representing bin edges

  • range (tuple(float, float), optional) – the minimum and maximum defining the bin range (used if bins is integral)

Returns

Examples

from bin multiplicity and a range

>>> from tdub.hist import edges_and_centers
>>> edges, centers = edges_and_centers(bins=20, range=(25, 225))

from pre-existing edges

>>> edges, centers = edges_and_centers(np.linspace(0, 10, 21))
tdub.hist.to_uniform_bins(bin_edges)[source]

Convert a set of variable width bins to arbitrary uniform bins.

This will create a set of bin edges such that the bin centers are at whole numbers, i.e. 5 variable width bins will return an array from 0.5 to 5.5: [0.5, 1.5, 2.5, 3.5, 4.5, 5.5].

Parameters

bin_edges (numpy.ndarray) – Array of bin edges.

Returns

The new set of uniform bins

Return type

numpy.ndarray

Examples

>>> import numpy as np
>>> from tdub.hist import to_uniform_bins
>>> var_width = [0, 1, 3, 7, 15]
>>> to_uniform_bins(var_width)
array([0.5, 1.5, 2.5, 3.5, 4.5])