Cartelle di dati
import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import curve_fit
from scipy.signal import find_peaks
import os
def gauss(x,a,mu,sigma):
return a * np.exp(-((x-mu)/sigma)**2)
def miaFunzione(fileName):
print(fileName)
x,y = np.loadtxt(fileName, unpack=True)
# Scelgo i dati da fittare
cond = (x > -100) & (x < 100) & (y > 0)
xData = x[cond]
yData = y[cond]
# Fitto
popt, pcov = curve_fit(gauss, xData, yData,
sigma = np.sqrt(yData), absolute_sigma = True,
p0 = (np.max(yData), xData[np.argmax(yData)], 50) )
# Plotto
fig, ax = plt.subplots()
ax.set_title(f"{fileName}", fontsize = 16)
ax.plot(x,y, c = "tab:green")
ax.plot(xData, gauss(xData, *popt), ":k")
ax.set_xlim(-500, 1000)
ax.set_yscale("log")
ax.grid()
ax.set_xlabel("Energia [ADC]", fontsize = 14)
ax.set_ylabel("Entries", fontsize = 14)
#plt.show()
# Calcolo le aree
myMu = popt[1]
mySigma = np.abs(popt[2])
inizio = myMu - 3 * mySigma
fine = myMu + 3 * mySigma
ax.axvline(x = inizio, c = "grey", ls = "--")
ax.axvline(x = fine, c = "grey", ls = "--")
tmpCond = (x >= inizio) & (x <= fine)
# Integrale manuale
tmpInt = np.sum(y[tmpCond])
# Probabilità picco in zero
A0 = tmpInt
A = np.sum(y)
prob0 = A0/A
#prob0 = tmpInt/np.sum(y)
lstProb0.append(prob0)
print(prob0)
# Calcolo il DCR con la formula (tau gate = 152 ns)
mu0 = -np.log(prob0)
errMu0 = np.sqrt( 1/A0 + 1/A)
myGate = 152e-9
errMyGate = 8e-9 # avevamo risoluzione a 8 nani dice giò
#myDCR = -np.log(prob0) / 152e-9
#myDCR = mu0 / 152e-9
myDCR = mu0 / myGate
lstDCR.append(myDCR)
print(myDCR)
errDCR = np.sqrt((errMu0/myGate)**2 + (mu0*errMyGate/(myGate**2))**2)
lstErrDCR.append(errDCR)
print(errDCR)
print(mu0, errMu0)
plt.show()
Far girare sia con punto3_old che punto3_new ed osservare che siamo disabili a settare il bias
lstProb0 = []
lstDCR = []
lstErrDCR = []
lstBias = []
for e in os.scandir(r".\punto3_new"):
if e.name.split(".")[-1] != "txt": continue
#if e.name.split("_")[-1] == "old.txt": continue
if e.name.split("_")[-2] in ("4", "5"): continue
miaFunzione(e.path)
lstBias.append(e.name.split("_")[2])
lstProb0 = np.array(lstProb0)
lstDCR = np.array(lstDCR)
lstBias = np.array(lstBias)
.\punto3_new\MPH_n_54.5_1_histo.txt 0.9764402648308574 156853.3109525504 20709.29444521686 0.023841703264787666 0.00288689030459137
.\punto3_new\MPH_n_54.5_2_histo.txt 0.976294095974947 157838.224447222 23945.48470251787 0.023991410115977743 0.003413662213549343
.\punto3_new\MPH_n_54.5_3_histo.txt 0.9765987300530333 155785.708757777 24249.9874914809 0.023679427731182104 0.00346891251147318
.\punto3_new\MPH_n_55.5_1_histo.txt 0.9653627816214299 231916.50517518757 26594.707726711396 0.035251308786628514 0.0035914767153030244
.\punto3_new\MPH_n_55.5_2_histo.txt 0.9662816972131559 225657.07406736826 26341.53928034441 0.03429987525823998 0.0035738460681959193
.\punto3_new\MPH_n_55.5_3_histo.txt 0.9661748830514574 226384.36052328045 25888.536612205273 0.03441042279953863 0.0034935205458345247
.\punto3_new\MPH_n_55_1_histo.txt 0.9713299721482446 191375.2716040176 23407.42548631121 0.029089041283810676 0.0032116800580818195
.\punto3_new\MPH_n_55_2_histo.txt 0.9728526924788607 181069.75953187665 99279.32683543464 0.027522603448845252 0.015020772032787993
.\punto3_new\MPH_n_55_3_histo.txt 0.9710229875764681 193454.8476639085 26373.936019838682 0.029405136844914095 0.0036980533416664583
.\punto3_new\MPH_n_56.5_1_histo.txt 0.9566010963801952 291900.01062310743 28096.208347569704 0.04436880161471233 0.003575621216496904
.\punto3_new\MPH_n_56.5_2_histo.txt 0.9552573019050874 301148.3467859819 29482.559693133702 0.04577454871146925 0.0037786649234707293
.\punto3_new\MPH_n_56.5_3_histo.txt 0.9561637232717876 294908.6969824161 28874.223340407174 0.04482612194132725 0.0037008285315100987
.\punto3_new\MPH_n_56_1_histo.txt 0.9602880093799504 266592.30094345973 21734.63436446914 0.04052202974340589 0.0025230191254537264
.\punto3_new\MPH_n_56_2_histo.txt 0.961175284802992 260516.37043564438 27813.87302021651 0.03959848830621795 0.0036783038171498555
.\punto3_new\MPH_n_56_3_histo.txt 0.9610941988068642 261071.40239729753 27034.303672427603 0.03968285316438923 0.003538857338244225
perm = np.argsort(lstBias)
lstBias = lstBias[perm]
lstDCR = lstDCR[perm]
lstProb0 = lstProb0[perm]
matDCR = np.reshape(lstDCR, (int(len(lstDCR)/3), 3))
matBias = np.reshape(lstBias, (int(len(lstDCR)/3), 3))
matBias
array([['54.5', '54.5', '54.5'], ['55', '55', '55'], ['55.5', '55.5', '55.5'], ['56', '56', '56'], ['56.5', '56.5', '56.5']], dtype='<U4')
vectBias = matBias[:,0]
meanDCR = np.mean(matDCR, axis = 1)
stdDCR = np.std(matDCR, axis = 1)
print (meanDCR)
print(matDCR)
[156825.74805252 188633.29293327 227985.97992195 262726.6912588 295985.68479717] [[156853.31095255 157838.22444722 155785.70875778] [191375.27160402 181069.75953188 193454.84766391] [231916.50517519 225657.07406737 226384.36052328] [266592.30094346 260516.37043564 261071.4023973 ] [291900.01062311 301148.34678598 294908.69698242]]
fig, ax = plt.subplots()
ax.plot(vectBias, meanDCR*1e-3, marker = ".", c = "tab:green", ms = 10, ls = "--", zorder=1, label = "Data")
ax.errorbar(vectBias, meanDCR*1e-3, yerr = stdDCR*1e-3, marker = "", c = "k", ms = 10, ls = "", zorder=2, label = "Errorbar")
ax.set_title("DCR vs Bias", fontsize = 16)
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("DCR [kHz]", fontsize = 14)
ax.grid()
ax.legend(fontsize = 14)
plt.show()
Avevamo sbagliato l'ultimo bias
lstProb0 = []
lstDCR = []
lstErrDCR = []
lstBias = []
for e in os.scandir(r".\punto3_old"):
if e.name.split(".")[-1] != "txt": continue
#if e.name.split("_")[-1] == "old.txt": continue
if e.name.split("_")[-2] in ("4", "5"): continue
miaFunzione(e.path)
lstBias.append(e.name.split("_")[2])
lstProb0 = np.array(lstProb0)
lstDCR = np.array(lstDCR)
lstBias = np.array(lstBias)
.\punto3_old\MPH_n_54.5_1_histo.txt 0.9764402648308574 156853.3109525504 20709.29444521686 0.023841703264787666 0.00288689030459137
.\punto3_old\MPH_n_54.5_2_histo.txt 0.976294095974947 157838.224447222 23945.48470251787 0.023991410115977743 0.003413662213549343
.\punto3_old\MPH_n_54.5_3_histo.txt 0.9765987300530333 155785.708757777 24249.9874914809 0.023679427731182104 0.00346891251147318
.\punto3_old\MPH_n_55.5_1_histo.txt 0.9653627816214299 231916.50517518757 26594.707726711396 0.035251308786628514 0.0035914767153030244
.\punto3_old\MPH_n_55.5_2_histo.txt 0.9662816972131559 225657.07406736826 26341.53928034441 0.03429987525823998 0.0035738460681959193
.\punto3_old\MPH_n_55.5_3_histo.txt 0.9661748830514574 226384.36052328045 25888.536612205273 0.03441042279953863 0.0034935205458345247
.\punto3_old\MPH_n_55_1_histo.txt 0.9713299721482446 191375.2716040176 23407.42548631121 0.029089041283810676 0.0032116800580818195
.\punto3_old\MPH_n_55_2_histo.txt 0.9728526924788607 181069.75953187665 99279.32683543464 0.027522603448845252 0.015020772032787993
.\punto3_old\MPH_n_55_3_histo.txt 0.9710229875764681 193454.8476639085 26373.936019838682 0.029405136844914095 0.0036980533416664583
.\punto3_old\MPH_n_56.5_1_histo.txt 0.9615038115038115 258268.09104362433 24936.857289809675 0.0392567498386309 0.003177765821830574
.\punto3_old\MPH_n_56.5_2_histo.txt 0.9622225124053277 253352.32359174572 27460.758701039813 0.03850955318594535 0.003648914534806858
.\punto3_old\MPH_n_56.5_3_histo.txt 0.9618264439337998 256060.8967355776 27413.011281266037 0.0389212563038078 0.003628462046458216
.\punto3_old\MPH_n_56_1_histo.txt 0.961904325753016 255528.20224637567 27539.409156406666 0.038840286741449105 0.0036528968652916583
.\punto3_old\MPH_n_56_2_histo.txt 0.9613141285395025 259566.096660209 26996.401977985508 0.03945404669235177 0.0035392591884458786
.\punto3_old\MPH_n_56_3_histo.txt 0.96222810111699 253314.11233329633 26800.504170990265 0.03850374507466105 0.003533848721982756
perm = np.argsort(lstBias)
lstBias = lstBias[perm]
lstDCR = lstDCR[perm]
lstProb0 = lstProb0[perm]
matDCR = np.reshape(lstDCR, (int(len(lstDCR)/3), 3))
matBias = np.reshape(lstBias, (int(len(lstDCR)/3), 3))
matBias
array([['54.5', '54.5', '54.5'], ['55', '55', '55'], ['55.5', '55.5', '55.5'], ['56', '56', '56'], ['56.5', '56.5', '56.5']], dtype='<U4')
vectBias = matBias[:,0]
meanDCR = np.mean(matDCR, axis = 1)
stdDCR = np.std(matDCR, axis = 1)
print (meanDCR)
print(matDCR)
[156825.74805252 188633.29293327 227985.97992195 256136.13707996 255893.77045698] [[156853.31095255 157838.22444722 155785.70875778] [191375.27160402 181069.75953188 193454.84766391] [231916.50517519 225657.07406737 226384.36052328] [255528.20224638 259566.09666021 253314.1123333 ] [258268.09104362 253352.32359175 256060.89673558]]
fig, ax = plt.subplots()
ax.plot(vectBias, meanDCR*1e-3, marker = ".", c = "tab:green", ms = 10, ls = "--", zorder=1, label = "Data")
ax.errorbar(vectBias, meanDCR*1e-3, yerr = stdDCR*1e-3, marker = "", c = "k", ms = 10, ls = "", zorder=2, label = "Errorbar")
ax.set_title("DCR vs Bias", fontsize = 16)
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("DCR [kHz]", fontsize = 14)
ax.grid()
ax.legend(fontsize = 14)
plt.show()