Skip to content

Commit

Permalink
refactor spec walking
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich committed Nov 25, 2020
1 parent 777c72a commit 11abd9a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/pyhf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ def _nominal_and_modifiers_from_spec(config, spec):
helper.setdefault(c['name'], {})[s['name']] = (c, s)

mega_samples = {}
for s in config.samples:
mega_nom = []
for c in config.channels:
for c in config.channels:
for s in config.samples:
mega_samples.setdefault(s,{'name': f'mega_{s}', 'nom': []})

defined_samp = helper.get(c, {}).get(s)
defined_samp = None if not defined_samp else defined_samp[1]
# set nominal to 0 for channel/sample if the pair doesn't exist
Expand All @@ -140,7 +141,7 @@ def _nominal_and_modifiers_from_spec(config, spec):
if defined_samp
else [0.0] * config.channel_nbins[c]
)
mega_nom += nom
mega_samples[s]['nom'] += nom
defined_mods = (
{f"{x['type']}/{x['name']}": x for x in defined_samp['modifiers']}
if defined_samp
Expand Down Expand Up @@ -188,8 +189,6 @@ def _nominal_and_modifiers_from_spec(config, spec):
mega_mods[key][s]['data']['uncrt'] += uncrt
mega_mods[key][s]['data']['nom_data'] += nom

sample_dict = {'name': f'mega_{s}', 'nom': mega_nom}
mega_samples[s] = sample_dict

nominal_rates = default_backend.astensor(
[mega_samples[s]['nom'] for s in config.samples]
Expand Down Expand Up @@ -556,6 +555,7 @@ def __init__(self, spec, custom_modifiers = None, batch_size=None, **config_kwar
model (:class:`~pyhf.pdf.Model`): The Model instance.
"""
custom_modifiers = custom_modifiers or []
self.batch_size = batch_size
self.spec = copy.deepcopy(spec) # may get modified by config
self.schema = config_kwargs.pop('schema', 'model.json')
Expand Down

0 comments on commit 11abd9a

Please sign in to comment.