We’ll demonstrate how a combination works by combining everything we’ve learned so far.
Loading the Workspace¶
To do so, we’ll use a simple workspace to demonstrate functionality of combinations.
import json
import pyhfwith open("data/2-bin_1-channel.json") as serialized:
spec = json.load(serialized)
workspace = pyhf.Workspace(spec)Combine Workspaces¶
Let’s just try to combine naively right now.
pyhf.Workspace.combine(workspace, workspace)As we can see, we can’t just combine a workspace with itself if it has some channel names in common. We try very hard in pyhf to make sure a combination “makes sense”.
Let’s go ahead and rename the channel (as well as the measurement). Then try to combine.
other_workspace = workspace.rename(
channels={"singlechannel": "othersinglechannel"},
modifiers={"uncorr_bkguncrt": "otheruncorr_bkguncrt"},
measurements={"Measurement": "OtherMeasurement"},
)
combined_workspace = pyhf.Workspace.combine(workspace, other_workspace)And did we combine?
print(f" channels: {combined_workspace.channels}")
print(f" nbins: {combined_workspace.channel_nbins}")
print(f" samples: {combined_workspace.samples}")
print(f" modifiers: {combined_workspace.modifiers}")
print(f"measurements: {combined_workspace.measurement_names}")Indeed. And at this point, we can just use all the same functionality we expect of pyhf, such as performing a fit:
model = workspace.model()
data = workspace.data(model)
test_poi = 1.0
pyhf.infer.hypotest(test_poi, data, model, test_stat="qtilde")other_model = other_workspace.model()
other_data = other_workspace.data(other_model)
pyhf.infer.hypotest(test_poi, other_data, other_model, test_stat="qtilde")combined_model = combined_workspace.model()
combined_data = combined_workspace.data(combined_model)
pyhf.infer.hypotest(test_poi, combined_data, combined_model, test_stat="qtilde")