This repository provides a self-contained example demonstrating how to perform a template fit using pyhf. It adapts an online HistFactory tutorial and refactors it into a more realistic scenario. Specifically, we fit the observable ( R_{D^} ) in the decay ( D^ \to \tau \nu_\tau ), where ( R_{D^*} ) is defined as:
[ R_{D^} = \frac{\mathcal{B}(D^ \to \tau \nu_\tau)}{\mathcal{B}(D^* \to \mu \nu_\mu)}. ]
In this example, there is a single analysis region containing four samples:
- sigmu
- sigtau
- D1
- misID
The template histograms are stored in DemoHistos.root
as three-dimensional histograms, and the data histogram is named h_data
.
This example includes the following scripts, which perform the same fit but use different tools or languages:
-
HistFactDstTauDemo_new.C
Uses CERN ROOT HistFactory in C++. Can be run by typingroot -l run_HistFactDstTauDemo_new.C
in the terminal. -
HistFactDstTauDemo.py
Uses CERN ROOT HistFactory in Python, mirroring the structure of the C++ script. Can be run by typingpython run_HistFactDstTauDemo.py
in the terminal. -
HistFactDstTauDemo_pyhf.py
Uses pyhf to flatten the 3D histograms into 1D, then performs the fit.
Also uses cabinetry for visualization. Can be run by typingpython run_HistFactDstTauDemo_pyhf.py
in the terminal. -
HistFactDstTauDemo_pyhf_new.ipynb
In this jupyter notebook, we first flatten the 3D histograms into 1D, then perform the fit by using pyhf. The model is constructed by using- pyhf, and the fit is performed by using pyhf.
- cabinetry, where the 1D flattened histograms are collected and used for the model construction.
Feel free to explore these scripts as a reference for your own analyses or as a stepping stone for integrating ROOT-based workflows with pyhf.