Ejemplo n.º 1
0
    def parse_observables(self, obslitst):
        observables = []
        allnames = []
        for obs in obslitst:
            if isinstance(obs, str):
                obsdict = {'name':obs}
            elif isinstance(obs, dict):
                obsdict = obs.copy()
            else:
                raise ConfigError("Observable format not understood: %s" % obs)
            namestr = obsdict.pop('name')
            names = glob.glob(namestr)
            if not names:
                raise ConfigError("No observables found for %s" %
                                  namestr)
            allnames += names
        for name in allnames:
            try:
                obsobj = make_observable(name, **obsdict)
            except ValueError as e:
                raise ConfigError("Could not parse the observable %s: %s"
                                       % (name, e))
            except TypeError as e:
                    raise ConfigError("Incorrect arguments passed to process "
                                      "observable %s: %s" % (name, e))
            observables.append(obsobj)
        s = set(observables)
        if len(s) != len(observables):
            c = Counter(observables)
            dups = [obs.name for obs in observables if c[obs]>1]
            obs = c.keys()
            logging.warn("Duplicate observables: %s" % dups)

        return observables
Ejemplo n.º 2
0
 def test_const_results(self):
     pdf = PDF('NNPDF30_nlo_as_0118')
     obs = make_observable('data/higgs/ggh_13tev.root', order=1)
     res = produce_results(pdf, obs)[0]._data.as_matrix()
     previous = [ 31.22150023,  28.9888971 ,  31.3305855 ,  31.35700134,
     30.66074282,  28.2795592 ,  31.50932389,  31.43558106,
     31.28601552,  31.36406676,  30.69818304,  30.86453794,
     31.62708945,  31.6582997 ,  31.11008626,  31.59319744,
     31.52866286,  31.28639456,  31.07427256,  31.41568155,
     31.60044526,  31.36966168,  30.93032191,  33.05392731,
     30.96536474,  31.4317893 ,  30.72436163,  31.22605137,
     31.24243901,  31.21880536,  31.68798426,  31.07646885,
     30.59035729,  31.34800315,  31.21256586,  32.19365014,
     31.58647388,  31.74649083,  31.04692704,  30.2313781 ,
     31.4132261 ,  31.01493873,  31.36481456,  31.26872855,
     31.09018502,  31.51168931,  31.28105268,  30.91102961,
     30.88952926,  31.31389055,  31.22196011,  31.19094082,
     31.03705732,  31.54684624,  31.25938782,  31.10403155,
     30.87467055,  31.83239232,  31.05799506,  31.68930494,
     31.0387522 ,  31.27327964,  31.30919955,  31.51614659,
     31.06029472,  31.43211917,  31.35963882,  32.68355944,
     30.96018759,  30.60001451,  31.25165147,  31.37222175,
     31.19241142,  29.4805518 ,  31.66853784,  30.96975209,
     30.61955437,  31.34032813,  32.0724701 ,  30.9346566 ,
     31.27130234,  31.38000397,  30.83068422,  31.50593514,
     31.22489125,  30.74042979,  31.21191289,  31.4358684 ,
     31.27231758,  31.81871636,  31.10093208,  30.64649533,
     31.40680264,  31.12985161,  31.8378625 ,  31.18650963,
     31.51129514,  31.18025208,  31.87366192,  31.78494394,  31.45846653]
     self.assertTrue(np.allclose(res, previous))
Ejemplo n.º 3
0
import contextlib

from smpdflib.initialization import init_app
if __name__ == '__main__':
    with contextlib.suppress(RuntimeError):
        init_app()

import matplotlib.pyplot as plt

from smpdflib.core import (PDF, make_observable, produce_results,
                           )

from smpdflib.reducedset import get_smpdf_params

pdf = PDF("MC900_nlo")
obs = [make_observable(path, order='NLO') for path in itertools.chain(
       sorted(glob.glob("data/z/*.root")),
       sorted(glob.glob("data/w/*.root")),
       sorted(glob.glob("data/higgs/*.root")),
       sorted(glob.glob("data/ttbar/*.root")),
       )]



tolerance = 0.05

thresholds = [0.0, 0.25, 0.5, 0.75, 0.9, 0.99]

if __name__ == '__main__':
    neig = []
    logging.basicConfig(level=logging.INFO)
Ejemplo n.º 4
0
from smpdflib.initialization import init_app

if __name__ == '__main__':
    init_app()

import matplotlib.pyplot as plt

from smpdflib.core import make_observable, PDF, produce_results, results_table

from smpdflib.plots import plot_bindist

#Db folder should exist...
db = shelve.open('db/db')


to_plot = {make_observable('data/applgrid/CMSWCHARM-WpCb-eta4.root', order=1)                      : 4,
           make_observable('data/applgrid/APPLgrid-LHCb-Z0-ee_arXiv1212.4260-eta34.root', order=1) : 8,
          }

pdfs = [PDF('MC900_nnlo', label="legendtext"),
        PDF('CMC100_nnlo', label="other"),
        PDF('MCH_nnlo_100', label="another")
       ]

if __name__ == '__main__':
    for obs, bin in to_plot.items():
        results = produce_results(pdfs, [obs], db=db)

        obs_table = results_table(results)
        for (obs,b), fig in plot_bindist(obs_table, bin, base_pdf = pdfs[0]):
            ax = fig.axes[0]
Ejemplo n.º 5
0
obs_name = 'data/z/z_13tev.root'

prior_name = "MC900_nnlo"

prefixes = ['z2tr'  + x for x in '0 10 25 50 75 90 99'.split()]

smpdf_names = [prefix + 'smpdf_' + prior_name for prefix in prefixes]

lincoef_paths = ['output/%s_lincomb.csv' % name for name in smpdf_names]

if __name__ == '__main__':
    prior = PDF(prior_name)
    smpdfs = [PDF(name) for name in smpdf_names]
    pdfs = [prior] + smpdfs
    obs = make_observable(obs_name, order='NLO')
    with shelve.open('db/db') as db:
        res_prior, *res_smpdfs = produce_results(pdfs, [obs], db=db)
    coefs = [pd.DataFrame.from_csv(path, sep='\t') for path in lincoef_paths]

    prior_std = res_prior.std_error()

    real_tols = [1 - res.std_error()/prior_std for res in res_smpdfs]

    prior_diffs = (res_prior._all_vals.T - res_prior.central_value).as_matrix().ravel()

    neig = [len(pdf) - 1 for pdf in smpdfs]

    rotated_tols = []
    for path in lincoef_paths:
        coefs = pd.DataFrame.from_csv(path, sep='\t')