Programma base
Analizza tutti i file dati a diversi voltaggi, trova i conteggi fittando i picchi e fa un fit lineare dei risultati in funzione del voltaggio
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize as opt
def gaus(x, A, mu, sigma):
return A*np.exp(-(x-mu)**2/(2*sigma**2))
# prepara per memorizzare i risultati
mean = []
mean_err = []
# figura
fig, axs = plt.subplots(4,4, sharex=True, figsize=(15,10))
# init fit
par0 = [20, 100,10]
bin0 = 7
for i in range(14,30):
datafile = open('dati/run%6.6d.dat' % (i))
a,b,c,counts,time = np.loadtxt(datafile,unpack=True)
rate = 1000*counts/time
h, bins, _ = axs.reshape(16)[i-14].hist(rate,20, range=(75,122), histtype='step', color='k', linewidth=2, label='Run %d'%i)
p, cov = opt.curve_fit(gaus,bins[bin0:-1],h[bin0:],p0=par0 )
par0 = p
errp = np.sqrt(np.diag(cov))
axs.reshape(16)[i-14].plot(bins[bin0:],gaus(bins[bin0:],*p),'--r', linewidth=2, label='fit')
axs.reshape(16)[i-14].legend()
mean.append(p[1])
mean_err.append(errp[2])
plt.show()
volt = np.linspace(350,500, 16)
plt.errorbar(volt,mean,mean_err, label='dati')
p = np.polyfit(volt,mean,1)
plt.plot(volt,p[1]+p[0]*volt,'r--', label='y=%.3f*x+%.3f' % (p[0],p[1]))
plt.title('Conteggi vs voltaggio')
plt.xlabel('Volt')
plt.ylabel('Conteggi')
plt.legend()
plt.show()