How to use the flavio.physics 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 / statistics / test_classes.py View on Github external
def test_bayesian_fit_class(self):
        o = Observable( 'test_obs' )
        def f(wc_obj, par_dict):
            return par_dict['m_b']*2
        pr  = Prediction( 'test_obs', f )
        d = NormalDistribution(4.2, 0.2)
        m = Measurement( 'measurement of test_obs' )
        m.add_constraint(['test_obs'], d)
        par = copy.deepcopy(flavio.parameters.default_parameters)
        par.set_constraint('m_b', '4.2+-0.2')
        par.set_constraint('m_c', '1.2+-0.1')
        par.set_constraint('m_s', '0.10(5)')
        wc = flavio.physics.eft.WilsonCoefficients()
        fit = BayesianFit('bayesian_test_fit_1', par, wc, ['m_b','m_c'],  ['m_s'], ['CVLL_bsbs','CVRR_bsbs'], ['measurement of test_obs'])
        self.assertEqual(fit.dimension, 7)
        # test from array to dict ...
        d = fit.array_to_dict(np.array([1.,2.,3.,4.,5.,6.,7.]))
        self.assertEqual(d, {'nuisance_parameters': {'m_s': 3.0}, 'fit_parameters': {'m_c': 2.0, 'm_b': 1.0}, 'fit_coefficients': {'CVLL_bsbs': 4.0+5.j, 'CVRR_bsbs': 6.0+7.0j}})
        # ... and back
        np.testing.assert_array_equal(fit.dict_to_array(d), np.array([1.,2.,3.,4.,5.,6.,7.]))
        self.assertEqual(fit.get_random.shape, (7,))
        fit.log_prior_parameters(np.array([4.5,1.0,0.08,4.,5.,6.,7.]))
        fit.get_predictions(np.array([4.5,1.0,0.08,4.,5.,6.,7.]))
        fit.log_likelihood(np.array([4.5,1.0,0.08,4.,5.,6.,7.]))
        # removing dummy instances
        BayesianFit.del_instance('bayesian_test_fit_1')
        Observable.del_instance('test_obs')
        Measurement.del_instance('measurement of test_obs')
github flav-io / flavio / flavio / physics / bdecays / test_blnu.py View on Github external
def test_blnu(self):
        Vub = flavio.physics.ckm.get_ckm(par)[0,2]
        # compare to literature value
        self.assertAlmostEqual(
            flavio.Observable["BR(B+->taunu)"].prediction_central(constraints, wc_obj),
            1.1e-4 * (abs(Vub)/3.95e-3)**2 * (par['f_B+']/0.2)**2,
            delta=2e-6)
        # check that B->enu BR is smaller than B->munu
        # (ratio given by mass ratio squared)
        self.assertAlmostEqual(
            (
            flavio.Observable["BR(B+->enu)"].prediction_central(constraints, wc_obj)/
            flavio.Observable["BR(B+->munu)"].prediction_central(constraints, wc_obj)
            )/(par['m_e']**2/par['m_mu']**2),
            1,
            delta=0.001) # there are corrections of order mmu**2/mB**2
        # check that Bc->taunu is larger by Vcb^2/Vub^2 (and more due to decay constant)
        self.assertAlmostEqual(
github flav-io / flavio / flavio / physics / bdecays / test_bpll.py View on Github external
c.set_constraint('B->K BCL a1_f+', -0.674)
c.set_constraint('B->K BCL a2_f+', -1.12)
c.set_constraint('B->K BCL a0_f0', 0.545)
c.set_constraint('B->K BCL a1_f0', -1.91)
c.set_constraint('B->K BCL a2_f0', 1.83)
c.set_constraint('B->K BCL a0_fT', 0.402)
c.set_constraint('B->K BCL a1_fT', -0.535)
c.set_constraint('B->K BCL a2_fT', -0.286)

par = c.get_central_all()

wc_obj = WilsonCoefficients()
wc = wctot_dict(wc_obj, 'bsmumu', 4.2, par)

wc_sm = flavio.physics.eft.WilsonCoefficients()
wc_lfv = flavio.physics.eft.WilsonCoefficients()
wc_lfv.set_initial({'C10_bsemu':4., 'C10_bsmue':2.}, 160.)


class TestBPll(unittest.TestCase):
    def test_bkll(self):
        # rough numerical test for branching ratio at high q^2 to old code
        self.assertAlmostEqual(bpll_dbrdq2(15., wc_obj, par, 'B+', 'K+', 'mu')/2.1824401629030333e-8, 1, delta=0.15)
        # test for errors
        flavio.sm_prediction('dBR/dq2(B0->Kmumu)', q2=3)
        flavio.sm_prediction('AFB(B0->Kmumu)', q2=15)
        flavio.sm_prediction('FH(B+->Kmumu)', q2=21)
        # direct CP asymmetry should be close to 0
        self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->Kmumu)", q2=1), 0, delta=0.01)
        self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->Kmumu)", q2=6), 0, delta=0.01)
        self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->Kmumu)", q2=17), 0, delta=0.01)
        self.assertAlmostEqual(flavio.sm_prediction("ACP(B+->Kmumu)", q2=1), 0, delta=0.01)
