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_bvll_integrate_pole(self):
def f(q2):
# dummy function with a pole at q2=0
return 1e-10*(1 + 0.1*q2 + 0.01*q2**2)/q2
from flavio.math.integrate import nintegrate
from flavio.physics.bdecays.bvll.observables import nintegrate_pole
self.assertAlmostEqual(nintegrate_pole(f, 0.1, 10)/nintegrate(f, 0.1, 10, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(f, 0.001, 0.01)/nintegrate(f, 0.001, 0.01, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(f, 0.0005, 2)/nintegrate(f, 0.0005, 2, epsrel=0.0001),
1, delta=0.03)
# try whether it also works with a well-behaved function
def g(q2):
return 1e-10*(1 + 0.1*q2 + 0.01*q2**2)
self.assertAlmostEqual(nintegrate_pole(g, 0.1, 10)/nintegrate(g, 0.1, 10, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(g, 0.001, 0.01)/nintegrate(g, 0.001, 0.01, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(g, 0.0005, 2)/nintegrate(g, 0.0005, 2, epsrel=0.001),
1, delta=0.01)
def test_bvll_integrate_pole(self):
def f(q2):
# dummy function with a pole at q2=0
return 1e-10*(1 + 0.1*q2 + 0.01*q2**2)/q2
from flavio.math.integrate import nintegrate
from flavio.physics.bdecays.bvll.observables import nintegrate_pole
self.assertAlmostEqual(nintegrate_pole(f, 0.1, 10)/nintegrate(f, 0.1, 10, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(f, 0.001, 0.01)/nintegrate(f, 0.001, 0.01, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(f, 0.0005, 2)/nintegrate(f, 0.0005, 2, epsrel=0.0001),
1, delta=0.03)
# try whether it also works with a well-behaved function
def g(q2):
return 1e-10*(1 + 0.1*q2 + 0.01*q2**2)
self.assertAlmostEqual(nintegrate_pole(g, 0.1, 10)/nintegrate(g, 0.1, 10, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(g, 0.001, 0.01)/nintegrate(g, 0.001, 0.01, epsrel=0.001),
1, delta=0.01)
self.assertAlmostEqual(nintegrate_pole(g, 0.0005, 2)/nintegrate(g, 0.0005, 2, epsrel=0.001),
1, delta=0.01)
def bpnunu_dbrdq2_int_summed(q2min, q2max, wc_obj, par, B, P):
def obs(q2):
return bpnunu_dbrdq2_summed(q2, wc_obj, par, B, P)
return flavio.math.integrate.nintegrate(obs, q2min, q2max)/(q2max-q2min)
def BR_binned(q2min, q2max, wc_obj, par, B, P, lep):
def integrand(q2):
return dBRdq2(q2, wc_obj, par, B, P, lep)
return flavio.math.integrate.nintegrate(integrand, q2min, q2max)
def bvlilj_obs_int(function, q2min, q2max, wc, par, B, V, l1, l2):
def obs(q2):
return bvlilj_obs(function, q2, wc, par, B, V, l1, l2)
return flavio.math.integrate.nintegrate(obs, q2min, q2max)
def bvnunu_BRtot_summed(wc_obj, par, B, V):
def obs(q2):
return bvnunu_dbrdq2_summed(q2, wc_obj, par, B, V)
mB = par['m_'+B]
mV = par['m_'+V]
q2max = (mB-mV)**2
q2min = 0
return flavio.math.integrate.nintegrate(obs, q2min, q2max)
def BR_binned(q2min, q2max, wc_obj, par, K, P, lep):
def integrand(q2):
return dBRdq2(q2, wc_obj, par, K, P, lep)
return flavio.math.integrate.nintegrate(integrand, q2min, q2max)
def bvnunu_dbrdq2_int_summed(q2min, q2max, wc_obj, par, B, V):
def obs(q2):
return bvnunu_dbrdq2_summed(q2, wc_obj, par, B, V)
return flavio.math.integrate.nintegrate(obs, q2min, q2max)/(q2max-q2min)