Fitto gli spettri illuminati, quindi plotto la delta pp al variare del bias.
I files sono in punto3_bis
Usiamo 3 dataset per ogni bias. Il fatto che si vedano le linee tratteggiate che fanno cose strane dipende dal fatto che non ho corretto a mano i files, ma ho usato pandas che non si lamenta. Semplicemente non mettiamo quei plot nella presentazione...
import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import curve_fit
from scipy.signal import find_peaks
import os
import pandas as pd
def gaus5Gaus(x,*args):
return args[0] * np.exp( -(x-args[1])**2 / (2*args[2]**2)) + \
args[3] * np.exp( -(x-args[4])**2 / (2*args[5]**2)) + \
args[6] * np.exp( -(x-args[7])**2 / (2*args[8]**2)) + \
args[9] * np.exp( -(x-args[10])**2 / (2*args[11]**2)) + \
args[12] * np.exp( -(x-args[13])**2 / (2*args[14]**2)) + \
args[15] * np.exp( -(x-args[16])**2 / (2*args[17]**2))
def myLine(x, m, q):
return m*x + q
def fittaSpettri(fileName):
#x,y = np.loadtxt(fileName, unpack=True)
df = pd.read_csv(fileName, sep = "\t", header = None, names = ("x", "y"), on_bad_lines = "warn")
x = df.x.to_numpy()
y = df.y.to_numpy()
#print(fileName)
cond = (x > -500) & (x < 6921) & (y > 0)
cond = (x > -500) & (x < 5500) & (y > 0)
xData = x[cond]
yData = y[cond]
# Trovo i massimi
idx, kkk = find_peaks(yData, width = 3, prominence = 50, distance = 30)
"""
if len(idx) > 5:
# li prendo in ordine di altezza
tmpy = yData[idx]
perm = np.flip(np.argsort(tmpy))
idx = idx[perm[:5]]
idx = np.sort(idx)
"""
if len(idx) > 5:
idx = idx[:5]
"""
print(idx)
print(len(idx))
print(kkk)
"""
# Definisco gli startPars
tmp = []
for i in idx:
tmp.append(yData[i])
tmp.append(xData[i])
tmp.append(30)
tmp.append(yData[idx[2]]/2)
tmp.append(xData[idx[2]])
tmp.append(750)
tmp = np.array(tmp)
#print(len(tmp))
# Nuove condizioni
cond = (x > -500) & (x < (xData[idx[4]] + 100)) & (y > 0)
xxData = x[cond]
yyData = y[cond]
# Effettuo il fit
popt, pcov = curve_fit(gaus5Gaus, xxData, yyData, sigma = np.sqrt(yyData), p0 = tmp, maxfev = 1000000)
#print(popt)
lstPopt.append(popt)
lstPcov.append(pcov)
#print(popt)
# Plotto spettro, fit e massimi trovati
fig, ax = plt.subplots()
ax.set_title(f"{fileName}")
ax.plot(x, y, ds = "steps-mid", c = "tab:green", lw = 3, ls = "", marker = ".")
ax.plot(xxData, gaus5Gaus(xxData, *popt), "--k")
ax.plot(xData[idx], yData[idx], "*r", ms = 20)
ax.set_xlim(-500, 3000)
ax.grid()
plt.show()
%matplotlib inline
plt.close("all")
# Parametri fit
lstPopt = []
lstPcov = []
# Bias
lstBias = []
for e in os.scandir(".\punto3_bis"):
if e.name.split(".")[-1] != "txt": continue
if e.name.split("_")[-1][:3] == "old": continue
if e.name.split("_")[-2] in ("4", "5", "0"): continue
"""
if e.path == r".\punto3_bis\MPH_l_55_3_histo.txt":
%matplotlib qt
fittaSpettri(e.path)
"""
print(e.path)
fittaSpettri(e.path)
lstBias.append(e.name.split("_")[2])
#print(e.name.split("_")[0][4:])
lstBias = np.array(lstBias, dtype = float)
lstPopt = np.array(lstPopt)
lstPcov = np.array(lstPcov)
lstBias
.\punto3_bis\MPH_l_55_3_histo.txt
.\punto3_bis\MPH_l_52.7_1_histo.txt
.\punto3_bis\MPH_l_52.7_2_histo.txt
.\punto3_bis\MPH_l_52.7_3_histo.txt
.\punto3_bis\MPH_l_52.8_1_histo.txt
.\punto3_bis\MPH_l_52.8_2_histo.txt
.\punto3_bis\MPH_l_52.8_3_histo.txt
.\punto3_bis\MPH_l_52.9_1_histo.txt
.\punto3_bis\MPH_l_52.9_2_histo.txt
.\punto3_bis\MPH_l_52.9_3_histo.txt
C:\Users\steca\anaconda3\lib\site-packages\scipy\optimize\minpack.py:833: OptimizeWarning: Covariance of the parameters could not be estimated warnings.warn('Covariance of the parameters could not be estimated',
.\punto3_bis\MPH_l_52.75_1_histo.txt
.\punto3_bis\MPH_l_52.75_2_histo.txt
.\punto3_bis\MPH_l_52.75_3_histo.txt
.\punto3_bis\MPH_l_52.85_1_histo.txt
.\punto3_bis\MPH_l_52.85_2_histo.txt
.\punto3_bis\MPH_l_52.85_3_histo.txt
.\punto3_bis\MPH_l_52.95_1_histo.txt
.\punto3_bis\MPH_l_52.95_2_histo.txt
.\punto3_bis\MPH_l_52.95_3_histo.txt
C:\Users\steca\anaconda3\lib\site-packages\scipy\optimize\minpack.py:833: OptimizeWarning: Covariance of the parameters could not be estimated warnings.warn('Covariance of the parameters could not be estimated',
.\punto3_bis\MPH_l_53.5_1_histo.txt
.\punto3_bis\MPH_l_53.5_2_histo.txt
.\punto3_bis\MPH_l_53.5_3_histo.txt
.\punto3_bis\MPH_l_53_1_histo.txt
.\punto3_bis\MPH_l_53_2_histo.txt
.\punto3_bis\MPH_l_53_3_histo.txt
.\punto3_bis\MPH_l_54.5_1_histo.txt
.\punto3_bis\MPH_l_54.5_2_histo.txt
.\punto3_bis\MPH_l_54.5_3_histo.txt
.\punto3_bis\MPH_l_54_1_histo.txt
.\punto3_bis\MPH_l_54_2_histo.txt
.\punto3_bis\MPH_l_54_3_histo.txt
.\punto3_bis\MPH_l_55.5_1_histo.txt
.\punto3_bis\MPH_l_55.5_2_histo.txt
.\punto3_bis\MPH_l_55.5_3_histo.txt
.\punto3_bis\MPH_l_55_1_histo.txt
.\punto3_bis\MPH_l_55_2_histo.txt
array([55. , 52.7 , 52.7 , 52.7 , 52.8 , 52.8 , 52.8 , 52.9 , 52.9 , 52.9 , 52.75, 52.75, 52.75, 52.85, 52.85, 52.85, 52.95, 52.95, 52.95, 53.5 , 53.5 , 53.5 , 53. , 53. , 53. , 54.5 , 54.5 , 54.5 , 54. , 54. , 54. , 55.5 , 55.5 , 55.5 , 55. , 55. ])
len(lstBias)/3
12.0
perm = np.argsort(lstBias)
print(perm)
lstBias = lstBias[perm]
lstPopt = lstPopt[perm]
lstPcov = lstPcov[perm]
lstBiasVect = np.reshape(lstBias, (int(len(lstBias)/3), 3))[:,0]
lstBiasVect
[ 1 2 3 10 11 12 4 5 6 14 13 15 7 8 9 18 17 16 22 23 24 19 20 21 30 28 29 25 26 27 0 34 35 31 32 33]
array([52.7 , 52.75, 52.8 , 52.85, 52.9 , 52.95, 53. , 53.5 , 54. , 54.5 , 55. , 55.5 ])
dpp21 = []
for i in lstPopt:
dpp21.append((i[7]-i[4]))
dpp21 = np.array(dpp21)
dpp21 = np.reshape(dpp21, (int(len(lstBias)/3), 3))
print(dpp21)
dpp21_mean = np.mean(dpp21, axis = 1)
dpp21_std = np.std(dpp21, axis = 1)
print(dpp21_mean)
# Serve?
errDpp21 = []
for i in lstPcov:
err2 = np.sqrt(np.diag(i)[7])
err1 = np.sqrt(np.diag(i)[4])
errDpp21.append(np.sqrt(err1**2 + err2**2))
errDpp21 = np.array(errDpp21)
# ===============================
dpp43 = []
for i in lstPopt:
dpp43.append((i[13]-i[10]))
dpp43 = np.array(dpp21)
dpp43 = np.reshape(dpp21, (int(len(lstBias)/3), 3))
print(dpp43)
dpp43_mean = np.mean(dpp43, axis = 1)
dpp43_std = np.std(dpp43, axis = 1)
print(dpp43_mean)
# Serve?
errDpp43 = []
for i in lstPcov:
err2 = np.sqrt(np.diag(i)[13])
err1 = np.sqrt(np.diag(i)[10])
errDpp43.append(np.sqrt(err1**2 + err2**2))
errDpp43 = np.array(errDpp43)
[[ 93.06849587 94.43615147 93.78774658] [104.96756917 103.80717032 103.95389928] [114.38527372 113.31745117 114.58411693] [125.56964435 125.85110281 125.14621233] [135.60278861 136.17528182 136.34866477] [146.48178633 146.16290248 146.46528144] [155.52362064 157.40215175 157.56261801] [252.13787137 252.88231397 252.27927075] [345.02342485 344.9575942 344.74101725] [435.89701827 436.70173558 436.21414885] [525.95647268 525.96278449 526.23295134] [616.12113612 616.10320693 616.8232128 ]] [ 93.76413131 104.24287959 114.09561394 125.52231983 136.04224506 146.36999009 156.82946347 252.43315203 344.90734543 436.27096757 526.05073617 616.34918529] [[ 93.06849587 94.43615147 93.78774658] [104.96756917 103.80717032 103.95389928] [114.38527372 113.31745117 114.58411693] [125.56964435 125.85110281 125.14621233] [135.60278861 136.17528182 136.34866477] [146.48178633 146.16290248 146.46528144] [155.52362064 157.40215175 157.56261801] [252.13787137 252.88231397 252.27927075] [345.02342485 344.9575942 344.74101725] [435.89701827 436.70173558 436.21414885] [525.95647268 525.96278449 526.23295134] [616.12113612 616.10320693 616.8232128 ]] [ 93.76413131 104.24287959 114.09561394 125.52231983 136.04224506 146.36999009 156.82946347 252.43315203 344.90734543 436.27096757 526.05073617 616.34918529]
def myLine(x,m,q):
return m*x+q
fig, ax = plt.subplots(1, 2)
popt1, pcov1 = curve_fit(myLine,lstBiasVect, dpp21_mean, sigma = dpp21_std, absolute_sigma = True)
popt2, pcov2 = curve_fit(myLine,lstBiasVect, dpp43_mean, sigma = dpp43_std, absolute_sigma = True)
ax[0].errorbar(lstBiasVect, dpp21_mean, yerr = dpp21_std, marker = "s", ls = "", c = "tab:green")
ax[1].errorbar(lstBiasVect, dpp43_mean, yerr = dpp43_std, marker = "s", ls = "", c = "tab:green")
ax[0].plot(lstBiasVect, myLine(lstBiasVect, *popt1), ":k")
ax[1].plot(lstBiasVect, myLine(lstBiasVect, *popt2), ":k")
ax[0].set_title("$\Delta_{pp}$ 21 vs Voltage", fontsize = 16)
ax[1].set_title("$\Delta_{pp}$ 43 vs Voltage", fontsize = 16)
for i in ax:
i.grid()
i.set_xlabel("Bias [mV]", fontsize = 14)
i.set_ylabel("$\Delta_{pp}$", fontsize = 14)
plt.show()
print(f"Il breakdown nel caso 21 vale {-popt1[1]/popt1[0]}")
print(f"Il breakdown nel caso 43 vale {-popt2[1]/popt2[0]}")
Il breakdown nel caso 21 vale 52.15891552943205 Il breakdown nel caso 43 vale 52.15891552943205