Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri May 7 09:37:02 2021
- Autore: Stefano Carsi
- Data ultima modifica: 202105111551
- - Cosa ho fatto:
- *
- - Cosa devo fare:
- *
- - Per relazione:
- *
- > 1 = Spesso
- > 2 = Sottile
- > L'ADC è a 14 bit: va da 0 a 16384-1
- + Perchè non vediamo il 136 in quello spesso? Saturazione positiva?
- """
- #INIZIO STANDARD
- %matplotlib inline
- import matplotlib.pyplot as plt
- import numpy as np
- import matplotlib as mpl
- from scipy.optimize import curve_fit
- import copy
- from matplotlib.patches import Rectangle
- import os
- path = r"F:\Corsi\Laboratorio 4 - Fisica nucleare e subnucleare\4 - Co-57\PITONE"
- os.chdir(path)
- Export = False
- #%% Carico i dati
- nev, time, ADC1, time1, ADC2, time2 = \
- np.loadtxt(r"..\DATI\run020006.dat", unpack=True)#, dtype=np.int32)
- #dati = np.loadtxt(r"..\DATI\run020006.dat")
- # Il tempo è in tick: 1tick=2ns ==> Converto il tempo in ns
- time1 *= 2
- time2 *= 2
- #%% Plotto gli istogrammi brutti
- range1 = (2500,14000)
- range2 = (200,14000)
- binnn1 = 200 # In origine era 250
- binnn2 = 250
- # Sopra i 14000 c'è la saturazione?
- h1, bins1 = np.histogram(ADC1, bins = binnn1, range = range1)
- h2, bins2 = np.histogram(ADC2, bins = binnn2, range = range2)
- binc1 = bins1[:-1] + bins1[1] - bins1[0]
- binc2 = bins2[:-1] + bins2[1] - bins2[0]
- fig, ax = plt.subplots(2, 1)#, sharex=True)
- #fig.subplots_adjust(hspace=0)
- fig.set_size_inches(12,5)
- fig.suptitle("Istogrammi individuali", fontsize=16)
- ax[0].plot(binc1, h1, ds="steps-mid", label = "Istogramma spesso")
- ax[1].plot(binc2, h2, ds="steps-mid", label = "Istogramma sottile")
- for i in range(2):
- ax[i].grid()
- ax[i].legend(fontsize=14)
- ax[i].set_ylabel("Entries", fontsize=14)
- ax[i].set_xlabel("ADC", fontsize=14)
- fig.subplots_adjust(hspace=.4)
- if Export:
- plt.savefig('../RELAZIONE/FIGURE/istogrammi-brutti.eps', format='eps')
- plt.show()
- #%% Plotto l'istogramma bidimensionale
- # Esistono problemi con i pixels zero: li risolvo
- my_cmap = copy.copy(mpl.cm.viridis) # copy the default cmap
- my_cmap.set_bad(my_cmap.colors[0])
- fig, ax = plt.subplots()
- fig.set_size_inches(12,5)
- ax.set_title("Istogramma bidimensionale", fontsize=16)
- myPlot = ax.hist2d(ADC1, ADC2, bins = (binnn1, binnn2), range = (range1, range2),
- norm = mpl.colors.LogNorm(), cmap = my_cmap)
- ax.set_xlabel("Rivelatore spesso (ADC)", fontsize = 14)
- ax.set_ylabel("Rivelatore sottile (ADC)", fontsize = 14)
- fig.colorbar(myPlot[3])
- if Export:
- plt.savefig('../RELAZIONE/FIGURE/istogramma-2d.eps', format='eps')
- plt.show()
- #%% Proviamo il contour
- xcentr = myPlot[1][:-1] + myPlot[1][1] - myPlot[1][0]
- ycentr = myPlot[2][:-1] + myPlot[2][1] - myPlot[2][0]
- fig, ax = plt.subplots()
- fig.set_size_inches(12,5)
- ax.set_title("Curve di livello (Contour)", fontsize=16)
- ax.set_xlabel("Rivelatore spesso (ADC)", fontsize = 14)
- ax.set_ylabel("Rivelatore sottile (ADC)", fontsize = 14)
- myContour = ax.contour(*np.meshgrid(xcentr, ycentr, indexing = "ij"),
- myPlot[0], levels = range(20,200,20))#np.logspace(1,2.3,5))
- rect1 = Rectangle((2840,10850), width = 900, height = 2400,
- ec='tab:green', fc='none', lw = 3)
- rect2 = Rectangle((8663,3470), width = 1200, height = 1400,
- ec='tab:green', fc='none', lw = 3)
- rect3 = Rectangle((10500,490), width = 3000, height = 800,
- ec='tab:green', fc='none', lw = 3)
- rect4 = Rectangle((10500,1600), width = 3000, height = 1050,
- ec='tab:red', fc='none', lw = 3)
- rectList = (rect1, rect2, rect3, rect4)
- ax.add_patch(rect1)
- ax.add_patch(rect2)
- ax.add_patch(rect3)
- ax.add_patch(rect4)
- fig.colorbar(myContour)
- # Stampo i rettangoloni
- plt.annotate("1", xytext=(5500, 9500), xy=(4000, 12000), xycoords='data',
- arrowprops=dict(arrowstyle="fancy",
- connectionstyle="arc3, rad=.3", color="tab:green"),
- c="tab:green", size=50)
- plt.annotate("2", xytext=(10500, 7000), xy=(9000, 5000), xycoords='data',
- arrowprops=dict(arrowstyle="fancy",
- connectionstyle="arc3, rad=.6", color="tab:green"),
- c="tab:green", size=50)
- plt.annotate("3", xytext=(6000, 4000), xy=(10300, 1000), xycoords='data',
- arrowprops=dict(arrowstyle="fancy",
- connectionstyle="arc3, rad=.3", color="tab:green"),
- c="tab:green", size=50)
- plt.annotate("4", xytext=(13000, 4000), xy=(12000, 3000), xycoords='data',
- arrowprops=dict(arrowstyle="fancy",
- connectionstyle="arc3, rad=.6", color="tab:red"),
- c="tab:red", size=50)
- if Export:
- plt.savefig('../RELAZIONE/FIGURE/contour.eps', format='eps')
- plt.show()
- #%%
- """
- in ogni rettangolo devo proiettare sui due assi e fittare con una gaussiana
- """
- #%% Fit gaussiani
- def gauss(x,a,mu,sigma):
- return a/(sigma*np.sqrt(2*np.pi)) * np.exp(-(x-mu)**2/(2*(sigma**2)))
- lista_popt = []
- lista_pcov = []
- lista_chi2 = []
- def calibra(idxRect, startingPts):
- myRect = rectList[idxRect]
- startx = myRect.get_x()
- endx = startx + myRect.get_width()
- idx_startx = np.where(xcentr >= startx)[0][0]
- idx_endx = np.where(xcentr >= endx)[0][0]
- starty = myRect.get_y()
- endy = starty + myRect.get_height()
- idx_starty = np.where(ycentr >= starty)[0][0]
- idx_endy = np.where(ycentr >= endy)[0][0]
- subdata = myPlot[0][ idx_startx:idx_endx , idx_starty:idx_endy]
- subdata_sqrt = np.sqrt(subdata)
- # *** EFFETTUO LE PROIEZIONI ***
- # Alla terza riga proietto per tutta la colonna/riga, di cui il
- # rettangolo è intersezione
- # Quello che vede il rivelatore sottile, proietto a sx
- proiez_sottile = np.sum(subdata, axis = 0)
- proiez_sottile_sqrt = np.sqrt(np.sum(subdata_sqrt**2, axis = 0))
- proiez_sottile_completo = np.sum( myPlot[0][idx_startx:idx_endx , :], axis = 0)
- # Quello che vede il rivelatore spesso, proietto sotto
- proiez_spesso = np.sum(subdata, axis = 1)
- proiez_spesso_sqrt = np.sqrt(np.sum(subdata_sqrt**2, axis = 1))
- proiez_spesso_completo = np.sum( myPlot[0][:, idx_starty:idx_endy], axis = 1)
- # Ottengo le x delle proiezioni
- vect_spesso = np.array([i for i in xcentr if (i >= startx) & (i<=endx)])
- vect_sottile = np.array([i for i in ycentr if (i >= starty) & (i<=endy)])
- # fitto con gaussiane
- popt_spesso, pcov_spesso = curve_fit(gauss, vect_spesso, proiez_spesso,
- sigma = proiez_spesso_sqrt,
- p0 = startingPts[0])
- popt_sottile, pcov_sottile = curve_fit(gauss, vect_sottile, proiez_sottile,
- sigma = proiez_sottile_sqrt,
- p0 = startingPts[1])
- lista_popt.append([popt_spesso, popt_sottile])
- lista_pcov.append([pcov_spesso, pcov_sottile])
- # *** LO PLOTTO ***
- fig, ax = plt.subplots(2, 1)#, sharex=True)
- #fig.subplots_adjust(hspace=0)
- fig.set_size_inches(12,5)
- fig.subplots_adjust(hspace=.4)
- fig.suptitle(f"Regione {idxRect+1}", fontsize=16)
- # Plotto le proiezioni (tanto dopo si vede già tutto)
- #ax[0].plot(vect_spesso, proiez_spesso, label = "Proiezione rivelatore spesso")
- #ax[1].plot(vect_sottile, proiez_sottile, label = "Proiezione rivelatore sottile")
- # Plotto la somma su tutta la striscia
- ax[0].plot(xcentr, proiez_spesso_completo,
- label = "Proiezione rivelatore spesso")
- ax[1].plot(ycentr, proiez_sottile_completo,
- label = "Proiezione rivelatore sottile")
- # Plotto le curve fittate
- ax[0].plot(vect_spesso, gauss(vect_spesso, *popt_spesso), ":k",
- label = "Curva fittata")
- ax[1].plot(vect_sottile, gauss(vect_sottile, *popt_sottile), ":k",
- label = "Curva fittata")
- # delimito le regioni di fit
- ax[0].axvline(x=startx, ls="--", c="grey")
- ax[0].axvline(x=endx, ls="--", c="grey")
- ax[1].axvline(x=starty, ls="--", c="grey")
- ax[1].axvline(x=endy, ls="--", c="grey")
- for i in range(2):
- ax[i].grid()
- ax[i].legend(fontsize=14)
- ax[i].set_ylabel("Entries", fontsize=14)
- ax[i].set_xlabel("ADC", fontsize=14)
- if Export:
- plt.savefig(f'../RELAZIONE/FIGURE/fit-gauss-{idxRect}.eps', format='eps')
- plt.show()
- mychi2_spesso = np.sum(((proiez_spesso-gauss(vect_spesso, *popt_spesso))/proiez_spesso_sqrt)**2) / (len(proiez_spesso)-3)
- mychi2_sottile = np.sum(((proiez_sottile-gauss(vect_sottile, *popt_sottile))/proiez_sottile_sqrt)**2) / (len(proiez_sottile)-3)
- lista_chi2.append([mychi2_spesso, mychi2_sottile])
- calibra(0, ((100, 3300, 400), (60, 12000, 2000))) # Regione 1
- calibra(1, ((100, 12000, 2000), (60, 2100, 700))) # Regione 2
- calibra(2, ((100, 12000, 2000), (60, 2100, 700))) # Regione 3
- calibra(3, ((100, 12000, 2000), (60, 2100, 700))) # Regione 4
- #%% Rette di calibrazione
- def line(x,a,b):
- return a*x+b
- picchiVeriSpesso = np.array((29, 93, 122, 122))
- picchiVeriSottile = np.array((93, 29, 6.4, 14.4))
- picchiSpesso = np.array([i[0][1] for i in lista_popt])
- sigmaSpesso = np.array([i[0][2] for i in lista_popt])
- errPicchiSpesso = np.array([np.sqrt(i[0][1,1]) for i in lista_pcov])
- picchiSottile = np.array([i[1][1] for i in lista_popt])
- sigmaSottile = np.array([i[1][2] for i in lista_popt])
- errPicchiSottile = np.array([np.sqrt(i[1][1,1]) for i in lista_pcov])
- # fit lineari
- popt1, pcov1 = curve_fit(line, picchiVeriSpesso, picchiSpesso,
- sigma = sigmaSpesso)
- popt2, pcov2 = curve_fit(line, picchiVeriSottile, picchiSottile,
- sigma = sigmaSottile)
- fig, ax = plt.subplots(1,2)#, sharex=True)
- fig.subplots_adjust(wspace=.3)
- fig.set_size_inches(12,5)
- # Plotto i punti
- ax[0].errorbar(picchiVeriSpesso, picchiSpesso, fmt=".",
- yerr = sigmaSpesso, label = "Dati" )
- ax[1].errorbar(picchiVeriSottile, picchiSottile, fmt=".",
- yerr = sigmaSottile, label = "Dati" )
- # Plotto le curve fittate
- ax[0].plot(picchiVeriSpesso, line(picchiVeriSpesso, *popt1), ":k")
- ax[1].plot(picchiVeriSottile, line(picchiVeriSottile, *popt2), ":k")
- ax[0].set_title("Rivelatore spesso", fontsize = 16)
- ax[1].set_title("Rivelatore sottile", fontsize = 16)
- for i in range(2):
- ax[i].grid()
- ax[i].legend(fontsize=14)
- ax[i].set_ylabel("Picchi fittati (ADC)", fontsize=14)
- ax[i].set_xlabel("Picchi veri (keV)", fontsize=14)
- if Export:
- plt.savefig(f'../RELAZIONE/FIGURE/retta-cal.eps', format='eps')
- plt.show()
- myChi2_Spesso = np.sum((( picchiSpesso - line(picchiVeriSpesso, *popt1)) /sigmaSpesso )**2) / (len(picchiVeriSpesso)-2)
- myChi2_Sottile = np.sum((( picchiSottile - line(picchiVeriSottile, *popt1)) /sigmaSottile )**2) / (len(picchiVeriSottile)-2)
- print(f"Chi2 spesso: {myChi2_Spesso}")
- print(f"Chi2 sottile: {myChi2_Sottile}")
- #%% Stampo la tabella con i parametri delle gaussiane
- # Spesso
- for i in range(len(lista_popt)):
- print(f"\t& {i+1}\t& {lista_popt[i][0][1]:.2f}\t& {np.sqrt(lista_pcov[i][0][1,1]):.2f}\t& {lista_popt[i][0][2]:.2f}\t& {np.sqrt(lista_pcov[i][0][2,2]):.2f}\t& {lista_chi2[i][0]:.2f} \\\\")
- print("\n")
- # Sottile
- for i in range(len(lista_popt)):
- print(f"\t& {i+1}\t& {lista_popt[i][1][1]:.2f}\t& {np.sqrt(lista_pcov[i][1][1,1]):.2f}\t& {lista_popt[i][1][2]:.2f}\t& {np.sqrt(lista_pcov[i][1][2,2]):.2f}\t& {lista_chi2[i][1]:.2f} \\\\")
- #%% NON LA METTIAMO Stampo una tabella con i picchi veri, quelli fittati in kev e errore
- # picco fittato kev, errore, picco vero
- err_retta = lambda x,dx,m,dm,q,dq : np.sqrt((x*dm)**2 + (m*dx)**2 + dq**2)
- # Spesso
- m = 1/popt1[0]
- q = -popt1[1]/popt1[0]
- errm = (1/(m**2)) * np.sqrt(pcov1[0,0])
- errq = np.sqrt((np.sqrt(pcov1[1,1]/m))**2 + ((q/(m**2))*np.sqrt(pcov1[0,0]))**2)
- for i in range(len(lista_popt)):
- print(f"\t& {picchiVeriSpesso[i]}\t& {line(lista_popt[i][0][1], m, q):.2f}\t& {err_retta(picchiSpesso[i],errPicchiSpesso[i],m,errm,q,errq):.2f} \\\\")
- # Sottile
- m = 1/popt2[0]
- q = -popt2[1] / popt2[0]
- errm = (1/(m**2)) * np.sqrt(pcov2[0,0])
- errq = np.sqrt((np.sqrt(pcov2[1,1]/m))**2 + ((q/(m**2))*np.sqrt(pcov2[0,0]))**2)
- for i in range(len(lista_popt)):
- print(f"\t& {picchiVeriSottile[i]}\t& {line(lista_popt[i][1][1], m, q):.2f}\t& {err_retta(picchiSottile[i],errPicchiSottile[i],m,errm,q,errq):.2f} \\\\")
- #%% Disegno le regioni considerate
- myRect = rectList[3]
- startx = myRect.get_x()
- endx = startx + myRect.get_width()
- idx_startx = np.where(xcentr >= startx)[0][0]
- idx_endx = np.where(xcentr >= endx)[0][0]
- starty = myRect.get_y()
- endy = starty + myRect.get_height()
- idx_starty = np.where(ycentr >= starty)[0][0]
- idx_endy = np.where(ycentr >= endy)[0][0]
- subdata = myPlot[0][ idx_startx:idx_endx , idx_starty:idx_endy]
- subdata_sqrt = np.sqrt(subdata)
- # Quello che vede il rivelatore sottile, proietto a sx
- proiez_sottile = np.sum(subdata, axis = 0)
- proiez_sottile_sqrt = np.sqrt(np.sum(subdata_sqrt**2, axis = 0))
- # Quello che vede il rivelatore spesso, proietto sotto
- proiez_spesso = np.sum(subdata, axis = 1)
- proiez_spesso_sqrt = np.sqrt(np.sum(subdata_sqrt**2, axis = 1))
- vect_spesso = np.array([i for i in xcentr if (i >= startx) & (i<=endx)])
- vect_sottile = np.array([i for i in ycentr if (i >= starty) & (i<=endy)])
- # fitto con gaussiane
- popt_spesso, pcov_spesso = curve_fit(gauss, vect_spesso, proiez_spesso,
- sigma = proiez_spesso_sqrt,
- p0 = lista_popt[3][0])
- popt_sottile, pcov_sottile = curve_fit(gauss, vect_sottile, proiez_sottile,
- sigma = proiez_sottile_sqrt,
- p0 = lista_popt[3][1])
- fig, ax = plt.subplots(2, 1)#, sharex=True)
- fig.subplots_adjust(hspace=.4)
- fig.set_size_inches(12,5)
- fig.suptitle(f"Regione 4 - aree per calcolo lifetime", fontsize=16)
- # Plotto le proiezioni
- ax[0].plot(vect_spesso, proiez_spesso, "k", label = "Proiezione rivelatore spesso")
- ax[1].plot(vect_sottile, proiez_sottile, "k", label = "Proiezione rivelatore sottile")
- # Plotto le curve fittate
- ax[0].plot(vect_spesso, gauss(vect_spesso, *popt_spesso), ":k",
- label = "Curva fittata")
- ax[1].plot(vect_sottile, gauss(vect_sottile, *popt_sottile), ":k",
- label = "Curva fittata")
- # Parte nuova
- # Disegno delle linee ad 1 sigma
- ax[0].axvline(lista_popt[3][0][1], ls = "--", c="grey")
- ax[0].axvline(lista_popt[3][0][1] + .75*lista_popt[3][0][2], ls = "--", c="tab:blue", label = "0.75 Sigma")
- ax[0].axvline(lista_popt[3][0][1] - .75*lista_popt[3][0][2], ls = "--", c="tab:blue")
- ax[0].axvline(lista_popt[3][0][1] + 1*lista_popt[3][0][2], ls = "--", c="tab:orange", label = "1 Sigma")
- ax[0].axvline(lista_popt[3][0][1] - 1*lista_popt[3][0][2], ls = "--", c="tab:orange")
- ax[0].axvline(lista_popt[3][0][1] + 1.25*lista_popt[3][0][2], ls = "--", c="tab:green", label = "1.25 Sigma")
- ax[0].axvline(lista_popt[3][0][1] - 1.25*lista_popt[3][0][2], ls = "--", c="tab:green")
- ax[0].axvline(lista_popt[3][0][1] + 1.5*lista_popt[3][0][2], ls = "--", c="tab:red", label = "1.5 Sigma")
- ax[0].axvline(lista_popt[3][0][1] - 1.5*lista_popt[3][0][2], ls = "--", c="tab:red")
- ax[1].axvline(lista_popt[3][1][1], ls = "--", c="grey")
- ax[1].axvline(lista_popt[3][1][1] + .75*lista_popt[3][1][2], ls = "--", c="tab:blue", label = "0.75 Sigma")
- ax[1].axvline(lista_popt[3][1][1] - .75*lista_popt[3][1][2], ls = "--", c="tab:blue")
- ax[1].axvline(lista_popt[3][1][1] + 1*lista_popt[3][1][2], ls = "--", c="tab:orange", label = "1 Sigma")
- ax[1].axvline(lista_popt[3][1][1] - 1*lista_popt[3][1][2], ls = "--", c="tab:orange")
- ax[1].axvline(lista_popt[3][1][1] + 1.25*lista_popt[3][1][2], ls = "--", c="tab:green", label = "1.25 Sigma")
- ax[1].axvline(lista_popt[3][1][1] - 1.25*lista_popt[3][1][2], ls = "--", c="tab:green")
- ax[1].axvline(lista_popt[3][1][1] + 1.5*lista_popt[3][1][2], ls = "--", c="tab:red", label = "1.5 Sigma")
- ax[1].axvline(lista_popt[3][1][1] - 1.5*lista_popt[3][1][2], ls = "--", c="tab:red")
- for i in range(2):
- ax[i].grid()
- ax[i].legend(fontsize=10)
- ax[i].set_ylabel("Conteggi", fontsize=14)
- ax[i].set_xlabel("ADC", fontsize=14)
- if Export:
- plt.savefig(f'../RELAZIONE/FIGURE/aree.eps', format='eps')
- plt.show()
- #%% =================================================================
- #%% Da qui si calcola la lifetime
- def myExp(x,a,tau):
- return a*np.exp(-x/tau)
- listaSigme = []
- listaLifetime = []
- listaErrLifetime = []
- nuovalistachi2 = []
- def calcolaLifetime(nsigma, altezza, numBins):
- ADC1_min = lista_popt[3][0][1] - nsigma*lista_popt[3][0][2]
- ADC1_max = lista_popt[3][0][1] + nsigma*lista_popt[3][0][2]
- ADC2_min = lista_popt[3][1][1] - nsigma*lista_popt[3][1][2]
- ADC2_max = lista_popt[3][1][1] + nsigma*lista_popt[3][1][2]
- listaTempi = []
- for i in range(len(time)):
- if (ADC1[i] >= ADC1_min) & (ADC1[i] <= ADC1_max) & \
- (ADC2[i] >= ADC2_min) & (ADC2[i] <= ADC2_max) :
- listaTempi.append(np.abs(time1[i] - time2[i]))
- listaTempi = np.array(listaTempi)
- h, bins = np.histogram(listaTempi, bins=numBins)
- binc = bins[:-1] + bins[1] - bins[0]
- plt.plot(binc, h, ds = "steps-mid", label = f"Sigma = {nsigma}")
- # fitto con un exp
- condizione = binc > 480
- xVect = binc[condizione]
- yVect = h[condizione]
- popt, pcov = curve_fit(myExp, xVect, yVect, sigma = np.sqrt(yVect),
- p0 = [altezza, 1.41920784e+02])
- plt.plot(xVect, myExp(xVect,*popt), ls = ":", c="k")
- print(f"Sigma: {nsigma} - Vita media: {popt[1]} più o meno {np.sqrt(pcov[1,1])}")
- listaSigme.append(nsigma)
- listaLifetime.append(popt[1])
- listaErrLifetime.append(np.sqrt(pcov[1,1]))
- # calcolo i chi2
- tmpchi2 = np.sum(( (yVect - myExp(xVect,*popt)) / np.sqrt(yVect) )**2)/(len(yVect)-2)
- nuovalistachi2.append(tmpchi2)
- # Calcolo le lifetime
- plt.figure(figsize=(12,5))
- plt.title(f"Lifetime", fontsize=16)
- calcolaLifetime(.75, 1.59507942e+05, 45)
- calcolaLifetime(1, 1.59507942e+05, 45)
- calcolaLifetime(1.25, 1.59507942e+05, 40)
- calcolaLifetime(1.5, 1.59507942e+05, 45)
- plt.xlabel("Delta time (ns)", fontsize=14)
- plt.ylabel("Entries", fontsize=14)
- plt.legend(fontsize=14)
- plt.grid()
- if Export:
- plt.savefig(r'../RELAZIONE/FIGURE/lifetime.eps', format='eps')
- plt.show()
- listaSigme = np.array(listaSigme)
- listaLifetime = np.array(listaLifetime)
- listaErrLifetime = np.array(listaErrLifetime)
- # Testo la compatibilità con 141
- Zvect = np.abs(141-listaLifetime)/listaErrLifetime
- #%% Stampatabella lifetime
- for i in range(len(listaSigme)):
- print(f"{listaSigme[i]}\t& {listaLifetime[i]:.2f}\t& {listaErrLifetime[i]:.2f}\t& {Zvect[i]:.2f}\t& {nuovalistachi2[i]:.2f} \\\\")
- #%% Calcolo la lifetime in modo bruttocon anche tutti i dati
- """
- Al plot di prima sovrapponiamo anche l'istogramma complessivo dei tempi
- """
- def calcolaLifetimebrutta(nsigma, altezza, numBins, primo=False):
- ADC1_min = lista_popt[3][0][1] - nsigma*lista_popt[3][0][2]
- ADC1_max = lista_popt[3][0][1] + nsigma*lista_popt[3][0][2]
- ADC2_min = lista_popt[3][1][1] - nsigma*lista_popt[3][1][2]
- ADC2_max = lista_popt[3][1][1] + nsigma*lista_popt[3][1][2]
- listaTempi = []
- listaTempiBrutto = []
- for i in range(len(time)):
- if (ADC1[i] >= ADC1_min) & (ADC1[i] <= ADC1_max) & \
- (ADC2[i] >= ADC2_min) & (ADC2[i] <= ADC2_max) :
- listaTempi.append(np.abs(time1[i] - time2[i]))
- if primo:
- for i in range(len(time)):
- listaTempiBrutto.append(np.abs(time1[i] - time2[i]))
- listaTempi = np.array(listaTempi)
- if primo:
- hb, binsb = np.histogram(listaTempiBrutto, bins=100)
- bincb = binsb[:-1] + binsb[1] - binsb[0]
- plt.plot(bincb, hb, ds = "steps-mid", label = f"Complessivo", c="k")
- h, bins = np.histogram(listaTempi, bins=numBins)
- binc = bins[:-1] + bins[1] - bins[0]
- plt.plot(binc, h, ds = "steps-mid", label = f"Sigma = {nsigma}")
- # Calcolo le lifetime
- plt.figure(figsize=(12,5))
- plt.title(f"Lifetime", fontsize=16)
- calcolaLifetimebrutta(.75, 1.59507942e+05, 45, True)
- calcolaLifetimebrutta(1, 1.59507942e+05, 45)
- calcolaLifetimebrutta(1.25, 1.59507942e+05, 40)
- calcolaLifetimebrutta(1.5, 1.59507942e+05, 45)
- plt.xlabel("Delta time (ns)", fontsize=14)
- plt.ylabel("Entries", fontsize=14)
- plt.legend(fontsize=14)
- plt.yscale("log")
- plt.grid()
- if Export:
- plt.savefig(r'../RELAZIONE/FIGURE/lifetime-brutto.eps', format='eps')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement