Beispiel #1
0
def q2_plot_th_bin(obs_name, bin_list, wc=None, divide_binwidth=False, N=50, **kwargs):
    r"""Plot the binned theory prediction with uncertainties of a
    $q^2$-dependent observable as a function of $q^2$  (in the form of coloured
    boxes)."""
    obs = flavio.classes.Observable.get_instance(obs_name)
    if obs.arguments != ['q2min', 'q2max']:
        raise ValueError(r"Only observables that depend on q2min and q2max (and nothing else) are allowed")
    if wc is None:
        wc = flavio.WilsonCoefficients() # 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) for bin_ in bin_list}
    else:
        wc = flavio.WilsonCoefficients() # SM Wilson coefficients
        obs_dict = {bin_:flavio.np_prediction(obs_name, wc, *bin_) for bin_ in bin_list}
    ax = plt.gca()
    for bin_, central_ in obs_dict.items():
        q2min, q2max = bin_
        err = obs_err_dict[bin_]
        if divide_binwidth:
            err = err/(q2max-q2min)
            central = central_/(q2max-q2min)
        else:
            central = central_
        if 'fc' not in kwargs and 'facecolor' not in kwargs:
            kwargs['fc'] = flavio.plots.colors.pastel[3]
        if 'linewidth' not in kwargs and 'lw' not in kwargs:
            kwargs['lw'] = 0
        ax.add_patch(patches.Rectangle((q2min, central-err), q2max-q2min, 2*err,**kwargs))
Beispiel #2
0
 def obstable_sm(self):
     self._check_sm_cov_loaded()
     if self._obstable_sm is None:
         info = tree()  # nested dict
         for flh_name, flh in self.fast_likelihoods.items():
             # loop over fast likelihoods: they only have a single "measurement"
             m = flh.pseudo_measurement
             ml = flh.full_measurement_likelihood
             pred_sm = ml.get_predictions_par(self.par_dict_sm,
                                              flavio.WilsonCoefficients())
             sm_cov = flh.sm_covariance.get(force=False)
             _, exp_cov = flh.exp_covariance.get(force=False)
             inspire_dict = self._get_inspire_dict(flh.observables, ml)
             for i, obs in enumerate(flh.observables):
                 info[obs]['lh_name'] = flh_name
                 info[obs]['name'] = obs if isinstance(obs, str) else obs[0]
                 info[obs]['th. unc.'] = np.sqrt(sm_cov[i, i])
                 info[obs]['experiment'] = m.get_central(obs)
                 info[obs]['exp. unc.'] = np.sqrt(exp_cov[i, i])
                 info[obs]['exp. PDF'] = NormalDistribution(
                     m.get_central(obs), np.sqrt(exp_cov[i, i]))
                 info[obs]['inspire'] = sorted(set(inspire_dict[obs]))
                 info[obs]['ll_sm'] = m.get_logprobability_single(
                     obs, pred_sm[obs])
                 info[obs]['ll_central'] = m.get_logprobability_single(
                     obs, m.get_central(obs))
         for lh_name, lh in self.likelihoods.items():
             # loop over "normal" likelihoods
             ml = lh.measurement_likelihood
             pred_sm = ml.get_predictions_par(self.par_dict_sm,
                                              flavio.WilsonCoefficients())
             inspire_dict = self._get_inspire_dict(lh.observables, ml)
             for i, obs in enumerate(lh.observables):
                 obs_dict = flavio.Observable.argument_format(obs, 'dict')
                 obs_name = obs_dict.pop('name')
                 with warnings.catch_warnings():
                     warnings.simplefilter("ignore")
                     p_comb = flavio.combine_measurements(
                         obs_name,
                         include_measurements=ml.get_measurements,
                         **obs_dict)
                 info[obs]['experiment'] = p_comb.central_value
                 info[obs]['exp. unc.'] = max(p_comb.error_left,
                                              p_comb.error_right)
                 info[obs]['exp. PDF'] = p_comb
                 info[obs]['inspire'] = sorted(set(inspire_dict[obs]))
                 info[obs]['th. unc.'] = 0
                 info[obs]['lh_name'] = lh_name
                 info[obs]['name'] = obs if isinstance(obs, str) else obs[0]
                 info[obs]['ll_sm'] = p_comb.logpdf([pred_sm[obs]])
                 if info[obs]['ll_sm'] == -np.inf:
                     info[obs]['ll_sm'] = -1e100
                 info[obs]['ll_central'] = p_comb.logpdf(
                     [p_comb.central_value])
         self._obstable_sm = info
     return self._obstable_sm
