Utilities reference
Core functionality (utils.core
)
Helper functions (utils.helpers
)
has_zfit = core.zfit_installed()
module-attribute
bin_nums_from_hist(hist)
Source code in src/triggercalib/utils/helpers.py
bins_from_taxis(axis, as_array=False)
Extract bin edges from a ROOT TAxis object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
ROOT TAxis object to extract bins from |
required | |
as_array
|
Whether to return bins as a ROOT array |
False
|
Returns:
Type | Description |
---|---|
list or array: List of bin edges or ROOT array of bin edges |
Source code in src/triggercalib/utils/helpers.py
construct_variable(name, backend, value=None, limits=None, title=None)
Source code in src/triggercalib/utils/helpers.py
create_dataset(data, observable, weight='')
Source code in src/triggercalib/utils/helpers.py
empty_histogram(name, binning)
Create an empty ROOT.TH1D with specified binning scheme
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Name for the histogram |
required | |
binning
|
binning scheme of interest |
required |
Returns:
Type | Description |
---|---|
TH1D or TH2D: Empty histogram with appropriate binning |
Source code in src/triggercalib/utils/helpers.py
fit_result_to_string(fit_result)
Source code in src/triggercalib/utils/helpers.py
get_backend(data=None, observable=None, pdf=None)
Source code in src/triggercalib/utils/helpers.py
get_variable_name(observable)
Source code in src/triggercalib/utils/helpers.py
parse_selection(particle, selection, category, branches)
Parse trigger selection strings into ROOT cut expressions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection
|
Union[str, List[str]]
|
Trigger line(s) to create selection for |
required |
category
|
Literal['', 'TIS', 'TOS']
|
Optional trigger outcome category (TIS/TOS) to append |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
ROOT cut expression combining the selections |
Source code in src/triggercalib/utils/helpers.py
sum_bins(hist)
Source code in src/triggercalib/utils/helpers.py
tgraph_to_np(tgraph, xscale=1, yscale=1, zscale=1, symmetric_uncertainties=False)
Source code in src/triggercalib/utils/helpers.py
tgraph_to_th(graph, name='', title='')
Convert a ROOT TGraph(2D)AsymmErrors to a TH1(2)D
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
ROOT TGraph(2D)AsymmErrors to convert |
required | |
name
|
Optional name for output histogram |
''
|
|
title
|
Optional title for output histogram |
''
|
Returns:
Type | Description |
---|---|
TH1D or TH2D: Histogram containing graph points with symmetric errors |
Source code in src/triggercalib/utils/helpers.py
th_to_np(th, xscale=1, yscale=1, zscale=1)
Source code in src/triggercalib/utils/helpers.py
write_fit_result(fit_result, path, verbose=False)
Source code in src/triggercalib/utils/helpers.py
I/O functionality (utils.io
)
load_config(path)
Load a configuration file from a JSON or YAML file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path to the configuration file |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Configuration as a dictionary |
Raises:
Type | Description |
---|---|
ValueError
|
If the file is not a '.json' or '.yaml' file |
Source code in src/triggercalib/utils/io.py
split_paths(paths, require_same_tree=True)
Split ROOT file paths into tree names and file paths
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths
|
Union[List[str], str]
|
Path(s) to ROOT file(s) of the form |
required |
require_same_tree
|
bool
|
Whether all paths must reference the same tree |
True
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tree name(s) and file path(s) |
Raises:
Type | Description |
---|---|
ValueError
|
If require_same_tree is True and different trees are provided |
Source code in src/triggercalib/utils/io.py
write_config(config, path)
Source code in src/triggercalib/utils/io.py
Statistics tools (utils.stats
)
poisson(passed, total, passed_error=None, total_error=None)
Calculate the efficiency and symmetric uncertainty based on propagation of Poisson-like errors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
passed
|
Union[float, List[float], ndarray[float]]
|
int or array of int Number of events passing a criteria (numerator of the efficiency). |
required |
total
|
Union[float, List[float], ndarray[float]]
|
int or array of int Total number of events (denominator of the efficiency). |
required |
passed_error
|
Union[float, List[float], ndarray[float]]
|
int or array of int, optional
Uncertainty on the number of events that pass some criteria if not strictly Poissonian;
defaults to Poissonian uncertainty, |
None
|
total_error
|
Union[float, List[float], ndarray[float]]
|
int or array of int, optional
Uncertainty on the total number of events if not strictly Poissonian;
defaults to Poissonian uncertainty, |
None
|
Returns:
Name | Type | Description |
---|---|---|
value |
float or array of float The raw efficiency (passed / total). |
|
lower_error |
float or array of float The symmetric error on the efficiency |
|
upper_error |
float or array of float The upper error on the efficiency (same as lower error, since uncertainty is symmetric) |
Notes
This function implements the propagation of Poisson-like uncertainties as detailed in Eq. 14 of LHCb-PUB-2014-039 (https://cds.cern.ch/record/1701134/).
Source code in src/triggercalib/utils/stats.py
wilson(passed, total, confidence=0.68, passed_error=None, total_error=None)
Calculate the efficiency and lower/upper uncertainties based on a generalised Wilson interval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
passed
|
Union[float, List[float], ndarray[float]]
|
float or array of float Number of events passing a critera (numerator of the efficiency) |
required |
total
|
Union[float, List[float], ndarray[float]]
|
float or array of float Total number of events (denominator of the efficiency) |
required |
confidence
|
float
|
float, optional Confidence level for the interval; defaults to 0.68 (1 sigma), per the recommendation of the LHCb Statistics guidelines |
0.68
|
passed_error
|
Union[float, List[float], ndarray[float]]
|
int or array of int, optional
Uncertainty on the number of events that pass some criteria if not strictly Poissonian; defaults to Poissonian uncertainty, |
None
|
total_error
|
Union[float, List[float], ndarray[float]]
|
int or array of int, optional
Uncertainty on the total number of events if not strictly Poissonian; defaults to Poissonian uncertainty, |
None
|
Returns:
Name | Type | Description |
---|---|---|
efficiency |
float or array of float The raw efficiency (passed / total) |
|
lower_error |
float or array of float The lower error on the efficiency from the Wilson interval |
|
upper_error |
float or array of float The upper error on the efficiency from the Wilson interval |
Notes
This function implements the generalised Wilson interval of H. Dembinski and M. Schmelling, 2022 (https://arxiv.org/pdf/2110.00294).
Source code in src/triggercalib/utils/stats.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
Test utilities (utils.tests
)
distributions = {'breitwigner': 'BreitWigner', 'doublecrystalball': 'CrystalBall', 'exponential': 'Exponential', 'gauss': 'Gaussian'}
module-attribute
build_component(ws, name, observable, component)
Build a RooFit PDF component
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ws
|
RooWorkspace to build component in |
required | |
name
|
Name for the component |
required | |
observable
|
Observable to build PDF for |
required | |
component
|
Component configuration dictionary |
required |
Returns:
Name | Type | Description |
---|---|---|
RooAbsPdf |
Built PDF component |
Source code in src/triggercalib/utils/tests.py
check_result(value, error, sample='example_file.root:Hlt2Test/DecayTree', cut='', line='Hlt1DummyOne', threshold=5.0)
Check if a test result matches expectations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
float
|
Measured value to check |
required |
error
|
Annotated[List[float], 2]
|
List of lower and upper uncertainties |
required |
sample
|
str
|
Path to input ROOT file and tree |
'example_file.root:Hlt2Test/DecayTree'
|
cut
|
str
|
Additional selection criteria |
''
|
line
|
str
|
Trigger line to check |
'Hlt1DummyOne'
|
threshold
|
float
|
Maximum allowed deviation in percent |
5.0
|
Returns:
Name | Type | Description |
---|---|---|
bool |
Whether result matches expectations within threshold |