# Import dei pacchetti
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
gate = np.arange(72,240,8)
d12 = np.array([527, 543 , 583 , 590 , 606, 622, 630, 638, 638, 639, 639, 646, 637, 647, 645, 645, 645, 647, 653, 651 , 650]) # 654 , 654 , 662])
err_y = np.ones(d12.size)*np.sqrt(2)
def f(x,a,b,c):
return a * (1-c*np.exp(- x / b ))
p0 = np.array([660 , 5, 1])
popt, optcov = curve_fit(f, gate, d12, p0 = p0 , sigma= err_y, absolute_sigma = True)
a,b,c = popt
y_new = f(gate, a, b, c)
var = b*5
window = gate[np.argmin(np.abs(gate-var))]
b
28.007232711825907
plt.figure()#figsize=(13, 8))
plt.title("Stima gate ottimale", fontsize = 16)
plt.grid('True', alpha = 0.3)
plt.ylabel("$\Delta pp_{21}$ [ADC]", fontsize = 14)
plt.xlabel("Gate [ns]", fontsize = 14)
plt.errorbar(gate, d12 , err_y, linestyle = '', marker = '*', label = 'Dati')
plt.plot(gate, y_new , linestyle = '--' , color = 'red', label = 'Fit')
plt.vlines(window,d12.min() - 10, d12.max()+ 30,linestyle = '-.', linewidth = 0.75, color = 'black', label = 'Finestra di integrazione ideale')
plt.legend(loc = "lower right", fontsize = 14)
plt.ylim(d12.min()-3,d12.max()+3)
plt.show()
window,d12.min() - 10
err_tau = np.sqrt(np.diag(optcov))[1]
print(b, '+-' , err_tau )
myChi2 = np.sqrt(np.sum(((d12-f(gate, *popt))/err_y )**2)) / (len(d12) - len(popt) )
print(myChi2)
28.007232711825907 +- 0.5720147269230895 0.7795466307163548
d34 = np.array([519 , 536 , 559 , 590 , 598, 615, 614, 629, 622, 622, 637, 630, 645, 637, 645, 653, 646, 654, 654, 653 , 660])# 661 , 661 , 653])
p0 = np.array([660 , 5, 1])
popt34, optcov34 = curve_fit(f, gate, d34, p0 = p0 , sigma= err_y, absolute_sigma = False)
a34,b34,c34 = popt34
y_new34 = f(gate, a34, b34, c34)
var34 = b34*5
window34 = gate[np.argmin(np.abs(gate-var34))]
plt.figure()#figsize=(13, 8))
plt.title("Stima gate ottimale", fontsize = 16)
plt.grid('True', alpha = 0.3)
plt.ylabel("$\Delta pp_{43}$ [ADC]", fontsize = 14)
plt.xlabel("Gate [ns]", fontsize = 14)
plt.errorbar(gate, d34 , err_y, linestyle = '', marker = '*', label = 'Dati')
plt.plot(gate, y_new34 , linestyle = '--' , color = 'red', label = 'Fit')
plt.vlines(window34,d34.min(), d34.max(),linestyle = '-.', color = 'black', label = 'Finestra di integrazione ideale')
plt.legend(loc = "lower right", fontsize = 14)
plt.show()
print(b34)
myChi2 = np.sqrt(np.sum(((d34-f(gate, *popt34))/err_y )**2)) / (len(d34) - len(popt34) )
print(myChi2)
38.659303354418746 1.087271274639762
err_tau34 = np.sqrt(np.diag(optcov34))[1]
print(b34, '+-' , err_tau34 )
38.659303354418746 +- 3.6815694832389663