forked from Pocar-Lab/SPE-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLXe_March_2024_Analysis.py
383 lines (349 loc) · 17 KB
/
LXe_March_2024_Analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 9 14:28:38 2023
@author: hpeltzsmalle
"""
import sys
import numpy as np
# append necessary file paths, and change E -> D or vice versa
#sys.path.append('D:/Xe/AnalysisScripts/LXe May 2023/')
from MeasurementInfo import MeasurementInfo
from RunInfo import RunInfo
import heapq
from scipy import signal
from scipy.optimize import curve_fit
import AnalyzePDE
from AnalyzePDE import SPE_data
from AnalyzePDE import Alpha_data
import matplotlib.pyplot as plt
import matplotlib as mpl
import ProcessWaveforms_MultiGaussian
from ProcessWaveforms_MultiGaussian import WaveformProcessor as WaveformProcessor
import h5py
#plt.style.use('D:/Xe/AnalysisScripts/LXe May 2023/nexo_new.mplstyle')
#%% SPE-VBD
#100ns, new shaper, 10x gain, filtered (c hange as needed; make sure it is the correct factor for the data set)
invC_spe_filter = 0.011959447603692185
invC_spe_err_filter = 3.881945391072933E-05
file_path = 'C:/Users/shofmann/Lab Work/Analysis Data/3_28_2024/' # folder with H5 data files
run_spe_solicited = RunInfo([file_path+'Run_1711658069.hdf5'], do_filter = True, is_solicit = True, upper_limit = 1, baseline_correct = True)
# loop quickly loads in files
# separate files for each bias voltage -> specifyAcquisition = False
files = ['Run_1711644709.hdf5', 'Run_1711646170.hdf5', 'Run_1711647473.hdf5','Run_1711649968.hdf5', 'Run_1711650930.hdf5', 'Run_1711652152.hdf5', 'Run_1711653287.hdf5', 'Run_1711655678.hdf5','Run_1711656528.hdf5' ] #,'Run_1695208893.hdf5', 'Run_1695215355.hdf5', 'Run_1695216383.hdf5', 'Run_1695220376.hdf5', 'Run_1695219096.hdf5'] #, 'Run_1695216841.hdf5', 'Run_1695209974.hdf5'
proms = [0.0097,0.0097,0.0067,0.007, 0.0075,0.0075,0.0075 ,0.0085, .0075, .00985]
upperlim = [.3, .4, .23, .76, .3, .3, .3, .3, .3 ,.3]
runs = []
for file in range(len(files)):
run_spe = RunInfo([file_path+files[file]], specifyAcquisition = False, do_filter = True, upper_limit = upperlim[file],
baseline_correct = True, prominence = proms[file], poly_correct = True, plot_waveforms = False, is_led=True)
runs.append(run_spe)
plt.show()
biases = [run.bias for run in runs]
#%%
run_spe_solicited.plot_hists("", "")
#%%
runs[6] = RunInfo([file_path +files[6]], specifyAcquisition = False, do_filter = True, upper_limit = .3 , baseline_correct = True, prominence = 0.0085 , poly_correct = True, plot_waveforms = False, is_led=True)
#%%
# TODO: Add baseline data to the historgrams
cutoffs = []
centers_list=[]
centers_guesses = []
for run in runs:
distance = 5
if run.bias == 36:
distance = 2
bins = int(round(np.sqrt(len(run.all_peak_data))))*2
print(bins)
count, edges = np.histogram(run.all_peak_data, bins=bins)
centers = (edges[:-1] + edges[1:])/2
peaks, props = signal.find_peaks(count, prominence=10, distance=distance)
print(peaks)
fitrange = ((centers[peaks[3]] - centers[peaks[0]])/2)
range_low = centers[peaks[0]]- 0.38*fitrange
range_high = centers[peaks[3]]+ 0.42*fitrange
cutoffs.append((range_low, range_high))
centers_list.append(centers[peaks[0]])
peaks = peaks[0:]
centers_guesses.append([centers[peak] for peak in peaks])
plt.figure()
plt.hist(run.all_peak_data, bins=bins)
for peak in peaks:
plt.scatter(centers[peak],count[peak])
plt.axvline(range_low, c='red')
plt.axvline(range_high, c='black')
# plt.xlim([0,1])
plt.yscale('log')
#%% testing cell - plot with peak fit
# set conditions, temp
n=0
T = 168
con = 'LXe'
info_spe = MeasurementInfo()
info_spe.condition = con
info_spe.date = runs[n].date
info_spe.temperature = T
info_spe.bias = biases[n]
info_spe.baseline_numbins = 200
info_spe.peaks_numbins = 400
info_spe.data_type = 'h5'
wp = WaveformProcessor(info_spe, run_info_self = runs[n], run_info_solicit = run_spe_solicited,
baseline_correct = True, cutoff = cutoffs[n], centers = centers_guesses[n], peak_range=(1,4)) #, numpeaks = 4)
wp.process(do_spe = True, do_alpha = False)
wp.plot_peak_histograms(log_scale = False)
wp.plot_spe()
wp.plot_both_histograms()
wp.plot_baseline_histogram()
#%% make a list of ProcessWaveforms objects
campaign_spe = []
cutoffs[0] = (.0064, .035)
cutoffs[1] = (.0064, .038)
for i in range(len(runs)):
info_spe = MeasurementInfo()
info_spe.condition = 'LXe'
info_spe.date = runs[i].date
info_spe.temperature = 168
info_spe.bias = runs[i].bias
info_spe.baseline_numbins = 50
info_spe.peaks_numbins = 150
info_spe.data_type = 'h5'
# if i == 2:
# num = 3
# else:
num = 4
wp_spe = WaveformProcessor(info_spe, run_info_self = runs[i], run_info_solicit = run_spe_solicited, baseline_correct = True,
cutoff = cutoffs[i], centers = centers_guesses[i], no_solicit = False, subtraction_method=True) #, numpeaks = num)
wp_spe.process(do_spe = True, do_alpha = False)
wp_spe.plot_peak_histograms(log_scale = False, savefig=False, path = 'D:/Xe/AnalysisScripts/May_170K_gauss_'+str(info_spe.bias)+'.png')
wp_spe.plot_spe(savefig=False, path = 'D:/Xe/AnalysisScripts/May_170K_spe_'+str(info_spe.bias)+'.png')
wp_spe.plot_both_histograms(log_scale = False, savefig=False, path = 'D:/Xe/AnalysisScripts/May_170K_baseline_'+str(info_spe.bias)+'.png')
wp_spe.plot_peak_histograms(log_scale = False, savefig=False, path = 'D:/Xe/AnalysisScripts/May_170K_gauss_'+str(info_spe.bias)+'.svg')
wp_spe.plot_spe(savefig=False, path = 'D:/Xe/AnalysisScripts/May_170K_spe_'+str(info_spe.bias)+'.svg')
wp_spe.plot_both_histograms(log_scale = False, savefig=False, path = 'D:/Xe/AnalysisScripts/May_170K_baseline_'+str(info_spe.bias)+'.svg')
plt.close()
campaign_spe.append(wp_spe)
#%% plot linear fit to the breakdown voltage
curr_campaign = campaign_spe
filtered_spe = SPE_data(curr_campaign, invC_spe_filter, invC_spe_err_filter, filtered = True)
filtered_spe.plot_spe(in_ov = False, absolute = False)#, out_file = 'D:/Xe/AnalysisScripts/May_170K_vbd_bias_updated.csv')
print(filtered_spe.v_bd)
print(filtered_spe.v_bd_err)
#%% plot in units of absolute gain vs OV
filtered_spe.plot_spe(in_ov = True, absolute = True) #, out_file = 'D:/Xe/AnalysisScripts/May_170K_vbd_ov_updated.csv')
#%% record BD voltage
# v_bd = 27.68
# v_bd_err = 0.05
v_bd = 28.58
v_bd_err = .215
#%%
filtered_spe.plot_CA()
#%% Corralated Avalanche
cutoffs = []
centers_list=[]
centers_guesses = []
for run in runs:
bins = int(round(np.sqrt(len(run.all_peak_data))))
print(bins)
count, edges = np.histogram(run.all_peak_data, bins=bins)
centers = (edges[:-1] + edges[1:])/2
peaks, props = signal.find_peaks(count, prominence=30, distance=3)
print(peaks)
fitrange = ((centers[peaks[3]] - centers[peaks[0]])/2)
range_low = centers[peaks[0]]- 0.36*fitrange
range_high = centers[peaks[3]]+ 0.4*fitrange
if run.bias < 33:
range_low = centers[peaks[0]]- 0.36*fitrange
range_high = centers[peaks[3]]+ 0.27*fitrange
cutoffs.append((range_low, range_high))
centers_list.append(centers[peaks[0]])
peaks = peaks[0:]
centers_guesses.append([centers[peak] for peak in peaks])
# plt.figure()
# plt.hist(run.all_peak_data, bins=bins)
# for peak in peaks:
# plt.scatter(centers[peak],count[peak])
# plt.axvline(range_low, c='red')
# plt.axvline(range_high, c='black')
# plt.xlim([0,1])
# plt.yscale('log')
# %% testing cell - plot with peak fit
# set conditions, temp
n=5
T = 171
con = 'GN'
info_spe = MeasurementInfo()
info_spe.condition = con
info_spe.date = runs_CA[n].date
info_spe.temperature = T
info_spe.bias = runs_CA[n].bias
info_spe.baseline_numbins = 50
info_spe.peaks_numbins = 500
info_spe.data_type = 'h5'
wp = WaveformProcessor(info_spe, run_info_self = runs_CA[n], run_info_solicit = run_spe_solicited_CA, baseline_correct = True, cutoff = cutoffs[n], centers = centers_guesses[n], numpeaks = 4)
wp.process(do_spe = True, do_alpha = False)
# wp.plot_peak_histograms(log_scale = False)
# wp.plot_spe()
wp.plot_both_histograms()
# wp.plot_baseline_histogram()
#%% make a list of ProcessWaveforms objects
campaign_CA = []
for i in range(len(runs_CA)):
info_spe = MeasurementInfo()
info_spe.condition = 'GN'
info_spe.date = runs_CA[i].date
info_spe.temperature = 171
info_spe.bias = runs_CA[i].bias
info_spe.baseline_numbins = 50
info_spe.peaks_numbins = 400
info_spe.data_type = 'h5'
num = 4
wp_spe = WaveformProcessor(info_spe, run_info_self = runs_CA[i], run_info_solicit = run_spe_solicited_CA, baseline_correct = True, cutoff = cutoffs[i], centers = centers_guesses[i], no_solicit = False, numpeaks = num)
wp_spe.process(do_spe = True, do_alpha = False)
wp_spe.plot_peak_histograms(log_scale = False)
campaign_CA.append(wp_spe)
#%%
invC_CA_filter = 0.01171
invC_CA_err_filter = 4.8E-05
spe_CA = SPE_data(campaign_CA, invC_CA_filter, invC_CA_err_filter, filtered = True)
spe_CA.plot_spe(in_ov = False, absolute = False, out_file = 'D:/Xe/AnalysisScripts/CA_vbd_bias.csv')
#%%
spe_CA.plot_CA(out_file='D:/Xe/AnalysisScripts/LXe May 2023/CA_GN.csv')
spe_CA.plot_CA_rms()
#%%
n = 0
for i in campaign_CA:
n+=1
i.plot_peak_histograms(log_scale = False, savefig=True, path = 'D:/Xe/AnalysisScripts/LXe May 2023/CA_GN_gauss_'+str(n)+'.png')
plt.close()
i.plot_peak_histograms(log_scale = False, savefig=True, path = 'D:/Xe/AnalysisScripts/LXe May 2023/CA_GN_gauss_'+str(n)+'.svg')
plt.close()
i.plot_spe(savefig=True, path = 'D:/Xe/AnalysisScripts/LXe May 2023/CA_GN_spe_'+str(n)+'.png')
plt.close()
i.plot_spe(savefig=True, path = 'D:/Xe/AnalysisScripts/LXe May 2023/CA_GN_spe_'+str(n)+'.svg')
plt.close()
i.plot_both_histograms(savefig=True, path = 'D:/Xe/AnalysisScripts/LXe May 2023/CA_GN_both_'+str(n)+'.png')
plt.close()
i.plot_both_histograms(savefig=True, path = 'D:/Xe/AnalysisScripts/LXe May 2023/CA_GN_both_'+str(n)+'.svg')
plt.close()
#%%
n = 0
for i in campaign_CA:
n+=1
i.plot_peak_histograms(log_scale = False)
#%% ALPHA - 1us
#1us, no gain, no filter
invC_alpha_1us = 0.001142
invC_alpha_err_1us = 2.1E-6
files = ['Acquisition_1684439574', 'Acquisition_1684439834','Acquisition_1684440058', 'Acquisition_1684440328','Acquisition_1684440542', 'Acquisition_1684440766', 'Acquisition_1684441008','Acquisition_1684441249','Acquisition_1684441553', 'Acquisition_1684441781', 'Acquisition_1684442031', 'Acquisition_1684442292', 'Acquisition_1684442515', 'Acquisition_1684442713', 'Acquisition_1684442986', 'Acquisition_1684443190', 'Acquisition_1684443416']
proms = [0.007,0.007,0.007,0.01,0.01,0.01,0.02,0.05,0.05,0.06,0.07,0.07,0.07,0.07, 0.2, 0.35, 0.4, 0.5, 0.5]
upperlim = [0.18,0.18,0.18,0.35,0.35,0.35,0.5,0.8,0.8,0.8,0.8,1.75,1.75,1.75,10,10,10,10,10]
runs_alpha_1us = []
for file in range(len(files)):
run_alpha_1us = RunInfo(['C:/Users/Hannah/Downloads/Run_1684439289.hdf5'], specifyAcquisition = True, acquisition = files[file], do_filter = False, upper_limit = upperlim[file], baseline_correct = True, prominence = proms[file], is_solicit = False)
runs_alpha_1us.append(run_alpha_1us)
biases = [run.bias for run in runs_alpha_1us] # get all the bias voltages from RunInfo (enter manually if metadata is wrong)
#%%
campaign_alpha_1us = []
runs_alpha = runs_alpha_1us
for i in range(len(runs_alpha)):
info_alpha = MeasurementInfo()
info_alpha.min_alpha_value = 0.01
if i > 7: # set lower cutoff to be higher for higher ov
info_alpha.min_alpha_value = 0.15
info_alpha.condition = 'LXe'
info_alpha.date = runs_alpha[i].date
info_alpha.temperature = 170
info_alpha.bias = runs_alpha[i].bias
info_alpha.baseline_numbins = 40
info_alpha.peaks_numbins = 50
info_alpha.data_type = 'h5'
wp = WaveformProcessor(info_alpha, run_info_self = runs_alpha[i], baseline_correct = True, no_solicit = True)
wp.process(do_spe = False, do_alpha = True)
j, k = wp.get_alpha()
campaign_alpha_1us.append(wp)
print(info_alpha.bias)
print(runs_alpha[i].do_filter)
#%% testing
for i in runs_alpha_1us:
i.plot_hists('','')
#%%
alpha_data_1us = Alpha_data(campaign_alpha_1us, invC_alpha_1us, invC_alpha_err_1us, spe_CA, v_bd, v_bd_err)
alpha_data_1us.analyze_alpha()
#%%
alpha_data_1us.plot_alpha(color = 'green', out_file = 'D:/Xe/AnalysisScripts/LXe May 2023/May2023_Alpha_1us.csv')
alpha_data_1us.plot_num_det_photons(color = 'green')
#%% values
N = 5.49/(19.6E-6) # based on Wesley's APS slides
PTE = 0.004928 # Sili's logbook post 12551 / copper reflection 100% specular reflective / diffusive teflon
alpha_data_1us.plot_PDE(N*PTE, color='green', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_1us_specular_copper_on_diffusive.csv')
#%% values
N = 5.49/(19.6E-6) # based on Wesley's APS slides
PTE = 0.014515 # Sili's logbook post 12551 / copper reflection 100% specular reflective / specular teflon
alpha_data_1us.plot_PDE(N*PTE, color='green', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_1us_specular_copper_on_specular.csv')
#%%
N = 5.49/(19.6E-6) # based on Wesley's APS slides
PTE = 0.003741 # Sili's logbook post 12551 / no copper reflection / diffusive teflon
alpha_data_1us.plot_PDE(N*PTE, color='green', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_1us_copper_off_diffusive.csv')
#%% values
N = 5.49/(19.6E-6) # based on Wesley's APS slides
PTE = 0.013578 # Sili's logbook post 12551 / no copper reflection / specular teflon
alpha_data_1us.plot_PDE(N*PTE, color='green', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_1us_copper_off_specular.csv')
#%% values
PTE = 0.005122 # Sili's logbook post 12551 / copper reflection 100% diffusive / diffusive teflon
alpha_data_1us.plot_PDE(N*PTE, color='green', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_1us_diffusive_copper_on_diffusive.csv')
#%% values
PTE = 0.014812 # Sili's logbook post 12551 / copper reflection 100% diffusive / specular teflon
alpha_data_1us.plot_PDE(N*PTE, color='green', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_1us_diffusive_copper_on_specular.csv')
#%% ALPHA - 100ns
#100ns, no gain, no filter
invC_alpha_100ns = 0.004074442176917963
invC_alpha_err_100ns = 1.4320358414009397E-05
files = ['Acquisition_1684429006', 'Acquisition_1684429323','Acquisition_1684429598','Acquisition_1684429901', 'Acquisition_1684430142', 'Acquisition_1684430326','Acquisition_1684430543','Acquisition_1684430787', 'Acquisition_1684431075', 'Acquisition_1684431293', 'Acquisition_1684431526', 'Acquisition_1684431824', 'Acquisition_1684432042', 'Acquisition_1684432244', 'Acquisition_1684432473', 'Acquisition_1684432689'] #,'Acquisition_1684432883','Acquisition_1684433075'
proms = [0.01,0.01,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07, 0.2, 0.35, 0.5, 0.5, 1]
upperlim = [0.15,0.15,0.35, 0.35,0.95,0.95,0.95,0.95,1.95,1.95,1.95,4.95,4.95,4.95,4.95,4.95]
runs_alpha_100ns = []
for file in range(len(files)):
run_alpha_100ns = RunInfo(['C:/Users/Hannah/Downloads/Run_1684428416.hdf5'], specifyAcquisition = True, acquisition = files[file], do_filter = False, upper_limit = upperlim[file], baseline_correct = True, prominence = proms[file], is_solicit = False)
runs_alpha_100ns.append(run_alpha_100ns)
biases = [run.bias for run in runs_alpha_100ns] # get all the bias voltages from RunInfo (enter manually if metadata is wrong)
#%%
campaign_alpha_100ns = []
runs_alpha = runs_alpha_100ns
for i in range(len(runs_alpha)):
info_alpha = MeasurementInfo()
info_alpha.min_alpha_value = 0.01
# if i > 7: # set lower cutoff to be higher for higher ov
# info_alpha.min_alpha_value = 0.15
info_alpha.condition = 'LXe'
info_alpha.date = runs_alpha[i].date
info_alpha.temperature = 170
info_alpha.bias = runs_alpha[i].bias
info_alpha.baseline_numbins = 40
info_alpha.peaks_numbins = 50
info_alpha.data_type = 'h5'
wp = WaveformProcessor(info_alpha, run_info_self = runs_alpha[i], baseline_correct = True, no_solicit = True)
wp.process(do_spe = False, do_alpha = True)
j, k = wp.get_alpha()
campaign_alpha_100ns.append(wp)
print(info_alpha.bias)
#%%
for i in runs_alpha_100ns:
i.plot_hists('','')
#%%
invC_alpha = invC_alpha_100ns
invC_alpha_err = invC_alpha_err_100ns
alpha_data_100ns = Alpha_data(campaign_alpha_100ns, invC_alpha, invC_alpha_err, spe, v_bd, v_bd_err)
alpha_data_100ns.analyze_alpha()
#%%
n = 0
for i in campaign_alpha_100ns:
n+=1
i.plot_alpha_histogram(peakcolor = 'purple')
plt.savefig('D:/Xe/AnalysisScripts/LXe May 2023/100ns_'+str(n)+'.png')
plt.close()
#%%
alpha_data_100ns.plot_alpha(color = 'purple', out_file = 'D:/Xe/AnalysisScripts/LXe May 2023/2023May_100ns_alpha.csv')
alpha_data_100ns.plot_num_det_photons()
#%% values
N = 5.49/(19.6E-6) # based on Wesley's APS slides
PTE = 0.003741 # Sili's logbook post 12551
alpha_data_100ns.plot_PDE(N*PTE, color='purple', out_file = 'D:/Xe/AnalysisScripts/May_170K_PDE_100ns.csv')