Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bxclnu_lfu(self):
self.assertAlmostEqual(
flavio.sm_prediction('Rmue(B->Xclnu)'), 1, delta=0.01)
self.assertAlmostEqual(
flavio.sm_prediction('Rtaumu(B->Xclnu)'),
flavio.sm_prediction('Rtaul(B->Xclnu)'),
delta=0.01)
self.assertEqual(
flavio.physics.bdecays.bxlnu.BR_tot_leptonflavour(wc_obj, par, 'e', 'e'), 1)
self.assertAlmostEqual(
flavio.physics.bdecays.bxlnu.BR_tot_leptonflavour(wc_obj, par, 'tau', 'e'),
1/flavio.physics.bdecays.bxlnu.BR_tot_leptonflavour(wc_obj, par, 'e', 'tau'))
def test_bxll_lratio(self):
# compare to arXiv:1503.04849
self.assertAlmostEqual(flavio.sm_prediction('(B->Xsll)', 1, 3.5),
0.96, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction('(B->Xsll)', 14.4, 25),
1.15, delta=0.01)
# for tau, just check this doesn't raise an error
flavio.sm_prediction('(B->Xsll)', 14.4, 25)
def test_ft(self):
# compare to exp values in table 4 of 1803.08732
wc_obj = flavio.WilsonCoefficients()
Ft = flavio.physics.betadecays.ft.Ft_superallowed(par, wc_obj, '10C')
self.assertAlmostEqual(Ft / s, 3078, delta=2 * 5)
Ft = flavio.physics.betadecays.ft.Ft_superallowed(par, wc_obj, '26mAl')
self.assertAlmostEqual(Ft / s, 3072.9, delta=3 * 1)
Ft = flavio.physics.betadecays.ft.Ft_superallowed(par, wc_obj, '46V')
self.assertAlmostEqual(Ft / s, 3074.1, delta=2 * 2)
Ft = flavio.sm_prediction('Ft(38Ca)')
self.assertAlmostEqual(Ft / s, 3076.4, delta=2 * 7.2)
def test_corrn(self):
# compare to exp values in table 5 of 1803.08732
self.assertAlmostEqual(flavio.sm_prediction('a_n'), -0.1034, delta=2 * 0.0037)
self.assertAlmostEqual(flavio.sm_prediction('atilde_n', me_E=0.695), -0.1090, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction('Atilde_n', me_E=0.569), -0.11869, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction('Btilde_n', me_E=0.591), 0.9805, delta=3 * 0.003)
self.assertAlmostEqual(flavio.sm_prediction('lambdaAB_n', me_E=0.581), -1.2686, delta=0.04)
self.assertEqual(flavio.sm_prediction('D_n'), 0)
self.assertEqual(flavio.sm_prediction('R_n'), 0)
def test_noerror(self):
flavio.sm_prediction('mu_gg(h->Zgamma)')
flavio.sm_prediction('mu_tth(h->tautau)')
flavio.sm_prediction('mu_Wh(h->mumu)')
flavio.sm_prediction('mu_Zh(h->bb)')
flavio.sm_prediction('mu_VBF(h->WW)')
def test_noerror(self):
flavio.sm_prediction('mu_gg(h->Zgamma)')
flavio.sm_prediction('mu_tth(h->tautau)')
flavio.sm_prediction('mu_Wh(h->mumu)')
flavio.sm_prediction('mu_Zh(h->bb)')
flavio.sm_prediction('mu_VBF(h->WW)')
self.assertAlmostEqual(flavio.sm_prediction("P4p(B0->K*mumu)", q2=1)/0.15140284164390483, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P5p(B0->K*mumu)", q2=1)/0.5064923738851054, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("AFB(B0->K*mumu)", q2=6)/0.17920578512694066, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("FL(B0->K*mumu)", q2=6)/0.6746725598733865, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S4(B0->K*mumu)", q2=6)/-0.24476949751293892, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S5(B0->K*mumu)", q2=6)/-0.3735858481345886, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P4p(B0->K*mumu)", q2=6)/-0.529132300413707, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P5p(B0->K*mumu)", q2=6)/-0.807602014278806, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("AFB(B0->K*mumu)", q2=15)/0.406194755197377, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("FL(B0->K*mumu)", q2=15)/0.36807161547568185, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S3(B0->K*mumu)", q2=15)/-0.14872271241628923, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S4(B0->K*mumu)", q2=15)/-0.2919191029733921, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S5(B0->K*mumu)", q2=15)/-0.34293705381921147, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P4p(B0->K*mumu)", q2=15)/-0.6065016593226283, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P5p(B0->K*mumu)", q2=15)/-0.7124983944730857, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("dBR/dq2(B0->K*mumu)", q2=1)/5.7131974656129313e-8, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("dBR/dq2(B0->K*mumu)", q2=6)/5.524478678779278e-8, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("dBR/dq2(B0->K*mumu)", q2=15)/7.412258847550239e-8, 1, delta=delta)
# direct CP asymmetry should be close to 0
self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->K*mumu)", q2=1), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->K*mumu)", q2=6), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->K*mumu)", q2=17), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B+->K*mumu)", q2=1), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B+->K*mumu)", q2=6), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B+->K*mumu)", q2=17), 0, delta=0.01)
# this is just a very rough comparison to the literature
delta = 0.2
self.assertAlmostEqual(flavio.sm_prediction("P1(B0->K*mumu)", q2=3), 0, delta=delta)
delta = 0.1
self.assertAlmostEqual(flavio.sm_prediction("P1(B0->K*mumu)", q2=17), -0.64, delta=delta)
delta = 0.1
self.assertAlmostEqual(flavio.sm_prediction("P2(B0->K*mumu)", q2=6)/(2/3.*0.179/0.325), 1, delta=delta)
def test_sm(self):
self.assertEqual(flavio.sm_prediction('d_Tl'), 0)
self.assertEqual(flavio.sm_prediction('omega_YbF'), 0)
self.assertEqual(flavio.sm_prediction('omega_HfF'), 0)
self.assertEqual(flavio.sm_prediction('omega_ThO'), 0)
def test_compare_to_Davids_old_code(self):
# this actually works to 3% and better! Still, setting it to 15%
# here to not give any error in case of future changes to the central value of the code
delta = 0.15
self.assertAlmostEqual(flavio.sm_prediction("AFB(B0->K*mumu)", q2=1)/-0.15349451759556973, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("FL(B0->K*mumu)", q2=1)/0.6406629242990924, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S5(B0->K*mumu)", q2=1)/0.22071783227496475, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P4p(B0->K*mumu)", q2=1)/0.15140284164390483, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P5p(B0->K*mumu)", q2=1)/0.5064923738851054, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("AFB(B0->K*mumu)", q2=6)/0.17920578512694066, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("FL(B0->K*mumu)", q2=6)/0.6746725598733865, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S4(B0->K*mumu)", q2=6)/-0.24476949751293892, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S5(B0->K*mumu)", q2=6)/-0.3735858481345886, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P4p(B0->K*mumu)", q2=6)/-0.529132300413707, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P5p(B0->K*mumu)", q2=6)/-0.807602014278806, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("AFB(B0->K*mumu)", q2=15)/0.406194755197377, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("FL(B0->K*mumu)", q2=15)/0.36807161547568185, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S3(B0->K*mumu)", q2=15)/-0.14872271241628923, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S4(B0->K*mumu)", q2=15)/-0.2919191029733921, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("S5(B0->K*mumu)", q2=15)/-0.34293705381921147, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P4p(B0->K*mumu)", q2=15)/-0.6065016593226283, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("P5p(B0->K*mumu)", q2=15)/-0.7124983944730857, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("dBR/dq2(B0->K*mumu)", q2=1)/5.7131974656129313e-8, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("dBR/dq2(B0->K*mumu)", q2=6)/5.524478678779278e-8, 1, delta=delta)
self.assertAlmostEqual(flavio.sm_prediction("dBR/dq2(B0->K*mumu)", q2=15)/7.412258847550239e-8, 1, delta=delta)
# direct CP asymmetry should be close to 0
self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->K*mumu)", q2=1), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->K*mumu)", q2=6), 0, delta=0.01)
self.assertAlmostEqual(flavio.sm_prediction("ACP(B0->K*mumu)", q2=17), 0, delta=0.01)
divide all values and uncertainties by the bin width (i.e. dimensionless
integrated BRs will be converted to $q^2$-integrated differential BRs with
dimensions of GeV$^{-2}$). Defaults to False.
- `N` (optional): number of random draws to determine the uncertainty.
Defaults to 50. Larger is slower but more precise. The relative
error of the theory uncertainty scales as $1/\sqrt{2N}$.
Additional keyword arguments are passed to the matplotlib add_patch function,
e.g. 'fc' for face colour.
"""
obs = flavio.classes.Observable[obs_name]
if not obs.arguments or len(obs.arguments) != 2:
raise ValueError(r"Only observables that depend on the two bin boundaries (and nothing else) are allowed")
if wc is None:
wc = flavio.physics.eft._wc_sm # SM Wilson coefficients
obs_dict = {bin_: flavio.sm_prediction(obs_name, *bin_) for bin_ in bin_list}
obs_err_dict = {bin_: flavio.sm_uncertainty(obs_name, *bin_, N=N, threads=threads) for bin_ in bin_list}
else:
obs_dict = {bin_:flavio.np_prediction(obs_name, wc, *bin_) for bin_ in bin_list}
obs_err_dict = {bin_: flavio.np_uncertainty(obs_name, wc, *bin_, N=N, threads=threads) for bin_ in bin_list}
ax = plt.gca()
for _i, (bin_, central_) in enumerate(obs_dict.items()):
xmin, xmax = bin_
err = obs_err_dict[bin_]
if divide_binwidth:
err = err/(xmax-xmin)
central = central_/(xmax-xmin)
else:
central = central_
if 'fc' not in kwargs and 'facecolor' not in kwargs:
kwargs['fc'] = 'C6'
if 'linewidth' not in kwargs and 'lw' not in kwargs: