diff --git a/raremodel-tf.py b/raremodel-tf.py index 2d368cb..4dc5bcf 100644 --- a/raremodel-tf.py +++ b/raremodel-tf.py @@ -60,7 +60,7 @@ for i in range(N): _sum += b0[i]*(tf.pow(z,i)) - return prefactor * _sum + return tf.complex(prefactor * _sum, ztf.constant(0.0)) #calculate f+ or fT @@ -76,7 +76,7 @@ for i in range(N): _sum += b[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) - return prefactor * _sum + return tf.complex(prefactor * _sum, ztf.constant(0.0)) def resonance(q, _mass, width, phase, scale): @@ -109,29 +109,19 @@ x = tf.cos(phase)*r y = tf.sin(phase)*r - com = tf.complex(x, y) + com = tf.complex(scale* x, scale * y) return com def bifur_gauss(q, mean, sigma_L, sigma_R, scale): - x_left = tf.where(q < mean, q, False) - - x_right = tf.where(q >= mean, q, False) - - #Calculate the exponential part of the cusp - - _exp_left = ztf.exp(- tf.pow((x_left-mean),2) / (2 * sigma_L**2)) - _exp_right = ztf.exp(- tf.pow((x_right-mean),2) / (2 * sigma_R**2)) - + _exp = tf.where(q < mean, ztf.exp(- tf.pow((q-mean),2) / (2 * sigma_L**2)), ztf.exp(- tf.pow((q-mean),2) / (2 * sigma_R**2))) #Scale so the total area under curve is 1 and the top of the cusp is continuous - _exp = _exp_left + _exp_right - dgamma = scale*_exp/(ztf.sqrt(2*np.pi))*2*(sigma_L*sigma_R)/(sigma_L+sigma_R) - com = ztf.complex(dgamma, 0) + com = ztf.complex(dgamma, ztf.constant(0.0)) return com @@ -149,7 +139,7 @@ mK = ztf.constant(pdg['Ks_M']) mB = ztf.constant(pdg['Bplus_M']) - q2 = tf.pow(x, 2) + q2 = tf.pow(q, 2) #Some helperfunctions @@ -163,7 +153,7 @@ #left term in bracket - bracket_left = 2./3. * kabs**2. * beta**2. *tf.abs(C10eff*formfactor(q2, "+"))**2. + bracket_left = 2./3. * kabs**2. * beta**2. *tf.abs(tf.complex(C10eff, ztf.constant(0.0))*formfactor(q2, "+"))**2. #middle term in bracket @@ -171,7 +161,7 @@ _under = q2 * mB**2. - bracket_middle = _top/_under *tf.pow(tf.abs(C10eff * formfactor(q2, "0")), 2) + bracket_middle = _top/_under *tf.pow(tf.abs(tf.complex(C10eff, ztf.constant(0.0)) * formfactor(q2, "0")), 2) #Note sqrt(q2) comes from derivation as we use q2 and plot q @@ -179,9 +169,9 @@ def vec(q, scale_vec, funcs): - scale = self.params['scale'] + scale = scale_vec - q2 = tf.pow(x, 2) + q2 = tf.pow(q, 2) GF = ztf.constant(pdg['GF']) alpha_ew = ztf.constant(pdg['alpha_ew']) @@ -209,7 +199,7 @@ prefactor2 = kabs**2 * (1. - 1./3. * beta**2) - abs_bracket = tf.abs(c9eff(x, funcs) * formfactor(q2, "+") + 2 * C7eff * (mb + ms)/(mB + mK) * formfactor(q2, "T"))**2 + abs_bracket = tf.abs(c9eff(q, funcs) * formfactor(q2, "+") + tf.complex(2.0 * C7eff * (mb + ms)/(mB + mK), ztf.constant(0.0)) * formfactor(q2, "T"))**2 bracket_right = prefactor2 * abs_bracket @@ -219,12 +209,11 @@ def c9eff(q, funcs): - C9eff_nr = ztf.constant(pdg['C9eff']) + C9eff_nr = tf.complex(ztf.constant(pdg['C9eff']), ztf.constant(0.0)) c9 = C9eff_nr - for func in funcs: - c9 += func(q) + c9 = c9 + funcs return c9 @@ -247,11 +236,11 @@ def cusp(q): return bifur_gauss(q, mean = self.params['cusp_mass'], sigma_L = self.params['sigma_L'], sigma_R = self.params['sigma_R'], scale = self.params['cusp_scale']) - funcs = [jpsi_res(x), psi2s_res(x), cusp(x)] + funcs = jpsi_res(x) + psi2s_res(x) + cusp(x) vec_f = vec(x, self.params['scale_vec'], funcs) - axiv_nr = axiv(x, self.params['scale_axiv']) + axiv_nr = axiv_nonres(x, self.params['scale_axiv']) tot = vec_f + axiv_nr @@ -318,6 +307,7 @@ nll = zfit.loss.UnbinnedNLL(model=total_f, data=data, fit_range = (x_min, x_max)) minimizer = zfit.minimize.MinuitMinimizer() +minimizer._use_tfgrad = False result = minimizer.minimize(nll) param_errors = result.error()