Пример #1
0
print(
    'Initialization finished, real time {0:.02f}s, cpu time {1:.02f}s'.format(
        time.time() - global_start,
        time.process_time() - cpu_global_start))
print('Processing {} entries'.format(Total_entries))

with h5py.File(filename, 'r', libver='latest', swmr=True) as ipt:
    l = len(ipt['Readout/Waveform'])
    Mu = ipt['Readout/Waveform'].attrs['mu']
    Tau = ipt['Readout/Waveform'].attrs['tau']
    Sigma = ipt['Readout/Waveform'].attrs['sigma']

N = 10
tic = time.time()
cpu_tic = time.process_time()
spe_pre = wff.read_model(reference[0])
slices = np.append(
    np.arange(0, Total_entries, int(np.ceil(Total_entries / N))),
    Total_entries)
ranges = list(zip(slices[0:-1], slices[1:]))
with Pool(min(N, cpu_count())) as pool:
    Waveforms_and_info = pd.concat(pool.starmap(Read_Data, ranges))
print('Data Loaded, consuming {0:.02f}s using {1} threads, cpu time {2:.02f}s'.
      format(time.time() - tic, N,
             time.process_time() - cpu_tic))

channelid_set = set(Waveforms_and_info['ChannelID'])
Channel_Grouped_Waveform = Waveforms_and_info.groupby(by='ChannelID')

# Loading CNN Net
tic = time.time()
Пример #2
0
                                'full')[:leng] / np.sum(spe_pre[cid]['spe'])
            wave1 = wave1 / np.sum(spe_pre[cid]['spe'])
            dt[extradist][c] = np.sum(wl) - np.sum(pwe0)
            dt[pecount][c] = len(pet0)


#         dt['wdist'][c] = scipy.stats.wasserstein_distance(pet0, pet_sub, u_weights=pwe0, v_weights=wl)
        dt['wdist'][c] = scipy.stats.wasserstein_distance(
            pet0[pwe0 > 0], pet_sub, u_weights=pwe0[pwe0 > 0], v_weights=wl)
        dt['EventID'][c] = df_wav[i_wav[i]]['EventID']
        dt['ChannelID'][c] = cid
        dt['RSS_truth'][c] = np.power(wave0 - wave, 2).sum()
        dt['RSS_recon'][c] = np.power(wave1 - wave, 2).sum()
    return dt

spe_pre = wff.read_model(args.ref[1])
with h5py.File(fref, 'r', libver='latest',
               swmr=True) as ref, h5py.File(fipt,
                                            'r',
                                            libver='latest',
                                            swmr=True) as ipt:
    df_ans = ref['GroundTruth'][:]
    df_wav = ref['Waveform'][:]
    df_sub = ipt['Answer'][:]
    method = ipt['Answer'].attrs['Method']
df_ans = np.sort(df_ans, kind='stable', order=['EventID', 'ChannelID'])
df_sub = np.sort(df_sub, kind='stable', order=['EventID', 'ChannelID'])
df_wav = np.sort(df_wav, kind='stable', order=['EventID', 'ChannelID'])
Chnum = len(np.unique(df_ans['ChannelID']))
e_ans = df_ans['EventID'] * Chnum + df_ans['ChannelID']
e_ans, i_ans = np.unique(e_ans, return_index=True)
Пример #3
0
                                              mode='charge',
                                              is_delta=is_delta)
    return A, wave, tlist, t0_init, t0_init_delta, npe_init, left_wave, right_wave


psr = argparse.ArgumentParser()
psr.add_argument("-o", dest="opt", type=str, help="output file")
psr.add_argument("ipt", type=str, help="input file")
psr.add_argument("--ref", type=str, help="reference file")
args = psr.parse_args()

fipt = args.ipt
fopt = args.opt
reference = args.ref

