Пример #1
0
def process(r0_paths, output_path):
    data = []

    for ipath, r0_path in enumerate(r0_paths):
        print(f"Processing: {ipath+1}/{len(r0_paths)}")
        pedestal_path = r0_path.replace(".tio", "_ped.tcal")

        regex_r0 = re.search(r".+_tc([\d.]+)_tmc([\d.]+).tio", r0_path)
        temperature_r0_chamber = float(regex_r0.group(1))
        temperature_r0_primary = float(regex_r0.group(2))

        regex_ped = re.search(r".+_tc([\d.]+)_tmc([\d.]+)_ped.tcal",
                              pedestal_path)
        temperature_pedestal_chamber = float(regex_ped.group(1))
        temperature_pedestal_primary = float(regex_ped.group(2))

        reader = TIOReader(r0_path, max_events=50000)
        pedestal = PedestalTargetCalib(reader.n_pixels, reader.n_samples,
                                       reader.n_cells)
        pedestal.load_tcal(pedestal_path)

        online_stats = OnlineStats()
        online_hist = OnlineHist(bins=100, range_=(-10, 10))

        # Subtract Pedestals
        desc = "Subtracting pedestal"
        for wfs in tqdm(reader, total=reader.n_events, desc=desc):
            if wfs.missing_packets:
                continue

            subtracted_tc = pedestal.subtract_pedestal(wfs,
                                                       wfs.first_cell_id)[[0]]
            online_stats.add_to_stats(subtracted_tc)
            online_hist.add(subtracted_tc)

        data.append(
            dict(
                temperature_r0_chamber=temperature_r0_chamber,
                temperature_r0_primary=temperature_r0_primary,
                temperature_pedestal_chamber=temperature_pedestal_chamber,
                temperature_pedestal_primary=temperature_pedestal_primary,
                mean=online_stats.mean,
                std=online_stats.std,
                hist=online_hist.hist,
                edges=online_hist.edges,
            ))

    with HDF5Writer(output_path) as writer:
        writer.write(data=pd.DataFrame(data))
def main():
    r0_path = "/Users/Jason/Downloads/tempdata/Pedestal_23deg_r0.tio"
    r1_int_path = "/Users/Jason/Downloads/tempdata/Pedestal_23deg_r1_int.tio"
    r1_rnd_path = "/Users/Jason/Downloads/tempdata/Pedestal_23deg_r1_rnd.tio"
    tcal_path = "/Users/Jason/Downloads/tempdata/Pedestal_23deg_ped.tcal"

    reader_r0 = TIOReader(r0_path, max_events=10000)
    reader_r1_int = TIOReader(r1_int_path, max_events=10000)
    reader_r1_rnd = TIOReader(r1_rnd_path, max_events=10000)

    # Generate Pedestal
    pedestal_tc = PedestalTargetCalib(reader_r0.n_pixels, reader_r0.n_samples,
                                      reader_r0.n_cells)
    pedestal_tc.load_tcal(tcal_path)

    l_int = []
    l_rnd = []

    # Subtract Pedestals
    desc = "Subtracting pedestal"
    z = zip(reader_r0, reader_r1_int, reader_r1_rnd)
    it = tqdm(z, total=reader_r0.n_events, desc=desc)
    for wfs_r0, wfs_r1_int, wfs_r1_rnd in it:
        if wfs_r0.missing_packets:
            continue

        wfs_r1_flt = pedestal_tc.subtract_pedestal(wfs_r0,
                                                   wfs_r0.first_cell_id)

        # offset = 700
        # scale = 13.6
        # wfs_r1_flt = (wfs_r1_flt + offset) * scale
        # wfs_r1_int = (wfs_r1_int + offset) * scale
        # wfs_r1_rnd = (wfs_r1_rnd + offset) * scale

        l_int.append(wfs_r1_flt - wfs_r1_int)
        l_rnd.append(wfs_r1_flt - wfs_r1_rnd)

    l_int = np.array(l_int).ravel()
    l_rnd = np.array(l_rnd).ravel()

    plt.hist(l_int, bins=20, histtype='step', label='int')
    plt.hist(l_rnd, bins=20, histtype='step', label='rnd')
    plt.legend(loc='best')
    plt.xlabel("Difference to float ped-sub ADC")
    plt.ylabel("N")
    plt.show()