How to use the flavio.classes.Prediction function in flavio

To help you get started, we’ve selected a few flavio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flav-io / flavio / flavio / test_functions.py View on Github external
def test_sm_covariance(self):
        o1 = Observable( 'test_obs 1' )
        o2 = Observable( 'test_obs 2' )
        def f1(wc_obj, par_dict):
            return par_dict['m_b']
        def f2(wc_obj, par_dict):
            return par_dict['m_c']
        Prediction('test_obs 1', f1)
        Prediction('test_obs 2', f2)
        cov_par = np.array([[0.1**2, 0.1*0.2*0.3], [0.1*0.2*0.3, 0.2**2]])
        d = flavio.statistics.probability.MultivariateNormalDistribution([4.2, 1.2], covariance=cov_par)
        par = copy.deepcopy(flavio.parameters.default_parameters)
        par.add_constraint(['m_b', 'm_c'], d)
        # test serial
        np.random.seed(135)
        cov = flavio.sm_covariance(['test_obs 1', 'test_obs 2'],
                                   N=1000, par_vary='all', par_obj=par)
        npt.assert_array_almost_equal(cov, cov_par, decimal=2)
        # test parallel
        np.random.seed(135)
        cov_parallel = flavio.sm_covariance(['test_obs 1', 'test_obs 2'],
                                   N=1000, par_vary='all', par_obj=par,
                                   threads=4)
        npt.assert_array_almost_equal(cov, cov_parallel, decimal=6)
        np.random.seed(135)
github flav-io / flavio / flavio / physics / bdecays / bvnunu.py View on Github external
# binned FL
        _obs_name = "("+M+"nunu)"
        _obs = flavio.classes.Observable(name=_obs_name, arguments=['q2min', 'q2max'])
        _obs.set_description(r"Binned longitudinal polarization fraction of $" + _process_tex + r"$")
        _obs.tex = r"$\langle F_L \rangle(" + _process_tex + r")$"
        _obs.add_taxonomy(_process_taxonomy + _process_tex + r"$")
        flavio.classes.Prediction(_obs_name, fl_int_summed(_hadr[M]['B'], _hadr[M]['V']))

        # differential FL
        _obs_name = "FL("+M+"nunu)"
        _obs = flavio.classes.Observable(name=_obs_name, arguments=['q2'])
        _obs.set_description(r"Differential longitudinal polarization fraction o f$" + _process_tex + r"$")
        _obs.tex = r"$F_L(" + _process_tex + r")$"
        _obs.add_taxonomy(_process_taxonomy + _process_tex + r"$")
        flavio.classes.Prediction(_obs_name, fl_summed(_hadr[M]['B'], _hadr[M]['V']))
github flav-io / flavio / flavio / physics / bdecays / bvll / observables.py View on Github external
def make_obs_pprime(M, l, obs, obsdict):
    B = _hadr[M]['B']
    V = _hadr[M]['V']
    func_num = obsdict['func_num']

    # binned "optimized"  angular observables
    _obs = make_metadata_binned(M, l, obs, obsdict)
    func = lambda wc_obj, par, q2min, q2max: BVll_int_pprime(func_num, q2min, q2max, B, V, l, wc_obj, par)()
    Prediction(_obs.name, func)

    # differential "optimized"  angular observables
    _obs = make_metadata_differential(M, l, obs, obsdict)
    func = lambda wc_obj, par, q2: BVll_pprime(func_num, q2, B, V, l, wc_obj, par)()
    Prediction(_obs.name, func)
github flav-io / flavio / flavio / physics / bdecays / bvlnu.py View on Github external
'dBR_L/dq2', 'BR_L', '',
               'dBR_T/dq2', 'BR_T', '',
               '<br>/', '<br>/', '<br>/',
               'dBR/dcl', 'dBR/dcV', 'dBR/dphi',
               '', 'FL', 'FLtot', 'FLttot', 'AFBtot', 'I3tot']:
        for M in _hadr.keys():
            _process_tex = _hadr[M]['tex']+_tex[l]+r"^+\nu_"+_tex[l]
            _obs_name = br + "("+M+l+"nu)"
            _obs = Observable(_obs_name)
            _obs.set_description(_desc[br] + r" branching ratio of $" + _process_tex + "$")
            _obs.tex = r'$' + _tex_br[br] + r"(" +_process_tex + ")$"
            _obs.arguments = _args[br]
            _obs.add_taxonomy(_process_taxonomy + _process_tex +  r'$')
            if br in _A:
                # for dBR/dq2, need to distinguish between total, L, and T
                Prediction(_obs_name, _func[br](_hadr[M]['B'], _hadr[M]['V'], l, A=_A[br]))
            else:
                # for other observables not
                Prediction(_obs_name, _func[br](_hadr[M]['B'], _hadr[M]['V'], l))