Beispiel #3
0
 def test_kpilnu_nu(self):
     wc_sm = flavio.WilsonCoefficients()
     wc_np_mu = flavio.WilsonCoefficients()
     wc_np_mu.set_initial({'CVL_sumunumu': 1}, 4.8)
     wc_np_e = flavio.WilsonCoefficients()
     wc_np_e.set_initial({'CVL_sumunue': 1}, 4.8)
     obs = flavio.Observable["BR(K+->pimunu)"]
     br_sm = obs.prediction_central(constraints, wc_sm)
     br_mu = obs.prediction_central(constraints, wc_np_mu)
     br_e = obs.prediction_central(constraints, wc_np_e)
     # with interference: (1 + 1)^2 = 4
     self.assertAlmostEqual(br_mu / br_sm, 4, delta=0.06)
     # without interference: 1 + 1 = 2
     self.assertAlmostEqual(br_e / br_sm, 2, delta=0.03)
Beispiel #4
0
 def test_bvlnu_nu(self):
     wc_sm = flavio.WilsonCoefficients()
     wc_np_tau = flavio.WilsonCoefficients()
     wc_np_tau.set_initial({'CVL_butaunutau': 1}, 4.8)
     wc_np_e = flavio.WilsonCoefficients()
     wc_np_e.set_initial({'CVL_butaunue': 1}, 4.8)
     obs = flavio.Observable["BR(B+->rhotaunu)"]
     br_sm = obs.prediction_central(constraints, wc_sm)
     br_tau = obs.prediction_central(constraints, wc_np_tau)
     br_e = obs.prediction_central(constraints, wc_np_e)
     # with interference: (1 + 1)^2 = 4
     self.assertAlmostEqual(br_tau / br_sm, 4, delta=0.04)
     # without interference: 1 + 1 = 2
     self.assertAlmostEqual(br_e / br_sm, 2, delta=0.02)
 def test_dplnu_nu(self):
     wc_sm = flavio.WilsonCoefficients()
     wc_np_mu = flavio.WilsonCoefficients()
     wc_np_mu.set_initial({'CVL_dcmunumu': 1}, 2)
     wc_np_e = flavio.WilsonCoefficients()
     wc_np_e.set_initial({'CVL_dcmunue': 1}, 2)
     obs = flavio.Observable["BR(D+->pimunu)"]
     constraints = flavio.default_parameters
     br_sm = obs.prediction_central(constraints, wc_sm)
     br_mu = obs.prediction_central(constraints, wc_np_mu)
     br_e = obs.prediction_central(constraints, wc_np_e)
     # with interference: (1 + 1)^2 = 4
     self.assertAlmostEqual(br_mu / br_sm, 4, delta=0.04)
     # without interference: 1 + 1 = 2
     self.assertAlmostEqual(br_e / br_sm, 2, delta=0.02)
