def loop_e_t2(): global energy global amp global energy1 global amp1 global waveloop global para_0 # plt.ion() # plt.figure(1) f = open("energy_1030c3_1.txt", "a") k = 0 while k < 100000: if len(waveloop) > 0: if para_0['SEQ'] == 'ON': for i in range(0, para_0['SEQ_N']): # c1 t1 = tools.Wavetools(waveloop[0]['c1'][0][i], waveloop[0]['c1'][1][i]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 # t2 = tools.Wavetools(waveloop[0]['c2'][0][i], waveloop[0]['c2'][1][i]) # e_2 = t2.get_energy(0.2) # amp_2 = t2.get_amplitude() energy.append(e_1) amp.append(amp_1) # energy1.append(e_2) # amp1.append(amp_2) f.write(str(e_1) + ' ' + str(amp_1) + '\n') k = k + 1 if k % 200 == 0: print(k) # plt.clf() # plt.hist(energy, 100, range=(0, 15)) # plt.pause(0.001) waveloop.pop(0) # for m in range(0, len(energy)): # f.write(str(energy[m]) + ' ' + str(amp[m]) + ' ' + str(energy1[m]) + ' ' + str(amp1[m]) + '\n') # f.write(str(energy[m]) + ' ' + str(amp[m]) + '\n') print(len(energy))
amp = [] energy = [] for i in range(0, 10000): time_1 = [] volt_1 = [] filename1 = "ch4/before/C3--200mV-ch4b--" m = str(i) filename2 = '.txt' filename = filename1 + m.zfill(5) + filename2 k = 0 with open(filename) as file1_object: for lines in file1_object: if k < 5: k = k + 1 else: line = lines.rstrip().split(',') time_1.append(1000000000 * float(line[0])) volt_1.append(-1 * float(line[1])) file1_object.close() t1 = tools.Wavetools(time_1, volt_1, basenum=9000) amp_1 = t1.get_amplitude() e1 = t1.get_energy_2(2) amp.append(amp_1) energy.append(e1) if i % 100 == 0: print(i) f = open("ch4/amp_b.txt", "a") for m in range(0, len(amp)): f.write(str(amp[m]) + ' ' + str(energy[m]) + '\n') f.close() print(len(amp))
def loop_lifetime_test(self): self.c_num_1 = 0 t_01 = time.time() while self.dos_0.isOpen(): c_num_2 = 0 waveform0 = self.dos_0.get_wave() if operator.eq(self.wave1, waveform0['c1'][1]) == False: if self.para_0['SEQ'] == 'ON': for i in range(0, self.para_0['SEQ_N']): # c1 t1 = tools.Wavetools(waveform0['c1'][0][i], waveform0['c1'][1][i]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 t2 = tools.Wavetools(waveform0['c2'][0][i], waveform0['c2'][1][i]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.c_num_1 = self.c_num_1 + 1 if e_1 > self.lt_start_l and e_1 < self.lt_start_r \ and e_2 > self.lt_stop_l and e_2 < self.lt_stop_r : # t_start = t1.get_time_cfd_poln(self.start_fraction, 4, 0.4) # t_stop = t2.get_time_cfd_poln(self.stop_fraction, 4, 0.4) t_start = t1.get_time_cfd_linear( self.start_fraction) t_stop = t2.get_time_cfd_linear(self.stop_fraction) self.lifetime.append(t_stop - t_start) #print(t_stop - t_start) c_num_2 = c_num_2 + 1 self.total_counts = self.total_counts + 1 else: # c1 t1 = tools.Wavetools(waveform0['c1'][0], waveform0['c1'][1]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 t2 = tools.Wavetools(waveform0['c2'][0], waveform0['c2'][1]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.c_num_1 = self.c_num_1 + 1 if e_1 > self.lt_start_l and e_1 < self.lt_start_r and e_2 > self.lt_stop_l \ and e_2 < self.lt_stop_r: # t_start = t1.get_time_cfd_poln(self.start_fraction, 4, 0.4) # t_stop = t2.get_time_cfd_poln(self.stop_fraction, 4, 0.4) t_start = t1.get_time_cfd_linear(self.start_fraction) t_stop = t2.get_time_cfd_linear(self.stop_fraction) self.lifetime.append(t_stop - t_start) c_num_2 = c_num_2 + 1 self.total_counts = self.total_counts + 1 if self.c_num_1 % 500 == 0: self.drawHistF_lt.clf() self.a_lt = self.drawHistF_lt.add_subplot(111) self.h_lifetime = self.a_lt.hist(self.lifetime, self.lt_bins, range=(self.lt_l, self.lt_r)) self.a_lt.semilogy() self.drawHistCanvas_lt.draw() t_02 = time.time() self.cps = c_num_2 / (t_02 - t_01) self.lt_cps_text.SetValue(str(int(self.cps))) self.lt_counts_text.SetValue(str(self.total_counts)) t_01 = time.time() self.wave1 = waveform0['c1'][1] if self.total_counts > self.counts_set: break
def loop_energy_test(self): self.c_num = 0 while self.dos_0.isOpen(): waveform0 = self.dos_0.get_wave() if operator.eq(self.wave0, waveform0['c1'][1]) == False: if self.para_0['SEQ'] == 'ON': for i in range(0, self.para_0['SEQ_N']): #c1 t1 = tools.Wavetools(waveform0['c1'][0][i], waveform0['c1'][1][i], 800) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() self.energy_c1.append(e_1) self.amp_c1.append(amp_1) #c2 t2 = tools.Wavetools(waveform0['c2'][0][i], waveform0['c2'][1][i], 800) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.energy_c2.append(e_2) self.amp_c2.append(amp_2) self.c_num = self.c_num + 1 else: #c1 t1 = tools.Wavetools(waveform0['c1'][0], waveform0['c1'][1]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() self.energy_c1.append(e_1) self.amp_c1.append(amp_1) #c2 t2 = tools.Wavetools(waveform0['c2'][0][i], waveform0['c2'][1][i]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.energy_c2.append(e_2) self.amp_c2.append(amp_2) self.c_num = self.c_num + 1 if self.c_num % 100 == 0: self.drawHistF.clf() #c1 self.a = self.drawHistF.add_subplot(221) self.h_energy_c1 = self.a.hist(self.energy_c1, 150, range=(self.e_rg['c1'][0], self.e_rg['c1'][1])) #self.a.set_xlabel('energy') self.b = self.drawHistF.add_subplot(222) self.h_amp_c1 = self.b.hist(self.amp_c1, 150, range=(self.e_rg['c1_amp'][0], self.e_rg['c1_amp'][1])) #self.b.set_xlabel('amp') #c2 self.a_c2 = self.drawHistF.add_subplot(223) self.h_energy_c2 = self.a_c2.hist( self.energy_c2, 150, range=(self.e_rg['c2'][0], self.e_rg['c2'][1])) self.a_c2.set_xlabel('energy') self.b_c2 = self.drawHistF.add_subplot(224) self.h_amp_c2 = self.b_c2.hist( self.amp_c2, 150, range=(self.e_rg['c2_amp'][0], self.e_rg['c2_amp'][1])) self.b_c2.set_xlabel('amp') #self.a.semilogy() self.drawHistCanvas.draw() self.wave0 = waveform0['c1'][1]
# = h1[0].tolist() filename1 = 'C2--C1C2_1200M--00000.csv' k = 0 time_1 = [] volt_1 = [] with open(filename1) as file1_object: for lines in file1_object: if k < 5: k = k + 1 else: line = lines.rstrip().split(',') time_1.append(1000000000 * float(line[0])) volt_1.append(float(line[1])) # print(time_1) tr1 = tl1.Wavetools(time_1, volt_1, basenum=9000) print(tr1.find_baseline()) t_0 = time.time() # for i in range(0, 100): # # tr1.get_time_cfd_linear(0.2) # tr1.get_time_cfd_poln(0.2, 3, 0.4) # # print(tr1.get_time_cfd_linear(0.2)) # # print(tr1.get_time_cfd_poln(0.2, 4, 0.4)) t_1 = time.time() print('time') print(t_1 - t_0) print(tr1.get_slope()) t_0 = time.time() # f = interpolate.interp1d(time_1, volt_1, kind='quadratic') f2 = interpolate.PchipInterpolator(time_1, volt_1) xnew = np.linspace(time_1[0], time_1[-1], 5*(len(time_1) - 1) + 1)
def loop_lt_t2(self): self.c_num_1 = 0 t_05 = time.time() t_01 = time.time() while self.dos_0.isOpen(): c_num_2 = 0 if len(self.waveloop) > 0: if self.para_0['SEQ'] == 'ON': for i in range(0, self.para_0['SEQ_N']): if self.intplo_switch == 1: f1 = interpolate.interp1d(self.waveloop[0]['c1'][0][i], self.waveloop[0]['c1'][1][i], kind='cubic') wave_01 = np.linspace(self.waveloop[0]['c1'][0][i][0], self.waveloop[0]['c1'][0][i][-1], 5 * (len(self.waveloop[0]['c1'][0][i]) - 1) + 1) wave_02 = f1(wave_01) self.waveloop[0]['c1'][0][i] = wave_01.tolist() self.waveloop[0]['c1'][1][i] = wave_02.tolist() f2 = interpolate.interp1d(self.waveloop[0]['c2'][0][i], self.waveloop[0]['c2'][1][i], kind='cubic') wave_03 = np.linspace(self.waveloop[0]['c2'][0][i][0], self.waveloop[0]['c2'][0][i][-1], 5 * (len(self.waveloop[0]['c2'][0][i]) - 1) + 1) wave_04 = f2(wave_03) self.waveloop[0]['c2'][0][i] = wave_03.tolist() self.waveloop[0]['c2'][1][i] = wave_04.tolist() # f1 = interpolate.PchipInterpolator(self.waveloop[0]['c1'][0][i], # self.waveloop[0]['c1'][1][i]) # wave_01 = np.linspace(self.waveloop[0]['c1'][0][i][0], self.waveloop[0]['c1'][0][i][-1], # 5 * (len(self.waveloop[0]['c1'][0][i]) - 1) + 1) # wave_02 = f1(wave_01) # self.waveloop[0]['c1'][0][i] = wave_01.tolist() # self.waveloop[0]['c1'][1][i] = wave_02.tolist() # f2 = interpolate.PchipInterpolator(self.waveloop[0]['c2'][0][i], # self.waveloop[0]['c2'][1][i]) # wave_03 = np.linspace(self.waveloop[0]['c2'][0][i][0], self.waveloop[0]['c2'][0][i][-1], # 5 * (len(self.waveloop[0]['c2'][0][i]) - 1) + 1) # wave_04 = f2(wave_03) # self.waveloop[0]['c2'][0][i] = wave_03.tolist() # self.waveloop[0]['c2'][1][i] = wave_04.tolist() # c1 t1 = tools.Wavetools(self.waveloop[0]['c1'][0][i], self.waveloop[0]['c1'][1][i]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 t2 = tools.Wavetools(self.waveloop[0]['c2'][0][i], self.waveloop[0]['c2'][1][i]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.c_num_1 = self.c_num_1 + 1 if e_1 > self.lt_start_l and e_1 < self.lt_start_r \ and e_2 > self.lt_stop_l and e_2 < self.lt_stop_r : # t_start = t1.get_time_cfd_poln(self.start_fraction, 4, 0.6) # t_stop = t2.get_time_cfd_poln(self.stop_fraction, 4, 0.6) # t_start = t1.get_time_cfd_gaus(self.start_fraction, 0.6) # t_stop = t2.get_time_cfd_gaus(self.stop_fraction, 0.6) # t_start = t1.get_time_cfd_linear(self.start_fraction) # t_stop = t2.get_time_cfd_linear(self.start_fraction) t_start = t1.get_time_cfd_interpolation(self.start_fraction) t_stop = t2.get_time_cfd_interpolation(self.start_fraction) t_start_l = t1.get_time_cfd_linear(self.start_fraction) t_stop_l = t2.get_time_cfd_linear(self.stop_fraction) self.lifetime.append(t_stop - t_start) self.lifetime_linear.append(t_stop_l - t_start_l) self.start_energy.append(e_1) self.stop_energy.append(e_2) c_num_2 = c_num_2 + 1 self.total_counts = self.total_counts + 1 if e_1 > self.lt_sp_start_l and e_1 < self.lt_sp_start_r and e_2 > self.lt_sp_stop_l \ and e_2 < self.lt_sp_stop_r: self.lifetime_sp.append(t_stop - t_start) else: if self.intplo_switch == 1: f1 = interpolate.interp1d(self.waveloop[0]['c1'][0][i], self.waveloop[0]['c1'][1][i], kind='quadratic') wave_01 = np.linspace(self.waveloop[0]['c1'][0][i][0], self.waveloop[0]['c1'][0][i][-1], 5 * (len(self.waveloop[0]['c1'][0][i]) - 1) + 1) wave_02 = f1(wave_01) self.waveloop[0]['c1'][0][i] = wave_01 self.waveloop[0]['c1'][1][i] = wave_02 # c1 t1 = tools.Wavetools(self.waveloop[0]['c1'][0], self.waveloop[0]['c1'][1]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 t2 = tools.Wavetools(self.waveloop[0]['c2'][0], self.waveloop[0]['c2'][1]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.c_num_1 = self.c_num_1 + 1 if e_1 > self.lt_start_l and e_1 < self.lt_start_r and e_2 > self.lt_stop_l \ and e_2 < self.lt_stop_r: t_start = t1.get_time_cfd_poln(self.start_fraction, 4, 0.6) t_stop = t2.get_time_cfd_poln(self.stop_fraction, 4, 0.6) # t_start = t1.get_time_cfd_linear(self.start_fraction) # t_stop = t2.get_time_cfd_linear(self.start_fraction) # t_start = t1.get_time_cfd_interpolation(self.start_fraction) # t_stop = t2.get_time_cfd_interpolation(self.start_fraction) t_start_l = t1.get_time_cfd_linear(self.start_fraction) t_stop_l = t2.get_time_cfd_linear(self.stop_fraction) self.lifetime.append(t_stop - t_start) self.lifetime_linear.append(t_stop_l - t_start_l) self.start_energy.append(e_1) self.stop_energy.append(e_2) c_num_2 = c_num_2 + 1 self.total_counts = self.total_counts + 1 if e_1 > self.lt_sp_start_l and e_1 < self.lt_sp_start_r and e_2 > self.lt_sp_stop_l \ and e_2 < self.lt_sp_stop_r: self.lifetime_sp.append(t_stop - t_start) if self.c_num_1 % 500 == 0: self.drawHistF_lt.clf() self.a_lt = self.drawHistF_lt.add_subplot(111) self.h_lifetime = self.a_lt.hist(self.lifetime_sp, self.lt_bins, range=(self.lt_l, self.lt_r)) self.a_lt.semilogy() self.drawHistCanvas_lt.draw() t_02 = time.time() self.cps = c_num_2/(t_02 - t_01) self.lt_cps_text.SetValue(str(int(self.cps))) self.lt_counts_text.SetValue(str(self.total_counts)) self.waveloop.pop(0) t_01 = time.time() if self.total_counts > self.counts_set: self.dos_0.close() self.e_start_but = 0 break t_06 = time.time() print(t_06 - t_05)
def loop_lifetime_test(self): self.c_num_1 = 0 t_01 = time.time() t_05 = time.time() while self.dos_0.isOpen(): c_num_2 = 0 waveform0 = self.dos_0.get_wave() if operator.eq(self.wave1, waveform0['c1'][1]) == False: if self.para_0['SEQ'] == 'ON': for i in range(0, self.para_0['SEQ_N']): # c1 if self.intplo_switch == 1: f1 = interpolate.interp1d(waveform0['c1'][0][i], waveform0['c1'][1][i], kind='quadratic') wave_01 = np.linspace(waveform0['c1'][0][i][0], waveform0['c1'][0][i][-1], 5*(len(waveform0['c1'][0][i]) - 1) + 1) wave_02 = f1(wave_01) waveform0['c1'][0][i] = wave_01 waveform0['c1'][1][i] = wave_02 t1 = tools.Wavetools(waveform0['c1'][0][i], waveform0['c1'][1][i]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 t2 = tools.Wavetools(waveform0['c2'][0][i], waveform0['c2'][1][i]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.c_num_1 = self.c_num_1 + 1 if e_1 > self.lt_start_l and e_1 < self.lt_start_r \ and e_2 > self.lt_stop_l and e_2 < self.lt_stop_r : # t_start = t1.get_time_cfd_poln(self.start_fraction, 4, 0.4) # t_stop = t2.get_time_cfd_poln(self.stop_fraction, 4, 0.4) # t_start = t1.get_time_cfd_linear(self.start_fraction) # t_stop = t2.get_time_cfd_linear(self.start_fraction) t_start = t1.get_time_cfd_interpolation(self.start_fraction) t_stop = t2.get_time_cfd_interpolation(self.start_fraction) # t_start_l = t1.get_time_cfd_linear(self.start_fraction) # t_stop_l = t2.get_time_cfd_linear(self.stop_fraction) self.lifetime.append(t_stop - t_start) # self.lifetime_linear.append(t_stop_l - t_start_l) self.start_energy.append(e_1) self.stop_energy.append(e_2) # print(t_stop - t_start) c_num_2 = c_num_2 + 1 self.total_counts = self.total_counts + 1 if e_1 > self.lt_sp_start_l and e_1 < self.lt_sp_start_r and e_2 > self.lt_sp_stop_l \ and e_2 < self.lt_sp_stop_r: self.lifetime_sp.append(t_stop - t_start) else: # c1 if self.intplo_switch == 1: f1 = interpolate.interp1d(waveform0['c1'][0][i], waveform0['c1'][1][i], kind='quadratic') wave_01 = np.linspace(waveform0['c1'][0][i][0], waveform0['c1'][0][i][-1], 5 * (len(waveform0['c1'][0][i]) - 1) + 1) wave_02 = f1(wave_01) waveform0['c1'][0][i] = wave_01 waveform0['c1'][1][i] = wave_02 t1 = tools.Wavetools(waveform0['c1'][0], waveform0['c1'][1]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() # c2 t2 = tools.Wavetools(waveform0['c2'][0], waveform0['c2'][1]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.c_num_1 = self.c_num_1 + 1 if e_1 > self.lt_start_l and e_1 < self.lt_start_r and e_2 > self.lt_stop_l \ and e_2 < self.lt_stop_r: t_start = t1.get_time_cfd_poln(self.start_fraction, 4, 0.4) t_stop = t2.get_time_cfd_poln(self.stop_fraction, 4, 0.4) # t_start_l = t1.get_time_cfd_linear(self.start_fraction) # t_stop_l = t2.get_time_cfd_linear(self.stop_fraction) self.lifetime.append(t_stop - t_start) # self.lifetime_linear.append(t_stop_l - t_start_l) self.start_energy.append(e_1) self.stop_energy.append(e_2) c_num_2 = c_num_2 + 1 self.total_counts = self.total_counts + 1 if e_1 > self.lt_sp_start_l and e_1 < self.lt_sp_start_r and e_2 > self.lt_sp_stop_l \ and e_2 < self.lt_sp_stop_r: self.lifetime_sp.append(t_stop - t_start) if self.c_num_1 % 500 == 0: self.drawHistF_lt.clf() self.a_lt = self.drawHistF_lt.add_subplot(111) self.h_lifetime = self.a_lt.hist(self.lifetime_sp, self.lt_bins, range=(self.lt_l, self.lt_r)) self.a_lt.semilogy() self.drawHistCanvas_lt.draw() t_02 = time.time() self.cps = c_num_2/(t_02 - t_01) self.lt_cps_text.SetValue(str(int(self.cps))) self.lt_counts_text.SetValue(str(self.total_counts)) t_01 = time.time() self.wave1 = waveform0['c1'][1] if self.total_counts > self.counts_set: self.dos_0.close() self.e_start_but = 0 break t_06 = time.time() print(t_06 - t_05)
def loop_energy_test(self): self.c_num = 0 while self.dos_0.isOpen(): waveform0 = self.dos_0.get_wave() if operator.eq(self.wave0, waveform0['c1'][1]) == False: if self.para_0['SEQ'] == 'ON': for i in range(0,self.para_0['SEQ_N']): if self.intplo_switch == 1: f1 = interpolate.interp1d(waveform0['c1'][0][i], waveform0['c1'][1][i], kind='quadratic') wave_01 = np.linspace(waveform0['c1'][0][i][0], waveform0['c1'][0][i][-1], 5 * (len(waveform0['c1'][0][i]) - 1) + 1) wave_02 = f1(wave_01) waveform0['c1'][0][i] = wave_01.tolist() waveform0['c1'][1][i] = wave_02.tolist() f2 = interpolate.interp1d(waveform0['c2'][0][i], waveform0['c2'][1][i], kind='quadratic') wave_03 = np.linspace(waveform0['c2'][0][i][0], waveform0['c2'][0][i][-1], 5 * (len(waveform0['c2'][0][i]) - 1) + 1) wave_04 = f2(wave_03) waveform0['c2'][0][i] = wave_03.tolist() waveform0['c2'][1][i] = wave_04.tolist() #c1 t1 = tools.Wavetools(waveform0['c1'][0][i],waveform0['c1'][1][i], 800) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() self.energy_c1.append(e_1) self.amp_c1.append(amp_1) #c2 t2 = tools.Wavetools(waveform0['c2'][0][i], waveform0['c2'][1][i], 800) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.energy_c2.append(e_2) self.amp_c2.append(amp_2) self.c_num = self.c_num + 1 else: #c1 t1 = tools.Wavetools(waveform0['c1'][0], waveform0['c1'][1]) e_1 = t1.get_energy(0.2) amp_1 = t1.get_amplitude() self.energy_c1.append(e_1) self.amp_c1.append(amp_1) #c2 t2 = tools.Wavetools(waveform0['c2'][0][i], waveform0['c2'][1][i]) e_2 = t2.get_energy(0.2) amp_2 = t2.get_amplitude() self.energy_c2.append(e_2) self.amp_c2.append(amp_2) self.c_num = self.c_num + 1 if self.c_num % 100 == 0: self.drawHistF.clf() #c1 self.a = self.drawHistF.add_subplot(221) self.h_energy_c1 = self.a.hist(self.energy_c1, 150, range=(self.e_rg['c1'][0], self.e_rg['c1'][1])) #self.a.set_xlabel('energy') self.b = self.drawHistF.add_subplot(222) self.h_amp_c1 = self.b.hist(self.amp_c1, 150, range=(self.e_rg['c1_amp'][0], self.e_rg['c1_amp'][1])) #self.b.set_xlabel('amp') #c2 self.a_c2 = self.drawHistF.add_subplot(223) self.h_energy_c2 = self.a_c2.hist(self.energy_c2, 150, range=(self.e_rg['c2'][0], self.e_rg['c2'][1])) self.a_c2.set_xlabel('energy') self.b_c2 = self.drawHistF.add_subplot(224) self.h_amp_c2 = self.b_c2.hist(self.amp_c2, 150, range=(self.e_rg['c2_amp'][0], self.e_rg['c2_amp'][1])) self.b_c2.set_xlabel('amp') #self.a.semilogy() self.drawHistCanvas.draw() self.wave0 = waveform0['c1'][1]