# Lepton flavour ratios
for l in [('mu','e'), ('tau','mu'), ('tau', 'l')]:
    for M in _hadr_l.keys():

        # binned ratio of BRs
        _obs_name = "("+M+"lnu)"
        _obs = Observable(name=_obs_name, arguments=['q2min', 'q2max'])
        _obs.set_description(r"Ratio of partial branching ratios of $" + _hadr_l[M]['tex'] +_tex[l[0]]+r"^+ \nu_"+_tex[l[0]]+r"$" + " and " + r"$" + _hadr_l[M]['tex'] +_tex[l[1]]+r"^+ \nu_"+_tex[l[1]]+r"$")
        _obs.tex = r"$\langle R_{" + _tex[l[0]] + ' ' + _tex[l[1]] + r"} \rangle(" + _hadr_l[M]['tex'] + r"\ell^+\nu)$"
        for li in l:
            for N in _hadr_l[M]['decays']:
github flav-io / flavio / flavio / physics / bdecays / bpll.py View on Github external
_process_taxonomy = r'Process :: $b$ hadron decays :: FCNC decays :: $B\to P\ell^+\ell^-$ :: $' + _process_tex + r"$"

        for obs in sorted(_observables.keys()):
            _obs_name = "&lt;" + obs + "&gt;("+M+l+l+")"
            _obs = Observable(name=_obs_name, arguments=['q2min', 'q2max'])
            _obs.set_description('Binned ' + _observables[obs]['desc'] + r" in $" + _process_tex + r"$")
            _obs.tex = r"$\langle " + _observables[obs]['tex'] + r"\rangle(" + _process_tex + r")$"
            _obs.add_taxonomy(_process_taxonomy)
            Prediction(_obs_name, bpll_obs_int_ratio_func(_observables[obs]['func_num'], dGdq2_cpaverage, _hadr[M]['B'], _hadr[M]['P'], l))

            _obs_name = obs + "("+M+l+l+")"
            _obs = Observable(name=_obs_name, arguments=['q2'])
            _obs.set_description(_observables[obs]['desc'][0].capitalize() + _observables[obs]['desc'][1:] + r" in $" + _process_tex + r"$")
            _obs.tex = r"$" + _observables[obs]['tex'] + r"(" + _process_tex + r")$"
            _obs.add_taxonomy(_process_taxonomy)
            Prediction(_obs_name, bpll_obs_ratio_func(_observables[obs]['func_num'], dGdq2_cpaverage, _hadr[M]['B'], _hadr[M]['P'], l))

        # binned branching ratio
        _obs_name = "("+M+l+l+")"
        _obs = Observable(name=_obs_name, arguments=['q2min', 'q2max'])
        _obs.set_description(r"Binned differential branching ratio of $" + _process_tex + r"$")
        _obs.tex = r"$\langle \frac{d\text{BR}}{dq^2} \rangle(" + _process_tex + r")$"
        _obs.add_taxonomy(_process_taxonomy)
        Prediction(_obs_name, bpll_dbrdq2_int_func(_hadr[M]['B'], _hadr[M]['P'], l))

        # differential branching ratio
        _obs_name = "dBR/dq2("+M+l+l+")"
        _obs = Observable(name=_obs_name, arguments=['q2'])
        _obs.set_description(r"Differential branching ratio of $" + _process_tex + r"$")
        _obs.tex = r"$\frac{d\text{BR}}{dq^2}(" + _process_tex + r")$"
        _obs.add_taxonomy(_process_taxonomy)
        Prediction(_obs_name, bpll_dbrdq2_func(_hadr[M]['B'], _hadr[M]['P'], l))
github flav-io / flavio / flavio / physics / bdecays / blnu.py View on Github external
return f