spe_pre = read_model(reference, 1)
with h5.File(fipt, "r", libver="latest", swmr=True) as ipt:
    ent = ipt["Readout/Waveform"][:]
    window = len(ent[0]["Waveform"])
    assert window >= len(
        spe_pre[0]["spe"]), "Single PE too long which is {}".format(
            len(spe_pre[0]["spe"]))
    Mu = ipt["Readout/Waveform"].attrs["mu"].item()
    Tau = ipt["Readout/Waveform"].attrs["tau"].item()
    Sigma = ipt["Readout/Waveform"].attrs["sigma"].item()
    gmu = ipt["SimTriggerInfo/PEList"].attrs["gmu"].item()
    gsigma = ipt["SimTriggerInfo/PEList"].attrs["gsigma"].item()

p = spe_pre[0]["parameters"]
std = 1.0
mix0sigma = 1e-3
Пример #4
0
basename = "electron-6"

baseline_file = "{}.baseline.root".format(basename)
with uproot.open(baseline_file) as ped:
    pedestal = ak.to_numpy(
        ak.flatten(ped["SimpleAnalysis"]["ChannelInfo.Pedestal"].array())
    )
    pedcid = ak.to_numpy(
        ak.flatten(ped["SimpleAnalysis"]["ChannelInfo.ChannelId"].array())
    )


spe_file = "{}.spe.h5".format(basename)

spe_pre = wff.read_model(spe_file)

fipt = "{}.h5".format(basename)
ipt = h5.File(fipt, "r")
ent = ipt["Readout/Waveform"]
ent = ent[ent["ChannelID"] < 30]
print("{} waveforms will be computed".format(len(ent)))
assert np.all(pedcid == ent["ChannelID"]), "Files do not match!"
leng = len(ent[0]["Waveform"])
assert leng >= len(spe_pre[0]["spe"]), "Single PE too long which is {}".format(
    len(spe_pre[0]["spe"])
)

waveforms = ent["Waveform"]
ent = pd.DataFrame(
    data={
Пример #5
0
psr.add_argument('--ref', type=str, nargs='+', help='reference file')
args = psr.parse_args()

global_start = time.time()
cpu_global_start = time.process_time()

def start_time(a0, a1):
    stime = np.empty(a1 - a0)
    for i in range(a0, a1):
        hitt = photoelectron[i_cha[i]:i_cha[i+1]]['HitPosInWindow'].astype(np.float64)
        char = photoelectron[i_cha[i]:i_cha[i+1]]['Charge']
        t0, _ = wff.likelihoodt0(hitt, char=char, gmu=gmu, Tau=Tau, Sigma=Sigma, mode='charge')
        stime[i - a0] = t0
    return stime

spe_pre = wff.read_model(args.ref[1], wff.nshannon)
p = spe_pre[0]['parameters']
with h5py.File(args.ipt, 'r', libver='latest', swmr=True) as ipt, h5py.File(args.ref[0], 'r', libver='latest', swmr=True) as ref:
    gmu = ref['SimTriggerInfo/PEList'].attrs['gmu']
    gsigma = ref['SimTriggerInfo/PEList'].attrs['gsigma']
    s0 = spe_pre[0]['std'] / np.linalg.norm(spe_pre[0]['spe'])
    method = ipt['photoelectron'].attrs['Method']
    Mu = ipt['photoelectron'].attrs['mu']
    Tau = ipt['photoelectron'].attrs['tau']
    Sigma = ipt['photoelectron'].attrs['sigma']
    photoelectron = ipt['photoelectron'][:]
    window = len(ref['Readout/Waveform'][:][0]['Waveform'][::wff.nshannon])
    n = 1 if min(photoelectron['HitPosInWindow'] % 1) == 0 else min(photoelectron['HitPosInWindow'] % 1)
    tlist_pan = np.sort(np.unique(np.hstack(np.arange(0, window)[:, None] + np.arange(0, 1, 1 / n))))
    Chnum = len(np.unique(photoelectron['ChannelID']))
    photoelectron = np.sort(photoelectron, kind='stable', order=['TriggerNo', 'ChannelID', 'HitPosInWindow'])