Description
Hey @alexander-held
For our analysis we would like to have a sqrt(mu) dependence of our LQ interference term. We found these custom modfiers of @lukasheinrich here that enables pyhf to accept definitions of custom functions (see also this pyhf feature branch). I tried a simple example with pyhf to verify that it also works with sqrt
:
import pyhf
import numpy as np
from add_custom_modifier import add_custom_modifier
new_params = {
'm1': { 'inits': (1.0,), 'bounds': ((-5.0, 5.0),) },
'm2': { 'inits': (1.0,), 'bounds': ((-5.0, 5.0),) }
}
expanded_pyhf = add_custom_modifier('customfunc', ['m1', 'm2'], new_params)
model_pyhf = pyhf.Model(
{
'channels': [
{
'name': 'singlechannel',
'samples': [
{
'name': 'signal', 'data': [10] * 20,
'modifiers': [
{ 'name': 'f_s', 'type': 'customfunc', 'data': { 'expr': 'm1' } },
],
},
{
'name': 'background', 'data': [100] * 20, 'modifiers': [
{ 'name': 'f_b', 'type': 'customfunc', 'data': { 'expr': 'm2' } }, # m2 should be set to 1.0, model doesn't work if I set 'expr': ''
]
},
{
'name': 'interference', 'data': [-1] * 20,
'modifiers': [
{ 'name': 'f_i', 'type': 'customfunc', 'data': { 'expr': '-sqrt(m1)' } },
],
},
],
}
]
},
modifier_set = expanded_pyhf,
poi_name = 'm1',
validate = False,
batch_size = 1
)
print(f'\nmodel_pyhf.expected_actualdata([[4.0, 1.0]]): {model_pyhf.expected_actualdata([[4.0, 1.0]])}\n')
which gives the desired output:
{'name': 'f_b', 'type': 'customfunc', 'data': {'expr': 'm2'}}
{'name': 'f_i', 'type': 'customfunc', 'data': {'expr': '-sqrt(m1)'}}
{'name': 'f_s', 'type': 'customfunc', 'data': {'expr': 'm1'}}
model_pyhf.expected_actualdata([[4.0, 1.0]]): [[142. 142. 142. 142. 142. 142. 142. 142. 142. 142. 142. 142. 142. 142.
142. 142. 142. 142. 142. 142.]]
Now it would be great if we can also use this feature in cabinetry. I tried already by manipulating a workspace JSON created by cabinetry and reading it back in, but obviously while trying to validate the workspace it fails since it can't find the modifiers.
I know that there might be some development (or merging) necessary on pyhf but it would be very benificial for us if we can start a harmonisation somewhere/somehow!
Many thanks already!
Roman
(more on my studies to custom modifiers can be found on this branch, our working cabinetry setup that we want to modfiy with srqt
can be found on this branch)