def get_amp(self, data, data_c=None, **kwargs): m = data["m"] mass1 = self.mass1() mass2 = self.mass2() width1 = self.width1() width2 = self.width2() q = data_c["|q|"] mdaughter1 = kwargs["all_data"]["particle"][self.decay[0].outs[0]]["m"] mdaughter2 = kwargs["all_data"]["particle"][self.decay[0].outs[1]]["m"] q1 = get_relative_p(mass1, mdaughter1, mdaughter2) q2 = get_relative_p(mass2, mdaughter1, mdaughter2) mlist = tf.stack([mass1, mass2]) wlist = tf.stack([width1, width2]) qlist = tf.stack([q1, q2]) Klist = [] for mi, wi, qi in zip(mlist, wlist, qlist): rw = Gamma(m, wi, q, qi, self.bw_l, mi, self.d) Klist.append(mi * rw / (mi**2 - m**2)) KK = tf.reduce_sum(Klist, axis=0) KK += self.alpha() beta_term = self.get_beta( m=m, mlist=mlist, wlist=wlist, q=q, qlist=qlist, Klist=Klist, **kwargs, ) MM = tf.complex(np.float64(1), -KK) MM = beta_term / MM return MM + self.KNR()
def spline_x_matrix(x, xi): """build matrix of x for spline interpolation""" ones = tf.ones_like(x) x2 = x * x x3 = x2 * x x_p = tf.stack([ones, x, x2, x3], axis=-1) x = tf.expand_dims(x, axis=-1) zeros = tf.zeros_like(x) def poly_i(i): cut = (x >= xi[i]) & (x < xi[i + 1]) return tf.where(cut, x_p, zeros) xs = [poly_i(i) for i in range(len(xi) - 1)] return tf.stack(xs, axis=-2)
def get_matrix_interp1d3_v2(x, xi): N = len(xi) - 1 zeros = tf.zeros_like(x) ones = tf.ones_like(x) # @pysnooper.snoop() def poly_i(i): tmp = zeros x_i = (xi[i] + xi[i - 1]) / 2 for j in range(i - 1, i + 3): if j < 0 or j > N - 1: continue r = ones for k in range(j - 1, j + 3): if k == i or k < 1 or k > N: continue x_k = (xi[k] + xi[k - 1]) / 2 r = r * (x - x_k) / (x_i - x_k) r = tf.where( (x >= (xi[j] + xi[j - 1]) / 2) & (x < (xi[j] + xi[j + 1]) / 2), r, zeros, ) tmp = tmp + r return tmp h = tf.stack([poly_i(i) for i in range(1, N)], axis=-1) b = tf.zeros_like(x) return h, b
def interp(self, m): # q = data_extra[self.outs[0]]["|q|"] # a = self.a() p = self.point_value() zeros = tf.zeros_like(m) ones = tf.ones_like(m) def poly_i(i, xi): tmp = zeros for j in range(i - 1, i + 1): if j < 0 or j > self.interp_N - 1: continue r = ones for k in range(j, j + 2): if k == i: continue r = r * (m - xi[k]) / (xi[i] - xi[k]) r = tf.where((m >= xi[j]) & (m < xi[j + 1]), r, zeros) tmp = tmp + r return tmp h = tf.stack( [poly_i(i, self.points) for i in range(1, self.interp_N - 1)], axis=-1, ) h = tf.stop_gradient(h) p_r = tf.math.real(p) p_i = tf.math.imag(p) ret_r = tf.reduce_sum(h * p_r, axis=-1) ret_i = tf.reduce_sum(h * p_i, axis=-1) return tf.complex(ret_r, ret_i)
def get_helicity_amp(self, data, data_p, **kwargs): q0 = self.get_relative_momentum(data_p, False) data["|q0|"] = q0 if "|q|" in data: q = data["|q|"] else: q = self.get_relative_momentum(data_p, True) data["|q|"] = q bf = barrier_factor([min(self.get_l_list())], q, q0, self.d) H = tf.stack(self.H()) bf = tf.cast(tf.reshape(bf, (-1, 1, 1)), H.dtype) return H * bf
def get_helicity_amp(self, data, data_p, **kwargs): n_b = len(self.outs[0].spins) n_c = len(self.outs[1].spins) H_part = tf.stack(self.H()) if self.part_H == 0: H = tf.concat( [H_part, self.parity_term * H_part[(n_b - 2) // 2::-1]], axis=0, ) else: H = tf.concat( [H_part, self.parity_term * H_part[:, (n_c - 2) // 2::-1]], axis=1, ) return H
def interp(self, m): zeros = tf.zeros_like(m) p = self.point_value() xs = [] def poly_i(i): x = 1.0 for j in range(self.interp_N): if i == j: continue x = (x * (m - self.points[j]) / (self.points[i] - self.points[j])) return x xs = tf.stack([poly_i(i) for i in range(self.interp_N)], axis=-1) zeros = tf.zeros_like(xs) xs = tf.complex(xs, zeros) ret = tf.reduce_sum(xs[:, 1:-1] * p, axis=-1) return ret
def get_matrix_interp1d3(x, xi): N = len(xi) - 1 zeros = tf.zeros_like(x) ones = tf.ones_like(x) # @pysnooper.snoop() def poly_i(i): tmp = zeros for j in range(i - 1, i + 3): if j < 0 or j > N - 1: continue r = ones for k in range(j - 1, j + 3): if k == i or k < 0 or k > N: continue r = r * (x - xi[k]) / (xi[i] - xi[k]) r = tf.where((x >= xi[j]) & (x < xi[j + 1]), r, zeros) tmp = tmp + r return tmp h = tf.stack([poly_i(i) for i in range(1, N)], axis=-1) b = tf.zeros_like(x) return h, b
def interp(self, m): p = self.point_value() ones = tf.ones_like(m) zeros = tf.zeros_like(m) def add_f(x, bl, br): return tf.where((x > bl) & (x <= br), ones, zeros) x_bin = tf.stack( [ add_f( m, (self.points[i] + self.points[i + 1]) / 2, (self.points[i + 1] + self.points[i + 2]) / 2, ) for i in range(self.interp_N - 2) ], axis=-1, ) p_r = tf.math.real(p) p_i = tf.math.imag(p) x_bin = tf.stop_gradient(x_bin) ret_r = tf.reduce_sum(x_bin * p_r, axis=-1) ret_i = tf.reduce_sum(x_bin * p_i, axis=-1) return tf.complex(ret_r, ret_i)
def interp(self, m): p = self.point_value() ret = interp1d3(m, self.points, tf.stack(p)) return ret
def get_helicity_amp(self, data, data_p, **kwargs): return tf.stack(self.H())