github flav-io / flavio / flavio / physics / bdecays / test_lambdablambdall.py View on Github external
import unittest
import numpy as np
import flavio


wc_sm = flavio.WilsonCoefficients()
# choose parameters as required to compare numerics to arXiv:1602.01399
par_nominal = flavio.default_parameters.copy()
flavio.physics.bdecays.formfactors.lambdab_12.lattice_parameters.lattice_load_nominal(par_nominal)
par_nominal.set_constraint('Vcb', 0.04175)
par_nominal.set_constraint('tau_Lambdab', 1/4.49e-13) # PDG 2016 value
par_nominal.set_constraint('Lambda->ppi alpha_-', 0.642) # PDG 2016 value
par_dict = par_nominal.get_central_all()

def ass_sm(s, name, q2min, q2max, target, delta, scalef=1):
    obs = flavio.classes.Observable[name]
    c = obs.prediction_central(par_nominal, wc_sm, q2min, q2max)*scalef
    s.assertAlmostEqual(c, target, delta=delta)

class TestLambdabLambdall(unittest.TestCase):
    def test_lambdablambdall(self):
        # first, make sure we use the same CKM factor as in arXiv:1602.01399 eq. (69)
        self.assertAlmostEqual(abs(flavio.physics.ckm.xi('t', 'bs')(par_dict)), 0.04088, delta=0.0001)
        # compare to table VII of 1602.01399
        ass_sm(self, '(Lambdab->Lambdamumu)', 0.1, 2, 0.25, 0.01, 1e7)
github flav-io / flavio / flavio / physics / bdecays / bpnunu.py View on Github external
def prefactor(q2, par, B, P):
    GF = par['GF']
    scale = flavio.config['renormalization scale']['bpll']
    alphaem = flavio.physics.running.running.get_alpha(par, scale)['alpha_e']
    di_dj = flavio.physics.bdecays.common.meson_quark[(B,P)]
    xi_t = flavio.physics.ckm.xi('t',di_dj)(par)
    return 4*GF/sqrt(2)*xi_t*alphaem/(4*pi)
github flav-io / flavio / flavio / physics / bdecays / bvll / nonfactorizable.py View on Github external
def function(wc_obj, par_dict, q2, cp_conjugate):
        return flavio.physics.bdecays.bvll.qcdf_interpolate.helicity_amps_qcdf(q2, par_dict, B, V, cp_conjugate, contribution)
    return function
github flav-io / flavio / flavio / physics / kdecays / kpilnu.py View on Github external
def logC(wc_obj, par, lep):
    mK = par['m_KL']
    mP = par['m_pi+']
    ml = par['m_' + lep]
    q2 = mK**2 - mP**2
    ff = get_ff(q2, par, 'KL')
    ff0 = get_ff(0, par, 'KL')
    scale = par['m_rho0']
    ms = flavio.physics.running.running.get_ms(par, scale)
    wc = flavio.physics.bdecays.wilsoncoefficients.get_wceff_fccc(wc_obj, par, 'su', lep, lep, ms, scale, nf=3)
    A = ml / q2 * (wc['a'] + wc['ap']).real
    mu = 0  # mu/ms neglected
    C = ff['f0'] / ff0['f0'] * ((wc['p'] + wc['pp']).real / (ms + mu) + A) / A
    return log(C)
github flav-io / flavio / flavio / physics / bdecays / bpnunu.py View on Github external
def get_ff(q2, par, B, P):
    ff_name = flavio.physics.bdecays.common.meson_ff[(B,P)] + ' form factor'
    return flavio.classes.AuxiliaryQuantity[ff_name].prediction(par_dict=par, wc_obj=None, q2=q2)
github flav-io / flavio / flavio / physics / bdecays / formfactors / b_p / isgurwise.py View on Github external
def isgur_wise(process, q2, ff, par, scale):
    pd = flavio.physics.bdecays.formfactors.b_p.bcl.process_dict[process]
    mB = par['m_'+pd['B']]
    mP = par['m_'+pd['P']]
    aT = par[process + ' IW a_T'] # a_T is a relative power correction
    ff['fT'] = ff['f+'] * (1 + aT)
    return ff