# order.variable¶

Tools to work with variables.

Contents

## Class Variable¶

class Variable(name, id='+', expression=None, binning=(1, 0.0, 1.0), x_title='', x_title_short=None, y_title='Entries', y_title_short=None, x_labels=None, log_x=False, log_y=False, unit='1', unit_format='{title} / {unit}', null_value=None, selection=None, selection_mode=None, tags=None, aux=None)[source]

Class that provides simplified access to variables for convenience methods for plotting with both ROOT and matplotlib.

Arguments

expression can be a string (for projection statements) or function that defines the variable expression. When empty, it defaults to name. selection is expected to be a string. Other options that are relevant for plotting are binning, x_title, x_title_short, y_title, y_title_short, unit, unit_format and null_value. See the attribute listing below for further information.

selection and selection_mode are passed to the SelectionMixin, tags to the TagMixin, aux to the AuxDataMixin, and name and id (defaulting to an automatically increasing id) to the UniqueObject constructor.

Copy behavior

All attributes are copied.

Example

import order as od

v1 = od.Variable(
name="myVar",
expression="myBranchA * myBranchB",
selection="myBranchC > 0",
binning=(20, 0.0, 10.0),
x_title=r"$\mu p_{T}$",
unit="GeV",
null_value=-999.0,
)

v1.x_title_root
# -> "#mu p_{T}"

v1.get_full_title()
# -> "myVar;$\mu p_{T}$" / GeV;Entries / 0.5 GeV'"

v2 = v1.copy(name="copiedVar", id="+",
binning=[0.0, 0.5, 1.5, 3.0],
)

v2.get_full_title()
# -> "copiedVar;#mu p_{T} / GeV;Entries / GeV"

v2.even_binning
# -> False


Members

expression
type: string, callable, None

The expression of this variable. Defaults to name if None.

binning
type: tuple, list

Descibes the bin edges when given a list, or the number of bins, minimum value and maximum value when passed a 3-tuple.

even_binning
type: bool

Whether or not the binning is even.

x_title
type: string

The title of the x-axis in standard LaTeX format.

x_title_root
type: string

The title of the x-axis, converted to ROOT-style latex.

x_title_short
type: string

Short version for the title of the x-axis in standard LaTeX format. Defaults to x_title when not explicitely set.

x_title_short_root
type: string

The short version of the title of the x-axis, converted to ROOT-style latex.

y_title
type: string

The title of the y-axis in standard LaTeX format.

y_title_root
type: string

The title of the y-axis, converted to ROOT-style latex.

y_title_short
type: string

Short version for the title of the y-axis in standard LaTeX format. Defaults to y_title when not explicitely set.

y_title_short_root
type: string

The short version of the title of the y-axis, converted to ROOT-style latex.

x_labels
type: list, None

A list of custom bin labels or None.

x_labels_root
type: list, None

A list of custom bin labels, converted to ROOT-style latex, or None.

unit
type: string, None

The unit to be shown on both, x- and y-axis. When None, no unit is shown.

unit_format
type: string

The format string for concatenating axis titles and units, e.g. "{title} / {unit}". The format string must contain the fields title and unit.

null_value
type: int, float, None

A configurable NULL value for this variable, possibly denoting missing values. None is considered as “non-configured”.

log_x
type: boolean

Whether or not the x-axis should be drawn logarithmically.

log_y
type: boolean

Whether or not the y-axis should be drawn logarithmically.

n_bins
type: int

The number of bins.

x_min
type: float

The minimum value of the x-axis.

x_max
type: float

The maximum value of the x-axis.

bin_width
type: float

The width of a bin.

bin_edges
type: list

A list of the n_bins + 1 bin edges.

Methods:

 get_full_x_title([short, root]) Returns the full title (i.e. get_full_y_title([bin_width, short, root]) Returns the full title (i.e. get_full_title([name, short, short_x, ...]) Returns the full combined title that is compliant with ROOT's TH1 classes. get_mpl_hist_data([update, skip]) Returns a dictionary containing information on bins, range, label, and log, that can be passed to matplotlib histograms.
get_full_x_title(short=False, root=False)[source]

Returns the full title (i.e. with unit string) of the x-axis. When short is True, the short version is returned. When root is True, the title is converted to proper ROOT latex.

get_full_y_title(bin_width=None, short=False, root=False)[source]

Returns the full title (i.e. with bin width and unit string) of the y-axis. When not None, the value bin_width instead of the one evaluated from binning when even. When short is True, the short version is returned. When root is True, the title is converted to ROOT-style latex.

get_full_title(name=None, short=False, short_x=None, short_y=None, root=False, bin_width=None)[source]

Returns the full combined title that is compliant with ROOT’s TH1 classes. short_x (short_y) is passed to full_x_title() (full_y_title()). Both values fallback to short when None. bin_width is forwarded to full_y_title(). When root is False, the axis titles are not converted to ROOT-style latex.

get_mpl_hist_data(update=None, skip=None)[source]

Returns a dictionary containing information on bins, range, label, and log, that can be passed to matplotlib histograms. When update is set, the returned dict is updated with update. When skip is set, it can be a single key or a sequence of keys that will not be added to the returned dictionary.