Getting Started with analysis_helpers¶
This notebook demonstrates two common operations:
- Asymmetry calculation from binned yields
- Efficiency and confidence intervals from selected/total samples
In [ ]:
Copied!
import numpy as np
from analysis_helpers.asymmetry import get_asymmetry_array
from analysis_helpers.efficiency import get_efficiency
import numpy as np
from analysis_helpers.asymmetry import get_asymmetry_array
from analysis_helpers.efficiency import get_efficiency
1) Asymmetry from binned counts¶
In [ ]:
Copied!
arr1 = np.array([120, 98, 105, 132, 111], dtype=float)
arr2 = np.array([115, 102, 95, 128, 120], dtype=float)
asym, asym_err = get_asymmetry_array(arr1, arr2)
print('asymmetry =', np.round(asym, 4))
print('asymmetry err =', np.round(asym_err, 4))
arr1 = np.array([120, 98, 105, 132, 111], dtype=float)
arr2 = np.array([115, 102, 95, 128, 120], dtype=float)
asym, asym_err = get_asymmetry_array(arr1, arr2)
print('asymmetry =', np.round(asym, 4))
print('asymmetry err =', np.round(asym_err, 4))
2) Efficiency with binned events¶
Here we create a toy dataset and emulate a simple selection threshold.
In [ ]:
Copied!
rng = np.random.default_rng(42)
total = rng.normal(loc=0.0, scale=1.0, size=4000)
passed = total[total > -0.2]
bin_edges = np.linspace(-3.0, 3.0, 13)
eff, eff_cl = get_efficiency(passed, total, bin_edges)
print('efficiency =', np.round(eff, 3))
print('lower CL =', np.round(eff_cl[0], 3))
print('upper CL =', np.round(eff_cl[1], 3))
rng = np.random.default_rng(42)
total = rng.normal(loc=0.0, scale=1.0, size=4000)
passed = total[total > -0.2]
bin_edges = np.linspace(-3.0, 3.0, 13)
eff, eff_cl = get_efficiency(passed, total, bin_edges)
print('efficiency =', np.round(eff, 3))
print('lower CL =', np.round(eff_cl[0], 3))
print('upper CL =', np.round(eff_cl[1], 3))
Next steps¶
- Replace toy arrays with your analysis variables
- Add event weights and pass them through the weighted API
- Visualize efficiency vs. the bin centers with matplotlib