Newer
Older
import h5py
import matplotlib.pyplot as plt
import numpy as np
import sys
import re
import ast
from scipy.optimize import curve_fit
import os
os.chdir('/home/nico/Documents/artiq_experiments/analisis/plots/20221024_BranchingFractionMeasurement')
Long_files = ['DP_long', 'SP_long']
Calib_files = ['Fondo_IR_50M', 'Fondo_UV_50M']
Short_files = [9132, 9134, 9136, 9138, 9140, 9142]
Fondo_files = [9133, 9135, 9137, 9139, 9141, 9143]
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
def expo(T, tau, N0, C):
global T0
return N0*np.exp(-(T-T0)/tau) + C
def pow_from_amp(amp):
"""Paso de amplitud urukul a potencia medida por Nico"""
# Forma altamente ineficiente de hacer esto, pero me salio asi
amplitudes_UV = np.flip(np.array([0.08, 0.10, 0.12, 0.14, 0.16, 0.18, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30]))
assert amp in amplitudes_UV
potencias_UV = np.flip(np.array([4, 10, 19, 32, 49, 71, 96, 125, 155, 183, 208, 229]))
return potencias_UV[np.where(amplitudes_UV == amp)][0]
def SP_Bkgr_builder(amp_in, amp_fin, derivadainicio, derivadafin, longbins):
CalibCurve = []
j=0
while j<longbins:
if j<=derivadainicio:
CalibCurve.append(amp_in)
elif j>=derivadainicio and j<=derivadafin:
pendiente=(amp_fin-amp_in)/(derivadafin-derivadainicio)
CalibCurve.append(amp_in+pendiente*(j-derivadainicio))
else:
CalibCurve.append(amp_fin)
j=j+1
return CalibCurve
"""
plt.plot(amplitudes_UV, potencias_UV, 'ko-', lw=0.2)
plt.xlabel("Amplitud Urukul")
plt.ylabel("Potencia /uW")
plt.grid()
"""
#%%
BINW = 10e-9
T0 = -0.4e-6
BINW_long = 10e-9
T0_long = -0.4e-6
Long_Heigths = []
Long_Bins = []
for i, fname in enumerate(Long_files):
#print(i)
#print(fname)
data = h5py.File('Data/Largas/'+str(fname)+'.h5', 'r')
counts = np.array(data['datasets']['counts'])
bines = np.arange(counts.min(), counts.max()+BINW_long, BINW_long)
heigs, binsf = np.histogram(counts, bines[bines>T0_long])
Long_Heigths.append(heigs)
Long_Bins.append(binsf)
BINW_calib = 10e-9
T0_calib = -0.4e-6
Calib_Heigths = []
Calib_Bins = []
for i, fname in enumerate(Calib_files):
#print(i)
#print(fname)
data = h5py.File('Data/Calibrations/'+str(fname)+'.h5', 'r')
counts = np.array(data['datasets']['counts'])
bines = np.arange(counts.min(), counts.max()+BINW_calib, BINW_calib)
heigs, binsf = np.histogram(counts, bines[bines>T0_calib])
Calib_Heigths.append(heigs)
Calib_Bins.append(binsf)
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
BINW_short = 5e-9
T0_short = -0.4e-6
Short_Heigths = []
Short_Bins = []
for i, fname in enumerate(Short_files):
#print(i)
#print(fname)
data = h5py.File('Data/Cortas/'+'00000'+str(fname)+'-SingleLine.h5', 'r')
counts = np.array(data['datasets']['counts'])
bines = np.arange(counts.min(), counts.max()+BINW_short, BINW_short)
heigs, binsf = np.histogram(counts, bines[bines>T0_short])
Short_Heigths.append(heigs)
Short_Bins.append(binsf)
BINW_fondo = 5e-9
T0_fondo = -0.4e-6
Fondo_Heigths = []
Fondo_Bins = []
for i, fname in enumerate(Fondo_files):
#print(i)
#print(fname)
data = h5py.File('Data/Fondos/00000'+str(fname)+'-SingleLine.h5', 'r')
counts = np.array(data['datasets']['counts'])
bines = np.arange(counts.min(), counts.max()+BINW_fondo, BINW_fondo)
heigs, binsf = np.histogram(counts, bines[bines>T0_fondo])
Fondo_Heigths.append(heigs)
Fondo_Bins.append(binsf)
#%%
"""
Vectores de amplitudes y potencias
"""
UVampVec = [0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26]
UVpotVec = [4, 6, 12, 17, 26, 36, 48, 77, 112, 151, 190, 226, 255, 279]
IRampVec = [0.10, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.2, 0.08]
#%%
RefBins = [t*1e6 for t in Long_Bins[0][:-1]]
plt.figure()
for i in range(len(Long_Heigths)):
plt.plot(Long_Bins[i][:-1], Long_Heigths[i])
for i in range(len(Calib_Heigths)):
plt.plot(Calib_Bins[i][:-1], Calib_Heigths[i])
#%%
"""Calculo branching"""
TotalDP = np.sum(Long_Heigths[0])
TotalSP = np.sum(Long_Heigths[1])
TotalDPbkg = np.sum(Calib_Heigths[0])
TotalSPbkg = np.sum(Calib_Heigths[1])
TotalDPfinal = TotalDP-TotalDPbkg
TotalSPfinal = TotalSP-TotalSPbkg
branch = TotalSPfinal/(TotalSPfinal+TotalDPfinal)
print(branch)
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
#%%
"""
Acondicionamiento señales
"""
SP_corrected = [Long_Heigths[1][k]-Calib_Heigths[1][k] for k in range(len(Long_Heigths[1]))]
DP_corrected = [Long_Heigths[0][k]-Calib_Heigths[0][k] for k in range(len(Long_Heigths[0]))]
plt.plot(Long_Bins[1][:-1], SP_corrected)
plt.plot(Long_Bins[0][:-1], DP_corrected)
#%%
"""
Figura branching
"""
import matplotlib
import seaborn as sns
matplotlib.rcParams['mathtext.fontset'] = 'stix'
matplotlib.rcParams['font.family'] = 'STIXGeneral'
plt.style.use('seaborn-bright')
plt.rcParams.update({
"text.usetex": False,
})
#plt.figure()
#plt.plot(Stat_Bins[0][:-1], Stat_Heigths[0])
#plot figuras papers
colors1=sns.color_palette("rocket", 10)
colors2=sns.color_palette("mako", 10)
color2 = colors2[1]
color3 = colors2[4]
color1 = colors2[8]
bins1 = np.arange(150,300, 1)
bins2 = np.arange(0,50,1)
bins3 = np.arange(30,100,1)
plt.figure(figsize = (3.8,3))
plt.plot([1e6*b-0.18 for b in Long_Bins[1][:-1]], SP_corrected, color=(0,0,128/255, 1),linewidth=2.5,label='SP transition')
plt.plot([1e6*b+0.09 for b in Long_Bins[0][:-1]], DP_corrected, color=(212/255,0,0, 1),linewidth=2.5,label='DP transition')
#plt.hist(Stat_Heigths[0], bins=bins1, histtype='step',density = True,color = color1, alpha = 0.6)#,label = 'BG')
#plt.hist(Stat_Heigths[1], bins=bins2, histtype='step',density = True,color = color2, alpha = 0.6)#,label = 'UV laser')
#plt.hist(Stat_Heigths[2], bins=bins3, histtype='step',density = True,color = color3, alpha = 0.6)#,label = 'Ion')
#plt.legend(loc=(0.15,0.65), prop={'size': 11})
plt.legend()
plt.grid()
plt.tight_layout()
plt.xlim(-0.3, 2)
plt.xticks([0, 1, 2], fontname='STIXGeneral')
plt.yticks([0,5000, 10000, 15000], fontname='STIXGeneral')
plt.xlabel('Time (us)', fontname='STIXGeneral')
plt.ylabel('Counts', fontname='STIXGeneral')
#poissoneidad = np.var(Stat_Heigths)/np.mean(Stat_Heigths)
#plt.title('Varianza/media = {:.4f}'.format(poissoneidad))
#plt.savefig('bg_laser_ion_stats.pdf',dpi = 600 )
name='fig02a'
plt.savefig('/home/nico/Nextcloud/G_liaf/Publicaciones/Papers/2022 Transient Phenomena JOSA B/Figures/'+name+'.pdf')
plt.savefig('/home/nico/Nextcloud/G_liaf/Publicaciones/Papers/2022 Transient Phenomena JOSA B/Figures/'+name+'.svg')
#%%
"""
Ahora mido de nuevo pero alternando medicion y fondo para que de mejor si hay derivas de potencias.
Estas mediciones DAN MUY BIEN. Tanto branching fraction como detection efficiency.
"""
med = 3
plt.plot(Short_Bins[med][:-1],Short_Heigths[med])
plt.plot(Fondo_Bins[med][:-1],Fondo_Heigths[med])
TotalSP = np.sum(Short_Heigths[2])-np.sum(Fondo_Heigths[2])+np.sum(Short_Heigths[4])-np.sum(Fondo_Heigths[4])
TotalDP = np.sum(Short_Heigths[3])-np.sum(Fondo_Heigths[3])+np.sum(Short_Heigths[5])-np.sum(Fondo_Heigths[5])
branch = TotalSP/(TotalSP+TotalDP)
print(branch)
ErrorSP = np.sqrt(np.sum(Short_Heigths[2])+np.sum(Fondo_Heigths[2])+np.sum(Short_Heigths[4])+np.sum(Fondo_Heigths[4]))
ErrorDP = np.sqrt(np.sum(Short_Heigths[3])+np.sum(Fondo_Heigths[3])+np.sum(Short_Heigths[5])+np.sum(Fondo_Heigths[5]))
Errorbranch =np.sqrt((1/(TotalSP + TotalDP) - TotalSP/(TotalSP+TotalDP)**2)**2 * ErrorSP**2 + (TotalSP/(TotalSP+TotalDP)**2)**2*ErrorDP**2)
DetectionEfficiency = 100*TotalDP/10e6
ErrorDetectionEfficiency = 100*np.sqrt(TotalDP)/10e6
Ratio = TotalSP/TotalDP
ErrorRatio = np.sqrt((1/(TotalDP**2))*(ErrorSP**2)+((TotalSP/(TotalDP**2))**2)*(ErrorDP**2))
print(ErrorRatio)