# Observable and Prediction instances
_tex = {'e': 'e', 'mu': '\mu', 'tau': r'\tau'}
_tex_B = {'B+': r'B^+', 'Bc': r'B_c'}
for l in ['e', 'mu', 'tau']:
    for B in ['B+', 'Bc']:
        _process_tex = _tex_B[B] + r"\to "+_tex[l]+r"^+\nu"
        _process_taxonomy = r'Process :: $b$ hadron decays :: Leptonic tree-level decays :: $B\to \ell\nu$ :: $' + _process_tex + r"$"

        _obs_name = "BR("+B+"->"+l+"nu)"
        _obs = flavio.classes.Observable(_obs_name)
        _obs.set_description(r"Branching ratio of $" + _process_tex + r"$")
        _obs.tex = r"$\text{BR}(" + _process_tex + r")$"
        _obs.add_taxonomy(_process_taxonomy)
        flavio.classes.Prediction(_obs_name, br_blnu_fct(B, l))
github flav-io / flavio / flavio / physics / zdecays / gammaz.py View on Github external
_obs = flavio.classes.Observable(_obs_name)
        _obs.tex = r"$\Gamma(" + _process_tex + r")$"
        _obs.set_description(r"Partial width of $" + _process_tex + r"$")
        _obs.add_taxonomy(r'Process :: $Z^0$ decays :: Flavour conserving decays :: $' + _process_tex + r"$")
        flavio.classes.Prediction(_obs_name, GammaZ_fct(f, f))

        _obs_name = "R_{}".format(f)
        _obs = flavio.classes.Observable(_obs_name)
        _obs.tex = r"$R_{}^0$".format(tex)
        _obs.add_taxonomy(r'Process :: $Z^0$ decays :: Flavour conserving decays :: $' + _process_tex + r"$")
        if f in _leptons:
            _obs.set_description(r"Ratio of $Z^0$ partial widths to hadrons vs. ${}$ pairs".format(tex))
            flavio.classes.Prediction(_obs_name, Remutau(f))
        else:
            _obs.set_description(r"Ratio of $Z^0$ partial widths to ${}$ pairs vs. all hadrons".format(tex))
            flavio.classes.Prediction(_obs_name, Rq(f))

_obs_name = "R_uc"
_obs = flavio.classes.Observable(_obs_name)
_obs.tex = r"$R_{uc}^0$"
_obs.add_taxonomy(r'Process :: $Z^0$ decays :: Flavour conserving decays :: $' + _process_tex + r"$")
_obs.set_description(r"Average ratio of $Z^0$ partial widths to $u$ or $c$ pairs vs. all hadrons")
flavio.classes.Prediction(_obs_name, Rq1q2('u', 'c'))

# LFV Z decays
for (f1, f2) in [('e', 'mu'), ('e', 'tau'), ('mu', 'tau'), ]:
    tex1 = _leptons[f1]
    tex2 = _leptons[f2]
    _obs_name = "BR(Z->{}{})".format(f1, f2)
    _obs = flavio.classes.Observable(_obs_name)
    _process_tex = r"Z^0\to {}^\pm{}^\mp".format(tex1, tex2)
    _obs.tex = r"$\text{BR}(" + _process_tex + r")$"
github flav-io / flavio / flavio / physics / taudecays / taupnu.py View on Github external
return f

# Observable and Prediction instances

_had = {'pi+': r'\pi^+', 'K+': r'K^+',}
_shortname = {'pi+': 'pi', 'K+': 'K'}

for P in _had:
    _obs_name = "BR(tau->" + _shortname[P]+"nu)"
    _obs = flavio.classes.Observable(_obs_name)
    _process_tex = r"\tau^+\to " + _had[P] + r"\bar\nu"
    _process_taxonomy = r'Process :: $\tau$ lepton decays :: Hadronic tree-level decays :: $\tau\to V\ell$ :: $' + _process_tex + r"$"
    _obs.add_taxonomy(_process_taxonomy)
    _obs.set_description(r"Branching ratio of $" + _process_tex + r"$")
    _obs.tex = r"$\text{BR}(" + _process_tex + r")$"
    flavio.classes.Prediction(_obs_name, br_taupnu_fct(P))
