コード例 #1
0
def main():
    sigma = 0.005
    r_name = "R_BC"

    config = ConfigLoader("config.yml")
    sample_N = config.resolution_size

    decays = config.get_decay(False)
    decay_chain = decays.get_decay_chain(r_name)
    data = config.get_data("data_origin")[0]
    phsp = config.get_data("phsp_plot")[0]

    dat_order = config.get_dat_order()

    generate = lambda x: gauss_random(x, decay_chain, r_name, sigma, sample_N,
                                      dat_order)

    pi = generate(data)
    np.savetxt("data/data.dat", pi)
    np.savetxt("data/data_weight.dat",
               np.ones((pi.shape[0] // len(dat_order), )))

    pi = generate(phsp)
    np.save("data/phsp_re.npy", pi)
    np.savetxt("data/phsp_re_weight.dat",
               np.ones((pi.shape[0] // len(dat_order), )))
コード例 #2
0
def generate_toy_from_phspMC(Ndata, mc_file, data_file):
    """Generate toy using PhaseSpace MC from mc_file"""
    config = ConfigLoader(f"{this_dir}/config_toy.yml")
    config.set_params(f"{this_dir}/gen_params.json")
    amp = config.get_amplitude()
    data = gen_data(
        amp,
        Ndata=Ndata,
        mcfile=mc_file,
        genfile=data_file,
        particles=config.get_dat_order(),
    )
    return data
コード例 #3
0
ファイル: gauss_sample.py プロジェクト: ReynLieu/tf-pwa
def main():
    sigma = 0.005
    sigma_delta = 5
    r_name = "R_BC"

    config = ConfigLoader("config.yml")

    sample_N = config.resolution_size

    decays = config.get_decay(False)
    decay_chain = decays.get_decay_chain(r_name)
    data = config.get_data("data_origin")[0]
    pi, total_weights = gauss_sample(data, decay_chain, "R_BC", sigma,
                                     sample_N, config.get_dat_order())
    np.savetxt("data/data.dat", pi.reshape((-1, 4)))
    np.savetxt("data/data_weight.dat", np.reshape(total_weights, (-1, )))

    data = config.get_data("phsp_plot")[0]
    pi, total_weights = gauss_sample(data, decay_chain, "R_BC", sigma,
                                     sample_N, config.get_dat_order())
    np.save("data/phsp_re.npy", pi.reshape((-1, 4)))
    np.savetxt("data/phsp_re_weight.dat", np.reshape(total_weights, (-1, )))
コード例 #4
0
ファイル: gen_toy.py プロジェクト: ReynLieu/tf-pwa
def generate_toy_from_phspMC(Ndata, mc_file, data_file):
    """Generate toy using PhaseSpace MC from mc_file"""
    # We use ConfigLoader to read the information in the configuration file
    config = ConfigLoader("config.yml")
    # Set the parameters in the amplitude model
    config.set_params("gen_params.json")
    amp = config.get_amplitude()
    # data is saved in data_file
    data = gen_data(
        amp,
        Ndata=Ndata,
        mcfile=mc_file,  # input phsase space file
        genfile=data_file,  # saved toy data file
        # use the order in config, the default is ascii order.
        particles=config.get_dat_order(),
    )
    return data
コード例 #5
0
ファイル: gauss_random.py プロジェクト: zhixing1996/tf-pwa
def main():
    sigma = 0.005
    r_name = "DstD"

    config = ConfigLoader("config_data.yml")

    decays = config.get_decay(False)
    decay_chain = decays.get_decay_chain(r_name)
    data = config.get_data("data")[0]
    angle = cal_helicity_angle(data["particle"],
                               decay_chain.standard_topology())
    decay_chain.standard_topology()
    tp_map = decay_chain.topology_map()

    r_particle = tp_map[get_particle(r_name)]

    mass = {}
    for i in data["particle"]:
        mi = data["particle"][i]["m"]
        if i == r_particle:
            mi = mi + tf.random.normal(mi.shape, 0, sigma, dtype=mi.dtype)
        mass[i] = mi

    mask = True
    p4_all = {}
    for i in decay_chain:
        phi = angle[tp_map[i]][tp_map[i.outs[0]]]["ang"]["alpha"]
        theta = angle[tp_map[i]][tp_map[i.outs[0]]]["ang"]["beta"]

        m0 = mass[tp_map[i.core]]
        m1 = mass[tp_map[i.outs[0]]]
        m2 = mass[tp_map[i.outs[1]]]

        mask = mask & (m0 >= m1 + m2)

        p_square = get_relative_p2(m0, m1, m2)

        p = tf.sqrt(tf.where(p_square > 0, p_square, 0))
        pz = p * tf.cos(theta)
        px = p * tf.sin(theta) * tf.cos(phi)
        py = p * tf.sin(theta) * tf.sin(phi)
        E1 = tf.sqrt(m1 * m1 + p * p)
        E2 = tf.sqrt(m2 * m2 + p * p)
        p1 = tf.stack([E1, px, py, pz], axis=-1)
        p2 = tf.stack([E2, -px, -py, -pz], axis=-1)
        p4_all[i.outs[0]] = p1
        p4_all[i.outs[1]] = p2

    core_boost = {}
    for i in decay_chain:
        if i.core != decay_chain.top:
            core_boost[i.outs[0]] = i.core
            core_boost[i.outs[1]] = i.core
    ret = {}
    for i in decay_chain.outs:
        tmp = i
        ret[i] = p4_all[i]
        while tmp in core_boost:
            tmp = core_boost[tmp]
            # print(i, tmp)
            ret[i] = lv.rest_vector(lv.neg(p4_all[tmp]), ret[i])

    ret2 = {}
    mask = tf.expand_dims(mask, -1)
    for i in ret:
        ret2[i] = tf.where(mask, ret[i], data["particle"][tp_map[i]]["p"])
    # print(ret)
    # print({i: data["particle"][tp_map[i]]["p"] for i in decay_chain.outs})

    pi = np.stack([ret2[i] for i in config.get_dat_order()], axis=1)
    np.savetxt("data_gauss.dat", pi.reshape((-1, 4)))