import struct
import os
import sys
import numpy as np
from matplotlib import pyplot as plt
import matplotlib as mpl
import copy
my_cmap = copy.copy(mpl.cm.jet) # copy the default cmap
my_cmap.set_bad(my_cmap(0))
myEvent = np.dtype([
('timestamp', np.dtype('u8')),
('qshort', np.dtype('u2')),
('qlong', np.dtype('u2')),
('baseline', np.dtype('u2')),
('channel', np.dtype('u1')),
('PUR', np.dtype('u1')),
])
with open("abcd_data_2022-05-04T08%3A30%3A27+0000_events.ade", "rb") as f:
myData = np.fromfile(f, dtype = myEvent)
ph = myData["qlong"]
tempi = myData["qshort"]
ch = myData["channel"]
for i,j in enumerate(ch):
if (i)%2 != j:
print("Mannaggia")
# Bene, sono alternati
ph1 = ph[ch==0]
ph2 = ph[ch==1]
tempi1 = tempi[ch==0]
tempi2 = tempi[ch==1]
sogliaPhAlpha = 1100
sogliaPhGamma = 920
fig, ax = plt.subplots(2,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
fig.suptitle("Istogrammi semplici", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1, bins=100, label = "PH alpha", **opts)
ax[1].hist(ph2, bins=100, range=(0,2000), label = "PH gamma", **opts)
ax[2].hist(tempi1, bins=100, label = "Tempo alpha", **opts)
ax[3].hist(tempi2, bins=100, label = "Tempo gamma", **opts)
ax[0].axvline(x = sogliaPhAlpha, c = "k", ls = "--")
ax[1].axvline(x = sogliaPhGamma, c = "k", ls = "--")
for i in ax:
i.set_yscale("log")
i.legend(fontsize = 16)
i.set_ylabel("Entries", fontsize = 14)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(ph1, ph2, bins = 100, range = ((0,2000),(0,1000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni PH", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(tempi1, tempi2, bins = 100, range = ((0,2000),(0,1000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni tempi", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
myLogic = (ph1 > sogliaPhAlpha) & (ph2 > sogliaPhGamma)
fig, ax = plt.subplots(2,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
fig.suptitle("Istogrammi - selezione in PH", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1[myLogic], bins=100, label = "PH alpha", **opts)
ax[1].hist(ph2[myLogic], bins=100, range=(0,2000), label = "PH gamma", **opts)
ax[2].hist(tempi1[myLogic], bins=100, label = "Tempo alpha", **opts)
ax[3].hist(tempi2[myLogic], bins=100, label = "Tempo gamma", **opts)
for i in ax:
i.set_yscale("log")
i.legend(fontsize = 16)
i.set_ylabel("Entries", fontsize = 14)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(ph1[myLogic], ph2[myLogic], bins = 100, range = ((0,2000),(0,2000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni PH", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
with open("241Am_corr_nuova_window_events.ade", "rb") as f:
myData = np.fromfile(f, dtype = myEvent)
ph = myData["qlong"]
tempi = myData["qshort"]
ch = myData["channel"]
for i,j in enumerate(ch):
if (i)%2 != j:
print("Mannaggia")
# Bene, sono alternati
ph1 = ph[ch==0]
ph2 = ph[ch==1]
tempi1 = tempi[ch==0]
tempi2 = tempi[ch==1]
sogliaPhAlpha = 1100
sogliaPhGamma = 750
fig, ax = plt.subplots(2,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
fig.suptitle("Istogrammi semplici", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1, bins=100, label = "PH alpha", **opts)
ax[1].hist(ph2, bins=100, range=(0,2000), label = "PH gamma", **opts)
ax[2].hist(tempi1, bins=100, label = "Tempo alpha", **opts)
ax[3].hist(tempi2, bins=100, label = "Tempo gamma", **opts)
ax[0].axvline(x = sogliaPhAlpha, c = "k", ls = "--")
ax[1].axvline(x = sogliaPhGamma, c = "k", ls = "--")
for i in ax:
i.set_yscale("log")
i.legend(fontsize = 16)
i.set_ylabel("Entries", fontsize = 14)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(ph1, ph2, bins = 100, range = ((0,2000),(0,1000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni PH", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(tempi1, tempi2, bins = 100, range = ((0,2000),(0,1000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni tempi", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
myLogic = (ph1 > sogliaPhAlpha) & (ph2 > sogliaPhGamma)
%matplotlib qt
%matplotlib inline
fig, ax = plt.subplots(3,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
fig.suptitle("Istogrammi - selezione in PH", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1[myLogic], bins=100, label = "PH alpha", **opts)
ax[1].hist(ph2[myLogic], bins=100, range=(0,2000), label = "PH gamma", **opts)
ax[2].hist(tempi1[myLogic], bins=100, label = "Tempo alpha", **opts)
ax[3].hist(tempi2[myLogic], bins=100, label = "Tempo gamma", **opts)
ax[4].hist(tempi1[myLogic], bins=100, label = "Tempo alpha", range = (3140, 3200), **opts)
ax[5].hist(tempi2[myLogic], bins=100, label = "Tempo gamma", range = (3000, 3130), **opts)
for i in ax:
i.set_yscale("log")
i.legend(fontsize = 16)
i.set_ylabel("Entries", fontsize = 14)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(ph1[myLogic], ph2[myLogic], bins = 100, range = ((0,2000),(0,2000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni PH", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
with open("241Am_corr_looong_events.ade", "rb") as f:
myData = np.fromfile(f, dtype = myEvent)
ph = myData["qlong"]
tempi = myData["qshort"]
ch = myData["channel"]
ph1 = ph[ch==0]
ph2 = ph[ch==1]
tempi1 = tempi[ch==0]
tempi2 = tempi[ch==1]
sogliaPhAlpha = 1100
sogliaPhGamma = 750
fig, ax = plt.subplots(2,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
fig.suptitle("Istogrammi semplici", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1, bins=100, label = "PH alpha", **opts)
ax[1].hist(ph2, bins=100, range=(0,2000), label = "PH gamma", **opts)
ax[2].hist(tempi1, bins=100, label = "Tempo alpha", **opts)
ax[3].hist(tempi2, bins=100, label = "Tempo gamma", **opts)
ax[0].axvline(x = sogliaPhAlpha, c = "k", ls = "--")
ax[1].axvline(x = sogliaPhGamma, c = "k", ls = "--")
for i in ax:
i.set_yscale("log")
i.legend(fontsize = 16)
i.set_ylabel("Entries", fontsize = 14)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(ph1, ph2, bins = 100, range = ((0,2000),(0,1000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni PH", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(tempi1, tempi2, bins = 100, range = ((0,2000),(0,1000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni tempi", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
myLogic = (ph1 > sogliaPhAlpha) & (ph2 > sogliaPhGamma)
%matplotlib qt
%matplotlib inline
fig, ax = plt.subplots(3,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
fig.suptitle("Istogrammi - selezione in PH", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1[myLogic], bins=100, label = "PH alpha", **opts)
ax[1].hist(ph2[myLogic], bins=100, range=(0,2000), label = "PH gamma", **opts)
ax[2].hist(tempi1[myLogic], bins=100, label = "Tempo alpha", **opts)
ax[3].hist(tempi2[myLogic], bins=100, label = "Tempo gamma", **opts)
ax[4].hist(tempi1[myLogic], bins=60, label = "Tempo alpha", range = (3140, 3200), **opts)
ax[5].hist(tempi2[myLogic], bins=65, label = "Tempo gamma", range = (3000, 3130), **opts)
for i in ax:
i.set_yscale("log")
i.legend(fontsize = 16)
i.set_ylabel("Entries", fontsize = 14)
plt.show()
fig, ax = plt.subplots()
hh = ax.hist2d(ph1[myLogic], ph2[myLogic], bins = 100, range = ((0,2000),(0,2000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Energia alpha [ADC]", fontsize = 14)
ax.set_ylabel("Energia gamma [ADC]", fontsize = 14)
ax.set_title("Correlazioni PH", fontsize = 16)
fig.colorbar(hh[3], ax = ax)
plt.show()
"""
myLogic = (ph1 > sogliaPhAlpha) & (ph2 > sogliaPhGamma)
"""
tMinAlpha = 3050
tMaxAlpha = 3200
tMinGamma = 3000
tMaxGamma = 3200
%matplotlib qt
%matplotlib inline
fig, ax = plt.subplots(2,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
# fig.suptitle("Istogrammi - selezione in PH", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1[myLogic], bins=100, label = "PH alpha with cut", **opts)
ax[1].hist(ph2[myLogic], bins=100, range=(0,2000), label = "PH gamma with cut", **opts)
ax[2].hist(tempi1[myLogic], bins=100, label = "Time alpha", **opts)
ax[3].hist(tempi2[myLogic], bins=100, label = "Time gamma", **opts)
# ax[4].hist(tempi1[myLogic], bins=60, label = "Tempo alpha", range = (3140, 3200), **opts)
# ax[5].hist(tempi2[myLogic], bins=65, label = "Tempo gamma", range = (3000, 3130), **opts)
ax[2].axvline(x = tMinAlpha, c = "k", ls = "--")
ax[2].axvline(x = tMaxAlpha, c = "k", ls = "--")
ax[3].axvline(x = tMinGamma, c = "k", ls = "--")
ax[3].axvline(x = tMaxGamma, c = "k", ls = "--")
for i in ax:
i.set_yscale("log")
i.set_ylabel("Entries", fontsize = 14)
ax[0].legend(fontsize = 14)
ax[1].legend(fontsize = 14, loc = 'upper left')
ax[2].legend(fontsize = 14, loc = 'upper left')
ax[3].legend(fontsize = 14, loc = 'upper left')
plt.show()
myLogicTime = myLogic & (tempi1 > tMinAlpha) & (tempi1 < tMaxAlpha) & (tempi2 > tMinGamma) & (tempi2 < tMaxGamma)
%matplotlib qt
%matplotlib inline
fig, ax = plt.subplots(2,2)
fig.set_size_inches(16,8)
ax = ax.flatten()
# fig.suptitle("Istogrammi - selezione in PH", fontsize = 16)
opts = {"color":"lime", "edgecolor":"darkgreen","histtype":"stepfilled"}
ax[0].hist(ph1[myLogicTime], bins=100, label = "PH alpha with cut", **opts)
ax[1].hist(ph2[myLogicTime], bins=100, range=(0,2000), label = "PH gamma with cut", **opts)
ax[2].hist(tempi1[myLogicTime], bins=100, label = "Time alpha", **opts)
ax[3].hist(tempi2[myLogicTime], bins=100, label = "Time gamma", **opts)
# ax[4].hist(tempi1[myLogic], bins=60, label = "Tempo alpha", range = (3140, 3200), **opts)
# ax[5].hist(tempi2[myLogic], bins=65, label = "Tempo gamma", range = (3000, 3130), **opts)
# ax[2].axvline(x = tMinAlpha, c = "k", ls = "--")
# ax[2].axvline(x = tMaxAlpha, c = "k", ls = "--")
# ax[3].axvline(x = tMinGamma, c = "k", ls = "--")
# ax[3].axvline(x = tMaxGamma, c = "k", ls = "--")
for i in ax:
i.set_yscale("log")
i.set_ylabel("Entries", fontsize = 14)
ax[0].legend(fontsize = 14)
ax[1].legend(fontsize = 14, loc = 'upper left')
ax[2].legend(fontsize = 14, loc = 'upper left')
ax[3].legend(fontsize = 14, loc = 'upper left')
plt.show()
fig, ax = plt.subplots()
fig.set_size_inches(12,10)
hh = ax.hist2d(ph1[myLogicTime], ph2[myLogicTime], bins = 100, range = ((0,2000),(0,2000)),
norm = mpl.colors.LogNorm(), cmap = my_cmap)
ax.set_xlabel("Alpha energy [ADC]", fontsize = 16)
ax.set_ylabel("Gamma energy [ADC]", fontsize = 16)
ax.set_title("Pulse height correlation plot", fontsize = 20)
fig.colorbar(hh[3], ax = ax)
plt.show()
with open("241Am_corr_timestampNuovi_events.ade", "rb") as f:
myData = np.fromfile(f, dtype = myEvent)
ph = myData["qlong"]
tempi = myData["qshort"]
ch = myData["channel"]
ph1 = ph[ch==0]
ph2 = ph[ch==1]
tempi1 = tempi[ch==0]
tempi2 = tempi[ch==1]
for i in range(30):
print(myData["timestamp"][i])
2913858729 2913858401 2914526093 2914527005 2914761325 2914761820 2918966169 2918963408 2919777624 2919776088 2920133986 2920133089 2924528053 2924526217 2925030162 2925028659 2927098443 2927098881 2928171368 2928168740 2930841845 2930839587 2931255191 2931254974 2932968979 2932966041 2935802486 2935801354 2937842331 2937839510
a = myData["timestamp"][3]
b = myData["timestamp"][2]
print(a,b)
2914527005 2914526093
for i in range(30):
aa = myData["qshort"][2*i]
gg = myData["qshort"][2*i+1]
print(aa-gg if aa>gg else gg-aa)
328 912 495 2761 1536 897 1836 1503 438 2628 2258 217 2938 1132 2821 448 1028 597 2188 394 1643 562 490 632 1433 1699 2827 285 1942 1970
for i in range(30):
aa = myData["timestamp"][2*i]
gg = myData["timestamp"][2*i+1]
print(aa-gg if aa>gg else gg-aa)
328 912 495 2761 1536 897 1836 1503 438 2628 2258 217 2938 1132 2821 448 1028 597 2188 394 1643 562 490 632 1433 1699 2827 285 1942 1970
for i,j in enumerate(ch):
if (i)%2 != j:
print("Mannaggia")
# Bene, sono alternati