github flav-io / flavio / flavio / physics / mesonmixing / observables.py View on Github external
o.set_description(r"Normalized mass difference in the $D^0$-$\bar D^0$ system")
o.tex = r"$x_D$"
o.add_taxonomy(r'Process :: Meson-antimeson mixing ::  $D^0$-$\bar D^0$ mixing')
Prediction('x_D', lambda wc_obj, par: x(wc_obj, par, 'D0'))

o = Observable('y_D')
o.set_description(r"Normalized width difference in the $D^0$-$\bar D^0$ system")
o.tex = r"$y_D$"
o.add_taxonomy(r'Process :: Meson-antimeson mixing ::  $D^0$-$\bar D^0$ mixing')
Prediction('y_D', lambda wc_obj, par: y(wc_obj, par, 'D0'))

o = Observable('phi_D')
o.set_description(r"Phase of $q/p$ in the $D^0$-$\bar D^0$ system")
o.tex = r"$\phi_D$"
o.add_taxonomy(r'Process :: Meson-antimeson mixing ::  $D^0$-$\bar D^0$ mixing')
Prediction('phi_D', lambda wc_obj, par: phase(-q_over_p(wc_obj, par, 'D0')))

o = Observable('q/p_D')
o.set_description(r"Absolute value of $q/p$ in the $D^0$-$\bar D^0$ system")
o.tex = r"$\vert q/p\vert_D$"
o.add_taxonomy(r'Process :: Meson-antimeson mixing ::  $D^0$-$\bar D^0$ mixing')
Prediction('q/p_D', lambda wc_obj, par: abs(q_over_p(wc_obj, par, 'D0')))

o = Observable('x12_D')
o.set_description(r"Normalized absolute value of the dispersive mixing amplitude in the $D^0$-$\bar D^0$ system")
o.tex = r"$x_{12}^D$"
o.add_taxonomy(r'Process :: Meson-antimeson mixing ::  $D^0$-$\bar D^0$ mixing')
Prediction('x12_D', lambda wc_obj, par: x12(wc_obj, par, 'D0'))

o = Observable('y12_D')
o.set_description(r"Normalized absolute value of the absorptive mixing amplitude in the $D^0$-$\bar D^0$ system")
o.tex = r"$y_{12}^D$"
github flav-io / flavio / flavio / physics / bdecays / bvgamma.py View on Github external
_func = {'BR': BR, 'ACP': ACP}
_tex = {'BR': r'\text{BR}', 'ACP': r'A_{CP}'}
_desc = {'BR': 'Branching ratio', 'ACP': 'Direct CP asymmetry'}

_process_taxonomy = r'Process :: $b$ hadron decays :: FCNC decays :: $B\to V\gamma$ :: $'


for key in _func.keys():
    _obs_name = key + "(B+->K*gamma)"
    _obs = Observable(_obs_name)
    _process_tex = r"B^+\to K^{*+}\gamma"
    _obs.set_description(_desc[key] + r" of $" + _process_tex + r"$")
    _obs.tex = r'$' + _tex[key] + r"(" + _process_tex + r")$"
    _obs.add_taxonomy(_process_taxonomy + _process_tex + r"$")
    Prediction(_obs_name, BVgamma_function(_func[key], 'B+', 'K*+'))

    _obs_name = key + "(B0->K*gamma)"
    _obs = Observable(_obs_name)
    _process_tex = r"B^0\to K^{*0}\gamma"
    _obs.set_description(_desc[key] + r" of $" + _process_tex + r"$")
    _obs.tex = r'$' + _tex[key] + r"(" + _process_tex + r")$"
    _obs.add_taxonomy(_process_taxonomy + _process_tex + r"$")
    Prediction(_obs_name, BVgamma_function(_func[key], 'B0', 'K*0'))

_obs_name = "ACP(Bs->phigamma)"
_obs = Observable(_obs_name)
_process_tex = r"B_s\to \phi\gamma"
_obs.set_description(_desc['ACP'] + r" of $" + _process_tex + r"$")
_obs.tex = r'$' + _tex['ACP'] + r"(" + _process_tex + r")$"
_obs.add_taxonomy(_process_taxonomy + _process_tex + r"$")
Prediction(_obs_name, BVgamma_function(_func['ACP'], 'Bs', 'phi'))