import numpy as np
import sys, os, re, glob
import uproot
from matplotlib import pyplot as plt
import matplotlib as mpl
path = "/eos/project/i/insulab-como/testBeam/TB_2023_10_T9_OREO/H2ROOT_NEW"
numRun = 720258
nameFile = f"run{numRun}_00001.root"
# nameFile = f"run{numRun}_00003.root"
nameFile = f"run{numRun}_00009.root"
fileToLoad = os.path.join(path, nameFile)
Carico i dati del primo 1742
with uproot.open(fileToLoad)["h3"] as f:
f.show()
for k in f:
print(k)
Nwdigi_742a = f["Nwdigi_742a"].arrays(library = "np")["Nwdigi_742a"]
Idigi_742a = f["Idigi_742a"].arrays(library = "np")["Idigi_742a"]
print(Nwdigi_742a.shape, Idigi_742a.shape)
# Condizione da soddisfare, (direi che è sempre vera)
conda = (Nwdigi_742a == 32992)#32992)
print(f"Good events: {conda.sum()}\nTotal: {conda.shape}")
#Nwdigi_742a = Nwdigi_742a[conda]
Idigi_742a = Idigi_742a[conda]
name | typename | interpretation ---------------------+--------------------------+------------------------------- Idigi3 | int32_t | AsDtype('>i4') Idtime3 | int32_t | AsDtype('>i4') Idatime3 | int32_t | AsDtype('>i4') Nwdigi_742a | uint16_t | AsDtype('>u2') Idigi_742a | uint16_t[40000] | AsDtype("('>u2', (40000,))") Nwfast_742a | uint16_t | AsDtype('>u2') Idigifast_742a | uint16_t[4112] | AsDtype("('>u2', (4112,))") Ifast_base742a | int32_t[32] | AsDtype("('>i4', (32,))") Ifast_time742a | int32_t[32] | AsDtype("('>i4', (32,))") Ifast_time50_742a | int32_t[32] | AsDtype("('>i4', (32,))") Ifast_ph742a | int32_t[32] | AsDtype("('>i4', (32,))") Iev_wri_a | int32_t | AsDtype('>i4') Iev_rd_a | int32_t | AsDtype('>i4') <TBranch 'Idigi3' at 0x7fb9c0514af0> <TBranch 'Idtime3' at 0x7fb9ab9517c0> <TBranch 'Idatime3' at 0x7fb9abd12b20> <TBranch 'Nwdigi_742a' at 0x7fba42f260a0> <TBranch 'Idigi_742a' at 0x7fba403f2af0> <TBranch 'Nwfast_742a' at 0x7fba42a9dca0> <TBranch 'Idigifast_742a' at 0x7fba42f1e760> <TBranch 'Ifast_base742a' at 0x7fb9abce4c70> <TBranch 'Ifast_time742a' at 0x7fba42452460> <TBranch 'Ifast_time50_742a' at 0x7fba42f3b2e0> <TBranch 'Ifast_ph742a' at 0x7fba4046d640> <TBranch 'Iev_wri_a' at 0x7fba42aa4160> <TBranch 'Iev_rd_a' at 0x7fb9ab954b50> (57,) (57, 40000) Good events: 57 Total: (57,)
print(type(Idigi_742a))
print(Idigi_742a.shape, Idigi_742a.dtype)
<class 'numpy.ndarray'> (57, 40000) uint16
# Parametri caratteristici che ho appena descritto sopra
nPtsDigi = 1024
nWordSingleChannel = 5+nPtsDigi+2
nChannels = 32
def getWaveform(matrice, canale, evento):
"""
matrice: matrice dei dati
canale: numero di canale, contando da 0
evento: numero di evento (riga), contando da 0
"""
i = evento
j = canale
return matrice[i, (5 + nWordSingleChannel*j) : (5 + nWordSingleChannel*j + nPtsDigi)]
Vero plot interessante: sovrappongo tutte le waveform
Idigi_742a.shape
(57, 40000)
Idigipack_742a = Idigi_742a[:, :nChannels*nWordSingleChannel].reshape(Idigi_742a.shape[0], nChannels, nWordSingleChannel)[:,:,5:5+nPtsDigi ]
iChan = 2
fig, ax = plt.subplots(8,4)
fig.set_size_inches(60, 40)
ax = ax.flatten()
for i in range(32):
iChan = i
# Ripeto 0..512 per il numero di eventi (Idigipack.shape[0])
hh = ax[i].hist2d(np.tile(np.arange(nPtsDigi),Idigipack_742a.shape[0]),
Idigipack_742a[:,iChan,:].flatten(),
bins=(nPtsDigi,50), norm=mpl.colors.LogNorm(), cmap = "jet")
ax[i].set_title(f"Chan {iChan}", fontsize = 40)
fig.colorbar(hh[3], ax = ax[i])
plt.show()
Attenzione: leggo solo 16 canali
with uproot.open(fileToLoad)["h4"] as f:
f.show()
for k in f:
print(k)
Nwdigi_742b = f["Nwdigi_742b"].arrays(library = "np")["Nwdigi_742b"]
Idigi_742b = f["Idigi_742b"].arrays(library = "np")["Idigi_742b"]
print(Nwdigi_742b.shape, Idigi_742b.shape)
# Condizione da soddisfare, (direi che è sempre vera)
conda = (Nwdigi_742b == 32992/2)#32992)
print(f"Good events: {conda.sum()}\nTotal: {conda.shape}")
#Nwdigi_742a = Nwdigi_742a[conda]
Idigi_742b = Idigi_742b[conda]
name | typename | interpretation ---------------------+--------------------------+------------------------------- Idigi4 | int32_t | AsDtype('>i4') Idtime4 | int32_t | AsDtype('>i4') Idatime4 | int32_t | AsDtype('>i4') Nwdigi_742b | uint16_t | AsDtype('>u2') Idigi_742b | uint16_t[40000] | AsDtype("('>u2', (40000,))") Nwfast_742b | uint16_t | AsDtype('>u2') Idigifast_742b | uint16_t[4112] | AsDtype("('>u2', (4112,))") Ifast_base742b | int32_t[32] | AsDtype("('>i4', (32,))") Ifast_time742b | int32_t[32] | AsDtype("('>i4', (32,))") Ifast_time50_742b | int32_t[32] | AsDtype("('>i4', (32,))") Ifast_ph742b | int32_t[32] | AsDtype("('>i4', (32,))") Iev_wri_b | int32_t | AsDtype('>i4') Iev_rd_b | int32_t | AsDtype('>i4') <TBranch 'Idigi4' at 0x7fb9b8216ac0> <TBranch 'Idtime4' at 0x7fb9c07f8f10> <TBranch 'Idatime4' at 0x7fb9c07c8640> <TBranch 'Nwdigi_742b' at 0x7fb9c07c0250> <TBranch 'Idigi_742b' at 0x7fb9c07c3e80> <TBranch 'Nwfast_742b' at 0x7fb9c07c0940> <TBranch 'Idigifast_742b' at 0x7fb9c07c6130> <TBranch 'Ifast_base742b' at 0x7fb9c07c68e0> <TBranch 'Ifast_time742b' at 0x7fb9c07c40d0> <TBranch 'Ifast_time50_742b' at 0x7fb9c07c4880> <TBranch 'Ifast_ph742b' at 0x7fb9c07c4fa0> <TBranch 'Iev_wri_b' at 0x7fb9c07ea820> <TBranch 'Iev_rd_b' at 0x7fb9c07eafd0> (57,) (57, 40000) Good events: 57 Total: (57,)
print(type(Idigi_742b))
print(Idigi_742b.shape, Idigi_742b.dtype)
<class 'numpy.ndarray'> (57, 40000) uint16
# Parametri caratteristici che ho appena descritto sopra
nPtsDigi_b = 1024
nWordSingleChannel_b = 5+nPtsDigi_b+2
nChannels_b = 16
def getWaveform(matrice, canale, evento):
"""
matrice: matrice dei dati
canale: numero di canale, contando da 0
evento: numero di evento (riga), contando da 0
"""
i = evento
j = canale
return matrice[i, (5 + nWordSingleChannel_b*j) : (5 + nWordSingleChannel_b*j + nPtsDigi_b)]
Idigipack_742b = Idigi_742b[:, :nChannels_b*nWordSingleChannel_b].reshape(Idigi_742b.shape[0], nChannels_b, nWordSingleChannel_b)[:,:,5:5+nPtsDigi_b ]
iChan = 2
fig, ax = plt.subplots(8,4)
fig.set_size_inches(60, 40)
ax = ax.flatten()
for i in range(16):
iChan = i
# Ripeto 0..512 per il numero di eventi (Idigipack.shape[0])
hh = ax[i].hist2d(np.tile(np.arange(nPtsDigi_b),Idigipack_742b.shape[0]),
Idigipack_742b[:,iChan,:].flatten(),
bins=(nPtsDigi_b,50), norm=mpl.colors.LogNorm(), cmap = "jet")
ax[i].set_title(f"Chan {iChan}", fontsize = 40)
fig.colorbar(hh[3], ax = ax[i])
plt.show()