Beispiel #6
0
    def test_bxll(self):
        # check whether QED corrections have the right behaviour
        wc_obj = flavio.WilsonCoefficients()
        par = flavio.default_parameters.get_central_all()
        br_1_noqedpc =  _bxll_dbrdq2(1, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_1_qed =  _bxll_dbrdq2(1, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        br_6_noqedpc =  _bxll_dbrdq2(6, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_6_qed =  _bxll_dbrdq2(6, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        br_15_noqedpc =  _bxll_dbrdq2(15, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_15_qed =  _bxll_dbrdq2(15, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        br_21_noqedpc =  _bxll_dbrdq2(21, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_21_qed =  _bxll_dbrdq2(21, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        self.assertAlmostEqual((br_1_qed+br_6_qed)/(br_1_noqedpc+br_6_noqedpc),
                                1.02, delta=0.01) # should lead to a 2% enhancement
        self.assertAlmostEqual((br_15_qed+br_21_qed)/(br_15_noqedpc+br_21_noqedpc),
                                0.92, delta=0.03) # should lead to a 8% suppression


        # compare SM predictions to arXiv:1503.04849
        # to convert to the parameters used there
        xi_t = flavio.physics.ckm.xi('t','bs')(par)
        Vcb = flavio.physics.ckm.get_ckm(par)[1,2]
        r = abs(xi_t)**2/Vcb**2/0.9621*0.574/par['C_BXlnu']*par['BR(B->Xcenu)_exp']/0.1051
        self.assertAlmostEqual(1e6*flavio.sm_prediction('<BR>(B->Xsmumu)', 1, 3.5)/r,
                               0.888, delta=0.02)
        self.assertAlmostEqual(1e6*flavio.sm_prediction('<BR>(B->Xsmumu)', 3.5, 6)/r,
                               0.731, delta=0.01)
        self.assertAlmostEqual(1e7*flavio.sm_prediction('<BR>(B->Xsmumu)', 14.4, 25)/r,
                               2.53, delta=0.6) # larger difference due to Krüger-Sehgal
        self.assertAlmostEqual(1e6*flavio.sm_prediction('<BR>(B->Xsee)', 1, 3.5)/r,
                               0.926, delta=0.04)
        self.assertAlmostEqual(1e6*flavio.sm_prediction('<BR>(B->Xsee)', 3.5, 6)/r,
                               0.744, delta=0.015)
        self.assertAlmostEqual(1e7*flavio.sm_prediction('<BR>(B->Xsee)', 14.4, 25)/r,
                               2.20, delta=0.6) # larger difference due to Krüger-Sehgal
Beispiel #7
0
def _setInitVal(dictParams, pred, lepton, _q2min, _q2max):
    channel = "B0->K*ee"
    if (lepton): channel = "B0->K*mumu"

    for key, par in dictParams.items():
        if (pred == 'NP'):
            wc = flavio.WilsonCoefficients()
            if (key == 'AT2'):
                par.set_value(
                    flavio.np_prediction('<P1>(' + channel + ')',
                                         wc,
                                         q2min=float(_q2min),
                                         q2max=float(_q2max)))
            else:
                par.set_value(
                    flavio.np_prediction('<' + key + '>(' + channel + ')',
                                         wc,
                                         q2min=float(_q2min),
                                         q2max=float(_q2max)))
        else:
            if (key == 'AT2'):
                par.set_value(
                    flavio.sm_prediction('<P1>(' + channel + ')',
                                         q2min=float(_q2min),
                                         q2max=float(_q2max)))
            else:
                par.set_value(
                    flavio.sm_prediction('<' + key + '>(' + channel + ')',
                                         q2min=float(_q2min),
                                         q2max=float(_q2max)))
Beispiel #8
0
 def test_bxclnu_np(self):
     wc_np = flavio.WilsonCoefficients()
     wc_np.set_initial({'CVp_bcenu': 0.1}, scale=4.6)
     br_sm = flavio.physics.bdecays.bxlnu.BR_BXclnu(par, wc_obj, 'e')
     br_np = flavio.physics.bdecays.bxlnu.BR_BXclnu(par, wc_np, 'e')
     # compare to the unnumbered eq. between (13) and (14) in 1407.1320
     self.assertAlmostEqual(br_np/br_sm, (1-0.34*0.1)**2, delta=0.1)
Beispiel #9
0
    def _get_covariance_sm(self, N=100):
        par_central = self.par_obj.get_central_all()

        def random_nuisance_dict():
            arr = self.get_random_nuisance_parameters
            nuis_dict = {
                par: arr[i]
                for i, par in enumerate(self.nuisance_parameters)
            }
            par = par_central.copy()
            par.update(nuis_dict)
            return par

        par_random = [random_nuisance_dict() for i in range(N)]

        pred_arr = np.zeros((len(self.observables), N))
        wc_sm = flavio.WilsonCoefficients()
        for i, observable in enumerate(self.observables):
            if isinstance(observable, tuple):
                obs_name = observable[0]
                _inst = flavio.classes.Observable.get_instance(obs_name)
                pred_arr[i] = np.array([
                    _inst.prediction_par(par, wc_sm, *observable[1:])
                    for par in par_random
                ])
            else:
                _inst = flavio.classes.Observable.get_instance(observable)
                pred_arr[i] = np.array(
                    [_inst.prediction_par(par, wc_sm) for par in par_random])
        return np.cov(pred_arr)
Beispiel #10
0
 def test_running(self):
     c_in = np.array([
         0.20910694, 0.77740198, 0.54696337, 0.46407456, 0.42482153,
         0.95717777, 0.62733321, 0.87053086
     ])
     wc = flavio.WilsonCoefficients()
     wc_names = [
         'C{}_bsbs'.format(i)
         for i in ['VLL', 'SLL', 'TLL', 'VRR', 'SRR', 'TRR', 'VLR', 'SLR']
     ]
     wc_dict = dict(zip(wc_names, c_in))
     wc.set_initial(wc_dict, 173.3)
     c_out_dict = wc.get_wc('sbsb', 4.2, par)
     c_out = np.array([c_out_dict[k] for k in wc_names])
     c_out_U = np.dot(U_mb, c_in)
     for i, r in enumerate(c_out / c_out_U):
         if 'S' in wc_names[i] or 'T' in wc_names[i]:
             self.assertAlmostEqual(r,
                                    1,
                                    delta=0.2,
                                    msg="Failed for {}".format(wc_names[i]))
         else:  # more precise
             self.assertAlmostEqual(r,
                                    1,
                                    delta=0.1,
                                    msg="Failed for {}".format(wc_names[i]))
     # compare eta at 2 GeV to the values in table 2 of hep-ph/0102316
     par_bju = par.copy()
     par_bju['alpha_s'] = 0.118
     par_bju['m_b'] = 4.4
     c_out_bju_dict = wc.get_wc('sbsb', 2, par_bju, nf_out=5)
     c_out_bju = np.array([c_out_bju_dict[k] for k in wc_names])
     self.assertAlmostEqual(c_out_bju[0] / c_in[0], 0.788, delta=0.02)
Beispiel #11
0
 def get_wc_obj(self, x):
     wc_obj = flavio.WilsonCoefficients()
     # if there are no WCs to be fitted, return the SM WCs
     if not self.fit_wc_names:
         return wc_obj
     d = self.array_to_dict(x)
     wc_obj.set_initial(self.fit_wc_function(**d['fit_wc']),
                        self.input_scale)
     return wc_obj
Beispiel #12
0
 def test_q2_th_diff(self):
     # without specifying WCs
     q2_plot_th_diff('dBR/dq2(B0->pienu)', 0, 25, q2steps=10)
     # with WCs
     q2_plot_th_diff('dBR/dq2(B+->pienu)', 0, 25,
                                wc=flavio.WilsonCoefficients(), q2steps=10)
     # check that observable not depending on q2 raises error
     with self.assertRaises(ValueError):
         q2_plot_th_diff('eps_K', 0, 25)
 def test_np(self):
     wc = flavio.WilsonCoefficients()
     for l in ['e', 'mu', 'tau']:
         wc.set_initial({'CSL_bc' + l + 'nu' + l: 1}, 4.8)
         self.assertTrue(par['tau_Bc_SM'] / flavio.np_prediction('tau_Bc', wc) > 1.1)
         self.assertAlmostEqual(par['tau_Bc_SM'] / flavio.np_prediction('tau_Bc', wc),
                                1 + flavio.np_prediction('BR(Bc->' + l + 'nu)', wc)
                                - flavio.sm_prediction('BR(Bc->' + l + 'nu)'),
                                delta=0.05,
                                msg="Failed for {}".format(l))
Beispiel #14
0
 def test_q2_th_bin(self):
     bins = [(0, 5), (5, 10)]
     # without specifying WCs
     q2_plot_th_bin('<BR>(B0->pienu)', bins, N=10)
     # with WCs
     q2_plot_th_bin('<BR>(B+->pienu)', bins, divide_binwidth=True,
                                       wc=flavio.WilsonCoefficients(), N=10)
     # check that observable not depending on q2 raises error
     with self.assertRaises(ValueError):
         q2_plot_th_bin('eps_K', bins)
Beispiel #15
0
    def test_bs_timedep(self):
        q2 = 3
        wc_obj = flavio.WilsonCoefficients()
        par = flavio.default_parameters.get_central_all()
        B = 'Bs'
        V = 'phi'
        l = 'mu'
        # a set of parameters with y_s=0!
        par_y0 = par.copy()
        par_y0['DeltaGamma/Gamma_Bs']=0

        # compare without lifetime effect: must be equal!
        self.assertEqual(
            observables.bvll_obs(     observables.dGdq2_ave,       q2, wc_obj, par_y0, B, V, l),
            observables_bs.bsvll_obs( observables_bs.dGdq2_ave_Bs, q2, wc_obj, par_y0, B, V, l))
        self.assertEqual(
            observables.bvll_obs(     observables.FL,       q2, wc_obj, par_y0, B, V, l),
            observables_bs.bsvll_obs( observables_bs.FL_Bs, q2, wc_obj, par_y0, B, V, l))
        for i in [3, 4, 7]: # S3,4,7
            self.assertEqual(
                observables.bvll_obs(     lambda J, J_bar:         observables.S_experiment(J, J_bar, i),               q2, wc_obj, par_y0, B, V, l),
                observables_bs.bsvll_obs( lambda y, J, J_bar, J_h: observables_bs.S_experiment_Bs(y, J, J_bar, J_h, i), q2, wc_obj, par_y0, B, V, l))

        # check that the phase phi has the right convention
        q_over_p = flavio.physics.mesonmixing.observables.q_over_p(wc_obj, par, B)
        phi = cmath.phase(-q_over_p) # the phase of q/p
        self.assertAlmostEqual(phi, 0.04, delta=0.01)

        # compare WITH lifetime effect: angular observables must be similar
        delta = 0.01
        self.assertAlmostEqual(
            observables.bvll_obs(     observables.FL,       q2, wc_obj, par, B, V, l)/
            observables_bs.bsvll_obs( observables_bs.FL_Bs, q2, wc_obj, par, B, V, l),
            1, delta=delta)
        for i in [4, 7]: # S4,7
            self.assertAlmostEqual(
                observables.bvll_obs(     lambda J, J_bar:         observables.S_experiment(J, J_bar, i),               q2, wc_obj, par, B, V, l)/
                observables_bs.bsvll_obs( lambda y, J, J_bar, J_h: observables_bs.S_experiment_Bs(y, J, J_bar, J_h, i), q2, wc_obj, par, B, V, l),
                1, delta=delta)
        for i in [3]: # S3: look at differnece only
            self.assertAlmostEqual(
                observables.bvll_obs(     lambda J, J_bar:         observables.S_experiment(J, J_bar, i),               q2, wc_obj, par, B, V, l) -
                observables_bs.bsvll_obs( lambda y, J, J_bar, J_h: observables_bs.S_experiment_Bs(y, J, J_bar, J_h, i), q2, wc_obj, par, B, V, l),
                0, delta=0.01)
        # compare WITH lifetime effect: BR suppressed by ~6%!
        self.assertAlmostEqual(
            observables.bvll_obs(     observables.dGdq2_ave,       q2, wc_obj, par, B, V, l)/
            observables_bs.bsvll_obs( observables_bs.dGdq2_ave_Bs, q2, wc_obj, par, B, V, l),
            1.06, delta=0.02)

        # and now just check a few observables to see if any errors are raised
        flavio.sm_prediction("FL(Bs->phimumu)", q2=1)
        flavio.sm_prediction("S3(Bs->phimumu)", q2=1)
        flavio.sm_prediction("S4(Bs->phimumu)", q2=1)
        flavio.sm_prediction("S7(Bs->phimumu)", q2=1)
Beispiel #16
0
 def test_wceff(self):
     wc_obj = flavio.WilsonCoefficients()
     wceff = flavio.physics.betadecays.common.wc_eff(par,
                                                     wc_obj,
                                                     scale=1,
                                                     nu='e')
     self.assertAlmostEqual(wceff['V'], 1, delta=0.05)
     self.assertAlmostEqual(wceff['A'], -1.27, delta=0.05)
     self.assertEqual(wceff['S'], 0)
     self.assertEqual(wceff['P'], 0)
     self.assertEqual(wceff['T'], 0)
     wc_obj = flavio.WilsonCoefficients()
     wc_obj.set_initial({'CVL_duenue': 1}, 1, 'WET-3', 'flavio')
     wceff = flavio.physics.betadecays.common.wc_eff(par,
                                                     wc_obj,
                                                     scale=1,
                                                     nu='e')
     self.assertAlmostEqual(wceff['V'], 2, delta=0.05)
     self.assertAlmostEqual(wceff['A'], -1.27 * 2, delta=0.05)
     self.assertEqual(wceff['S'], 0)
     self.assertEqual(wceff['P'], 0)
     self.assertEqual(wceff['T'], 0)
     wc_obj.set_initial({'CVR_duenue': 1}, 1, 'WET-3', 'flavio')
     wceff = flavio.physics.betadecays.common.wc_eff(par,
                                                     wc_obj,
                                                     scale=1,
                                                     nu='e')
     self.assertAlmostEqual(wceff['V'], 2, delta=0.05)
     self.assertAlmostEqual(wceff['A'], 0, delta=0.05)
     self.assertEqual(wceff['S'], 0)
     self.assertEqual(wceff['P'], 0)
     self.assertEqual(wceff['T'], 0)
     wc_obj.set_initial({'CT_duenue': 1}, 1, 'WET-3', 'flavio')
     wceff = flavio.physics.betadecays.common.wc_eff(par,
                                                     wc_obj,
                                                     scale=1,
                                                     nu='e')
     self.assertAlmostEqual(wceff['V'], 1, delta=0.05)
     self.assertAlmostEqual(wceff['A'], -1.27, delta=0.05)
     self.assertEqual(wceff['S'], 0)
     self.assertEqual(wceff['P'], 0)
     self.assertAlmostEqual(wceff['T'], 4 * 1, delta=0.1)
Beispiel #17
0
 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)
Beispiel #18
0
 def test_bsll_lfv(self):
     # test for errors
     self.assertEqual(flavio.sm_prediction('BR(B0->emu)'), 0)
     self.assertEqual(flavio.sm_prediction('BR(Bs->taumu)'), 0)
     self.assertEqual(flavio.sm_prediction('BR(B0->emu,mue)'), 0)
     self.assertEqual(flavio.sm_prediction('BR(Bs->mutau,taumu)'), 0)
     wc = flavio.WilsonCoefficients()
     wc.set_initial({'C10_bdemu': 1, 'C10_bdmue': 2}, scale=4.8)
     self.assertEqual(flavio.np_prediction('BR(B0->mue)', wc)
                     /flavio.np_prediction('BR(B0->emu)', wc), 4)
     self.assertEqual(flavio.np_prediction('BR(B0->emu,mue)', wc)
                     /flavio.np_prediction('BR(B0->emu)', wc), 5)
Beispiel #19
0
 def test_dmixing(self):
     par_D = par.copy()
     wc_obj = flavio.WilsonCoefficients()
     par_D['M12_D a_bb'] = 0
     par_D['M12_D a_bs'] = 10
     par_D['M12_D a_ss'] = -0.1
     par_D['Gamma12_D a_bb'] = 0
     par_D['Gamma12_D a_bs'] = 10
     par_D['Gamma12_D a_ss'] = -0.3
     x12 = flavio.Observable['x12_D'].prediction_par(par_D, wc_obj)
     x12Im = flavio.Observable['x12Im_D'].prediction_par(par_D, wc_obj)
     phi12 = flavio.Observable['phi12_D'].prediction_par(par_D, wc_obj)
     self.assertAlmostEqual(x12 * sin(phi12), x12Im)
Beispiel #20
0
 def test_nedm_jms_CEDM(self):
     wc = wcxf.WC('WET', 'JMS', 160, {'dG_11': {'Im': 1e-10}})
     wcf = flavio.WilsonCoefficients()
     wcf.set_initial_wcxf(wc)
     wcd = wcf.get_wc('dF=0', scale=2, par=par, eft='WET-3', basis='flavio')
     self.assertAlmostEqual(wcd['C8_dd'] / 1j, 0.07, delta=0.02)
     par_dG = par.copy()
     par_dG['nEDM gT_d'] = 0
     par_dG['nEDM beta_G'] = 0
     par_dG['nEDM gT_u'] = 0
     par_dG['nEDM ~rho_u'] = 0
     p = flavio.Observable['d_n'].prediction_par(par_dG, wcf)
     self.assertAlmostEqual(p, 2e-10, delta=0.3e-10)
Beispiel #21
0
 def np_predictions_nockm(self, w=None, **ckm):
     """Return the predictions for the four input observables in the presence
     of NP (parametrized by a `wilson.Wilson` instance `w`) with the
     CKM prefactor removed."""
     fac = self.ckm_fac(**ckm)
     par_dict = self.par_central.copy()
     par_dict.update(ckm)
     if w is None:
         w = flavio.WilsonCoefficients()
     return [
         flavio.classes.Observable[obs].prediction_par(par_dict, w) / fac[i]
         for i, obs in enumerate(self.observables)
     ]
Beispiel #22
0
def sm_error_budget(obs_name, *args, N=50, **kwargs):
    """Get the *relative* uncertainty of the Standard Model prediction due to
    variation of individual observables.

    Parameters
    ----------

    - `obs_name`: name of the observable as a string
    - `N` (optional): number of random evaluations of the observable.
    The relative accuracy of the uncertainties returned is given by $1/\sqrt{2N}$.

    Additional arguments are passed to the observable and are necessary,
    depending on the observable (e.g. $q^2$-dependent observables).
    """
    obs = flavio.classes.Observable.get_instance(obs_name)
    wc_sm = flavio.WilsonCoefficients()
    par_central = flavio.default_parameters.get_central_all()
    par_random = [flavio.default_parameters.get_random_all() for i in range(N)]

    # Step 1: determine the parameters the observable depends on at all.
    # to this end, compute the observables once for each parameter with a
    # random value for this parameter but central values for all other
    # parameters. If the prediction is equal to the central prediction, the
    # observable does not depend on the parameter!
    pred_central = obs.prediction_par(par_central, wc_sm, *args, **kwargs)
    dependent_par = []
    for k in par_central.keys():
        par_tmp = par_central.copy()
        par_tmp[k] = par_random[0][k]
        pred_tmp = obs.prediction_par(par_tmp, wc_sm, *args, **kwargs)
        if pred_tmp != pred_central:
            dependent_par.append(k)

    # Step 2: for each of the dependent parameters, determine the error
    # analogous to the sm_uncertainty function. Normalize to the central
    # prediction (so relative errors are returned)
    individual_errors = {}

    def make_par_random(key, par_random):
        par_tmp = par_central.copy()
        par_tmp[key] = par_random[key]
        return par_tmp

    for p in dependent_par:
        par_random_p = [make_par_random(p, pr) for pr in par_random]
        all_pred = np.array([
            obs.prediction_par(par, wc_sm, *args, **kwargs)
            for par in par_random_p
        ])
        individual_errors[p] = np.std(all_pred) / abs(pred_central)
    return individual_errors
 def test_nedm_jms_G(self):
     wc = wcxf.WC('WET', 'JMS', 160, {'Gtilde': 1e-6})
     wcf = flavio.WilsonCoefficients()
     wcf.set_initial_wcxf(wc)
     wcd = wcf.get_wc('dF=0', scale=2, par=par, eft='WET-3', basis='flavio')
     self.assertEqual(wcd['CG'], 0)
     self.assertAlmostEqual(wcd['CGtilde'], 0.007, delta=0.001)
     par_G = par.copy()
     par_G['nEDM gT_d'] = 0
     par_G['nEDM ~rho_d'] = 0
     par_G['nEDM gT_u'] = 0
     par_G['nEDM ~rho_u'] = 0
     p = flavio.Observable['d_n'].prediction_par(par_G, wcf)
     self.assertAlmostEqual(p, 4.5e-9, delta=1e-9)
def tau_Bc(wc_obj, par):
    r"""Lifetime of the $B_c$ meson based on the SM OPE estimate plus
    the NP contribution to leptonic decays."""
    Gamma_SM = 1 / par['tau_Bc_SM']
    Gamma_exp = 1 / par['tau_Bc']
    Gamma_NP = 0
    wc_sm = flavio.WilsonCoefficients()
    for l in ['e', 'mu', 'tau']:
        _br_SM = flavio.Observable['BR(Bc->{}nu)'.format(l)].prediction_par(
            par, wc_sm)
        _br_NP = flavio.Observable['BR(Bc->{}nu)'.format(l)].prediction_par(
            par, wc_obj)
        Gamma_NP += (_br_NP - _br_SM) * Gamma_exp
    return 1 / (Gamma_SM + Gamma_NP)
Beispiel #25
0
def sm_covariance(obs_list, N=100, par_vary='all', **kwargs):
    """Get the covariance matrix of the Standard Model predictions for a
    list of observables.

    Parameters
    ----------

    - `obs_list`: a list of observables that should be given either as a string
    name (for observables that do not depend on any arguments) or as a tuple
    of a string and values for the arguements the observable depends on (e.g.
    the values of `q2min` and `q2max` for a binned observable)
    - `N` (optional): number of random evaluations of the observables.
    The relative accuracy of the uncertainties returned is given by $1/\sqrt{2N}$.
    - `par_vary`: a list of parameters to vary. Defaults to 'all', i.e. all
    parameters are varied according to their probability distributions.
    """
    wc_sm = flavio.WilsonCoefficients()
    par_central_all = flavio.default_parameters.get_central_all()
    par_random_all = [
        flavio.default_parameters.get_random_all() for i in range(N)
    ]

    def par_random_some(par_random, par_central):
        # take the central values for the parameters not to be varied
        par1 = {k: v for k, v in par_central.items() if k not in par_vary}
        # take the random values for the parameters to be varied
        par2 = {k: v for k, v in par_random.items() if k in par_vary}
        par1.update(par2)  # merge them
        return par1

    if par_vary == 'all':
        par_random = par_random_all
    else:
        par_random = [
            par_random_some(par_random_all[i], par_central_all)
            for i in range(N)
        ]

    def get_prediction(obs, par):
        if isinstance(obs, str):
            obs_obj = flavio.classes.Observable.get_instance(obs)
            return obs_obj.prediction_par(par, wc_sm, **kwargs)
        elif isinstance(obs, tuple):
            obs_obj = flavio.classes.Observable.get_instance(obs[0])
            return obs_obj.prediction_par(par, wc_sm, *obs[1:], **kwargs)

    all_pred = np.array([[get_prediction(obs, par) for par in par_random]
                         for obs in obs_list])
    return np.cov(all_pred)
Beispiel #26
0
 def testkpinunu(self):
     self.assertAlmostEqual(
         flavio.sm_prediction('BR(K+->pinunu)')/1e-10,
         1, delta=0.2)
     self.assertAlmostEqual(
         flavio.sm_prediction('BR(KL->pinunu)')/3e-11,
         1, delta=0.2)
     obs = flavio.classes.Observable['BR(K+->pinunu)']
     wc_sm = flavio.WilsonCoefficients()
     # confirm that deltaPcu leads to an enhancement of the K+->pinunu BR
     # by 6% as stated in the abstract of hep-ph/0503107
     self.assertAlmostEqual(
         obs.prediction_central(constraints, wc_sm)/obs.prediction_central(constraints_no_deltaPcu, wc_sm),
         1.06,
         delta=0.01)
Beispiel #27
0
def sm_prediction(obs_name, *args, **kwargs):
    """Get the central value of the Standard Model prediction of an observable.

    Parameters
    ----------

    - `obs_name`: name of the observable as a string

    Additional arguments are passed to the observable and are necessary,
    depending on the observable (e.g. $q^2$-dependent observables).
    """
    obs = flavio.classes.Observable.get_instance(obs_name)
    wc_sm = flavio.WilsonCoefficients()
    return obs.prediction_central(flavio.default_parameters, wc_sm, *args,
                                  **kwargs)
Beispiel #28
0
        def BR(c10, c10p, cS, cSp, cP, cPp):
            list_wc = {'C10_bsmumu' :  c10,
                 'C10p_bsmumu': c10p,
                 'CS_bsmumu'  : cS,
                 'CSp_bsmumu' : cSp,
                 'CP_bsmumu'  : cP,
                 'CPp_bsmumu' : cPp,
                 'C9_bsmumu'  : 0.,
                 'C9p_bsmumu' : 0.}
            wc = flavio.WilsonCoefficients()
            wc.set_initial(list_wc, scale=160 )

            BR_flavio    = flavio.np_prediction('BR(Bs->mumu)', wc)
            BR_Amsterdam = BR_Amsterdam_Bs_mumu(par, list_wc)

            return {'flavio': BR_flavio, 'Amsterdam': BR_Amsterdam}
Beispiel #29
0
def q2_plot_th_diff(obs_name, q2min, q2max, wc=None, q2steps=100, **kwargs):
    r"""Plot the central theory prediction of a $q^2$-dependent observable
    as a function of $q^2$."""
    obs = flavio.classes.Observable.get_instance(obs_name)
    if obs.arguments != ['q2']:
        raise ValueError(r"Only observables that depend on $q^2$ (and nothing else) are allowed")
    q2_arr = np.arange(q2min, q2max, (q2max-q2min)/(q2steps-1))
    if wc is None:
        wc = flavio.WilsonCoefficients() # SM Wilson coefficients
        obs_arr = [flavio.sm_prediction(obs_name, q2) for q2 in q2_arr]
    else:
        obs_arr = [flavio.np_prediction(obs_name, wc, q2) for q2 in q2_arr]
    ax = plt.gca()
    if 'c' not in kwargs and 'color' not in kwargs:
        kwargs['c'] = 'k'
    ax.plot(q2_arr, obs_arr, **kwargs)
Beispiel #30
0
 def test_dmixing(self):
     par_D = par.copy()
     wc_obj = flavio.WilsonCoefficients()
     # check correct limiting cases for vanishing mixing
     par_D['M12_D a_bb'] = 0
     par_D['M12_D a_bs'] = 0
     par_D['M12_D a_ss'] = 0
     par_D['Gamma12_D a_bb'] = 0
     par_D['Gamma12_D a_bs'] = 0
     par_D['Gamma12_D a_ss'] = 0
     self.assertEqual(
         flavio.Observable['x_D'].prediction_par(par_D, wc_obj), 0)
     self.assertEqual(
         flavio.Observable['y_D'].prediction_par(par_D, wc_obj), 0)
     self.assertEqual(
         flavio.Observable['phi_D'].prediction_par(par_D, wc_obj), 0)
     self.assertEqual(
         flavio.Observable['q/p_D'].prediction_par(par_D, wc_obj), 1)