예제 #1
0
def data_source_dict(model, input_spec, **options):
    if input_spec == 'data':
        source_dict = {'type': 'histo_source', 'name': 'source'}
        for o in model.observables:
            source_dict[o] = model.data_histos[o].get_cfg(False)
        if len(model.data_rvobsvalues) > 0:
            source_dict['rvobs-values'] = dict(model.data_rvobsvalues)
        return (source_dict,
                theta_interface.delta_distribution(beta_signal=0.0))
    elif input_spec.startswith('toys:') or input_spec.startswith(
            'toys-asimov:'):
        beta_signal_value = float(input_spec[input_spec.find(':') + 1:])
        seed = 1
        if 'toydata_seed' in options: seed = int(options['toydata_seed'])
        result = {
            'type': 'model_source',
            'name': 'source',
            'model': '@model',
            'rnd_gen': {
                'seed': seed
            }
        }
        if input_spec.startswith('toys-asimov:'):
            result['dice_poisson'] = False
            result['dice_template_uncertainties'] = False
        return (result,
                theta_interface.delta_distribution(
                    beta_signal=beta_signal_value))
    else:
        raise RuntimeError, 'data_source dict: not implemented for input = "%s"' % input_spec
예제 #2
0
def signal_prior_dict(spec):
    if type(spec) == str:
        if spec.startswith('flat'):
            if spec.startswith('flat:'):
                res = re.match('flat:\[([^,]+),(.*)\]', spec)
                if res is None:
                    raise RuntimeError, "signal_prior specification '%s' invalid (does not match range specification syntax)" % spec
                xmin, xmax = float(res.group(1)), float(res.group(2))
            else:
                if spec != 'flat':
                    raise RuntimeError, "signal_prior specification '%s' invalid" % spec
                xmin, xmax = 0.0, float("inf")
            value = 0.5 * (xmax - xmin)
            if value == float("inf"): value = 1.0
            signal_prior_dict = {
                'type': 'flat_distribution',
                'beta_signal': {
                    'range': [xmin, xmax],
                    'fix-sample-value': value
                }
            }
        elif spec.startswith('fix:'):
            v = float(spec[4:])
            signal_prior_dict = theta_interface.delta_distribution(
                beta_signal=v)
        else:
            raise RuntimeError, "signal_prior specification '%s' unknown" % spec
    else:
        if type(spec) != dict:
            raise RuntimeError, "signal_prior specification has to be a string ('flat' / 'fix:X') or a dictionary!"
        signal_prior_dict = spec
    return signal_prior_dict
예제 #3
0
def data_source_dict(model, input_spec, **options):
    if input_spec == 'data':
        source_dict = {'type': 'histo_source', 'name': 'source'}
        for o in model.observables:
            source_dict[o] = model.data_histos[o].get_cfg(False)
        if len(model.data_rvobsvalues) > 0:
            source_dict['rvobs-values'] = dict(model.data_rvobsvalues)
        return (source_dict, theta_interface.delta_distribution(beta_signal = 0.0))
    elif input_spec.startswith('toys:') or input_spec.startswith('toys-asimov:'):
        beta_signal_value = float(input_spec[input_spec.find(':') + 1:])
        seed = 1
        if 'toydata_seed' in options: seed = int(options['toydata_seed'])
        result = {'type': 'model_source', 'name': 'source', 'model': '@model', 'rnd_gen': {'seed': seed}}
        if input_spec.startswith('toys-asimov:'):
            result['dice_poisson'] = False
            result['dice_template_uncertainties'] = False
        return (result, theta_interface.delta_distribution(beta_signal = beta_signal_value))
    else: raise RuntimeError, 'data_source dict: not implemented for input = "%s"' % input_spec
예제 #4
0
def signal_prior_dict(spec):
    if type(spec) == str:
        if spec.startswith('flat'):
            if spec.startswith('flat:'):
                res = re.match('flat:\[([^,]+),(.*)\]', spec)
                if res is None: raise RuntimeError, "signal_prior specification '%s' invalid (does not match range specification syntax)" % spec
                xmin, xmax = float(res.group(1)), float(res.group(2))
            else:
                if spec!='flat': raise RuntimeError, "signal_prior specification '%s' invalid" % spec
                xmin, xmax = 0.0, float("inf")
            value = 0.5 * (xmax - xmin)
            if value==float("inf"): value = 1.0
            signal_prior_dict = {'type': 'flat_distribution', 'beta_signal': {'range': [xmin, xmax], 'fix-sample-value': value}}
        elif spec.startswith('fix:'):
            v = float(spec[4:])
            signal_prior_dict = theta_interface.delta_distribution(beta_signal = v)
        else: raise RuntimeError, "signal_prior specification '%s' unknown" % spec
    else:
        if type(spec) != dict: raise RuntimeError, "signal_prior specification has to be a string ('flat' / 'fix:X') or a dictionary!"
        signal_prior_dict = spec
    return signal_prior_dict