Utility belt for spey-pyhf plug-in#
Working with full likelihoods from HEPData#
The spey-pyhf plug-in includes a set of helper functions to manipulate the input data in a spey-ready fashion.
We will use an example background-only JSON file which is downloaded from HEPData, but you can use any background-only JSON file.
Load the background file. You can use any background only JSON file for this example. Simply adjust the rest of the code accordingly.#
with open("/PATH/TO/BkgOnly.json", "r") as f:
bkg_only = json.load(f)
spey_pyhf.helper_functions.WorkspaceInterpreter scans the background-only dictionary and extracts relevant information such as channel names:
interpreter = WorkspaceInterpreter(bkg_only)
print(list(interpreter.channels))
['WREM_cuts', 'STCREM_cuts', 'TRHMEM_cuts', 'TRMMEM_cuts', 'TRLMEM_cuts', 'SRHMEM_mct2', 'SRMMEM_mct2', 'SRLMEM_mct2']
and information about bin sizes in each channel
print(interpreter.bin_map['SRHMEM_mct2'])
3
we can inject signal to any channel we like
interpreter.inject_signal('SRHMEM_mct2', [5.0, 12.0, 4.0])
Notice that we only added 3 inputs since the "SRHMEM_mct2" region has only 3 bins. One can inject signals to as many channels as one wants, but for simplicity, we will use only one channel. Now we are ready to export this signal patch and compute the exclusion limit
pdf_wrapper = spey.get_backend("pyhf")
statistical_model = pdf_wrapper(
analysis="simple_pyhf",
background_only_model=interpreter.background_only_model,
signal_patch=interpreter.make_patch(),
)
print(statistical_model.exclusion_confidence_level())
[0.9856303068018685]