Reference

Condition

class Condition(value)[source]

Conditions used to define criteria and cuts.

Example

>>> from pyrootplots import Condition
>>> print(Condition.GREATER_THAN_OR_EQUAL_TO)
<Condition.GREATER_THAN_OR_EQUAL_TO: 3>
>>> print(Condition.GREATER_THAN_OR_EQUAL_TO.name)
GREATER_THAN_OR_EQUAL_TO
>>> print(Condition.GREATER_THAN_OR_EQUAL_TO.value)
3
LESS_THAN = 0
LESS_THAN_OR_EQUAL_TO = 1
GREATER_THAN = 2
GREATER_THAN_OR_EQUAL_TO = 3
IN_RANGE_OPEN_OPEN = 4
IN_RANGE_OPEN_CLOSED = 5
IN_RANGE_CLOSED_OPEN = 6
IN_RANGE_CLOSED_CLOSED = 7
NOT_IN_RANGE_OPEN_OPEN = 8
NOT_IN_RANGE_OPEN_CLOSED = 9
NOT_IN_RANGE_CLOSED_OPEN = 10
NOT_IN_RANGE_CLOSED_CLOSED = 11

Criterion

class Criterion(variableName, condition, values)[source]
Parameters
  • variableName (str) – Variable name.

  • condition (Condition) – Condition.

  • values (list(float)) – Values.

Example

>>> from pyrootplots import Criterion
>>> from pyrootplots import Condition
>>> crit = Criterion("eta", Condition.LESS_THAN_OR_EQUAL_TO, [2.5])
>>> print(crit)
eta <= 2.5

Cut

class Cut(criterion, sigEvtBefore, sigEvtAfter, bkgEvtBefore, bkgEvtAfter, sigScale=1.0, bkgScale=[1.0], scale=False)[source]

A cut is defined by a variable name (on which the cut is applied) and 1 or 2 values (defining the criterion). The number of signal and background events before and after the cut must be specified.

Parameters
  • criterion (Criterion) – Criterion defining the cut.

  • sigEvtBefore (float) – Number of signal events before the cut.

  • sigEvtAfter (float) – Number of signal events after the cut.

  • bkgEvtBefore (dict[str, float]) – Number of background events before the cut, for each background.

  • bkgEvtAfter (dict[str, float]) – Number of background events after the cut, for each background.

  • sigScale (float) – Scaling to luminosity factor for the signal.

  • bkgScale (list[float]) – Scaling to luminosity factor for each background.

  • scale (bool) – Whether or not the numbers displayed should be scaled to luminosity or not.

CutEffVsVal

class CutEffVsVal(evtBefore, evtAfter, variableName, yticks=array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.]), xlabel='', ylabel='events(after) / events(before)')[source]

Signal or background efficiency vs. cut value/threshold.

Parameters
  • evtBefore (list[float]) – Number of events before the cut, for each cut value.

  • evtAfter (list[float]) – Number of events after the cut, for each cut value.

  • variableName (str) – Name of the variable on which the cut is applied.

  • yticks – Y axis ticks position.

  • xlabel (str) – X axis label.

  • ylabel (str) – Y axis label.

plot(show=False)[source]
Parameters

show (bool) – True to call plt.show(), False otherwise.

Returns

self

Histogram1D

class Histogram1D(data, weights, bins, xmin, xmax, logx, logy, stacked, density=False, histStyle='bar', color=[], labels=[], makeLegend=True)[source]

1D histogram. :type data: list[DataFrame] :param data: List of data to fill histogram :type data: list[pandas.DataFrame] :type weights: list[DataFrame] :param weights: Multiply each bin by the value of the weighted bin. The shape of the weights list must be equal to that of the data.

If no weights is needed, default is set to 1.

Parameters
  • bins (int) – Number of bins for histogram.

  • xmin (float) – Minimum x-axis value

  • xmax (float) – Maximum x-axis value

  • logx (bool) – Set x-axis to log scale

  • logy (bool) – Set y-axis to log scale

  • stacked (bool) – Set to True if one wants to stack distributions. The default is set to False.

  • density (bool) – Integrates the histogram to 1: as density = counts / (sum(counts) * np.diff(bins)). By default set to False

  • histStyle (str) –

    The type of histogram to draw.

    ’bar’ is a traditional bar-type histogram. If multiple data are given the bars are arranged side by side. ‘barstacked’ is a bar-type histogram where multiple data are stacked on top of each other. ‘step’ generates a lineplot that is by default unfilled. ‘stepfilled’ generates a lineplot that is by default filled.

  • color (list[str]) – Color or sequence of colors, one per dataset

  • makeLegend (bool) – Bool to set legend

unitWeight(lenghtOfData)[source]
writeLegend(ax, labels=[], title='', position='upper right', ncols=1, spaceBetweenCols=0.8, shadow=False, facecolor='inherit', edgecolor='0.8')[source]
plot(ax)[source]

Histogram2D

class Histogram2D[source]

2D histogram.

fromTH2F()[source]

Constructs a 2D histogram from a TH2F ROOT object.

fromTH2D()[source]

Constructs a 2D histogram from a TH2D ROOT object.

plot()[source]

ROCCurve

class ROCCurve(cuts, title='ROC curve', xlabel='B(after) / B(before)', ylabel='S(after) / S(before)', xticks=array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.]), yticks=array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.]), xlim=[0.0, 1.0], ylim=[0.0, 1.0], minorGrid={}, majorGrid={}, scatter={}, txt=[])[source]

Receiver operating characteristic curve.

Parameters
  • cuts (list[Cut]) – List of the cuts to place on the ROC curve.

  • title (str) – Title of the ROC curve.

  • xlabel (str) – X axis label.

  • ylabel (str) – Y axis label.

  • xticks – X axis ticks position.

  • yticks – Y axis ticks position.

  • xlim (list(str)) – X axis boundaries.

  • ylim (list(str)) – Y axis boundaries.

  • minorGrid (dict) – Parameters passed to plt.grid(which = "minor").

  • majorGrid (dict) – Parameters passed to plt.grid(which = "major").

  • scatter (dict) – Parameters passed to plt.scatter().

  • txt (list[str]) –

plot(fig=None, ax=None, show=False, whichBkg='')[source]

Plots signal efficiency vs. background efficiency for each cut.

Parameters
  • fig – matplotlib Figure object.

  • ax – matplotlib Axes object.

  • show (bool) – True to call plt.show(), False otherwise.

  • whichBkg (str) – Name of the background.

Returns

self

ROOTDataLoader