diff --git a/grand/dataio/root_files.py b/grand/dataio/root_files.py index 138e472d..e6f1bb44 100644 --- a/grand/dataio/root_files.py +++ b/grand/dataio/root_files.py @@ -12,6 +12,7 @@ import numpy as np import ROOT +import matplotlib.pyplot as plt import grand.dataio.root_trees as groot from grand.basis.traces_event import Handling3dTraces @@ -192,6 +193,37 @@ def get_obj_handling3dtraces(self): o_tevent.info_shower += f" energy_primary={nrj:.1e} GeV" return o_tevent + def get_nb_traces_in_file(self): + nb_traces = 0 + cur_idx = self.idx_event + for idx in range(self.get_nb_events()): + self.load_event_idx(idx) + nb_traces += self.du_count + self.load_event_idx(cur_idx) + return nb_traces + + def plot_histo_vmax(self, nbins=20): + cur_idx = self.idx_event + a_vmax = np.zeros(self.get_nb_traces_in_file(), dtype=np.float32) + idx_t = 0 + #for idx_e in range(self.get_nb_events()): + for idx_e in range(10): + self.load_event_idx(idx_e) + tr3d = self.get_obj_handling3dtraces() + max_norm = tr3d.get_max_norm() + a_vmax[idx_t : idx_t + self.du_count] = max_norm + idx_t += self.du_count + + _, bins = np.histogram(a_vmax, bins=nbins) + logbins = np.logspace(0,np.log10(bins[-1]),len(bins)) + plt.figure() + plt.title(f"{self.f_name}\nHistogram of max value for each traces") + plt.hist(a_vmax, bins=logbins) + #plt.xscale('log') + plt.yscale('log') + plt.grid() + self.load_event_idx(cur_idx) + # # public function class diff --git a/scripts/plot_grandlib_vmax_adc_events.py b/scripts/plot_grandlib_vmax_adc_events.py new file mode 100644 index 00000000..d843cb7c --- /dev/null +++ b/scripts/plot_grandlib_vmax_adc_events.py @@ -0,0 +1,51 @@ +""" +Created on 16 avr. 2024 + +@author: jcolley +""" +import sys + + +import grand.dataio.root_trees as groot +import numpy as np +import matplotlib.pyplot as plt + + +pnf_event = sys.argv[1] +s_evt = pnf_event.split("/") + +# Read only traces +fevt = groot.TADC(pnf_event) +# close doesn't exist ? +#fevt.close() +print(fevt.event_number) +sys.exit() + + +a_nb_tr = ak.num(traces, axis=1) +nb_traces = ak.sum(a_nb_tr) +print("nb traces: ",nb_traces) +a_vmax = np.zeros(nb_traces, dtype=np.float32) +nb_evt = ak.num(traces, axis=0) +idx_t = 0 +for idx, nb_tr in zip(range(nb_evt),a_nb_tr) : + tr3d = ak.to_numpy(traces[idx]) + max_norm = np.max(np.linalg.norm(tr3d, axis=1), axis=1) + a_vmax[idx_t : idx_t + nb_tr] = max_norm + idx_t += nb_tr +print("end") + +_, bins = np.histogram(a_vmax, bins=20) +logbins = np.logspace(0,np.log10(bins[-1]),len(bins)) +plt.rcParams["savefig.bbox"]='tight' +plt.rcParams["savefig.pad_inches"]=0.2 +plt.title(f"Histogram of max value for {nb_traces} traces") +plt.hist(a_vmax, bins=logbins) +plt.xscale('log') +plt.yscale('log') +plt.xlabel(f"ADU\nDir: {s_evt[-2]}\nFile: {s_evt[-1]}") +plt.ylabel("Number of trace in bin") +plt.grid() +plt.savefig(f'histo_grandlib_{nb_traces}_traces.png') + +#plt.show() \ No newline at end of file diff --git a/scripts/plot_uproot_vmax_adc_events.py b/scripts/plot_uproot_vmax_adc_events.py new file mode 100644 index 00000000..15a16a63 --- /dev/null +++ b/scripts/plot_uproot_vmax_adc_events.py @@ -0,0 +1,64 @@ +""" +Created on 16 avr. 2024 + +@author: jcolley +""" +import sys + +import awkward as ak +import uproot +import numpy as np +import matplotlib.pyplot as plt + + +pnf_event = sys.argv[1] +s_evt = pnf_event.split("/") + +# Read only traces +fevt = uproot.open(pnf_event) +traces = fevt["tadc"]["trace_ch"].array() +fevt.close() + +# array of number of traces by event +a_nb_tr = ak.num(traces, axis=1) +# number of all traces in files +nb_traces = ak.sum(a_nb_tr) +print("nb traces: ", nb_traces) +a_vmax = np.zeros(nb_traces, dtype=np.float32) +nb_evt = ak.num(traces, axis=0) +idx_t = 0 +for idx, nb_tr in zip(range(nb_evt), a_nb_tr): + tr3d = ak.to_numpy(traces[idx]) + max_norm = np.max(np.linalg.norm(tr3d, axis=1), axis=1) + a_vmax[idx_t : idx_t + nb_tr] = max_norm + idx_t += nb_tr +print("end") + +idx_zero = np.where(a_vmax == 0.0)[0] +print(len(idx_zero)) +idx_un = np.where(a_vmax == 1.0)[0] +print(len(idx_un)) + +_, bins = np.histogram(a_vmax, bins=20) +logbins = np.logspace(-0.001, np.log10(bins[-1]), len(bins)) +plt.rcParams["savefig.bbox"] = "tight" +plt.rcParams["savefig.pad_inches"] = 0.2 +plt.figure() +plt.title(f"Histogram of max value for {nb_traces} traces") +plt.hist(a_vmax, bins=logbins) +plt.xscale("log") +plt.yscale("log") +plt.xlabel(f"ADU\nDir: {s_evt[-2]}\nFile: {s_evt[-1]}") +plt.ylabel("Number of trace in bin") +plt.grid() +plt.savefig(f"histo_uproot_{nb_traces}_traces.png") + +plt.figure() +plt.title(f"Histogram of max value for {nb_traces} traces") +plt.hist(a_vmax, bins=50) +plt.xlabel(f"ADU\nDir: {s_evt[-2]}\nFile: {s_evt[-1]}") +plt.ylabel("Number of trace in bin") +plt.yscale("log") +plt.grid() +plt.savefig(f"histo_noxlog_{nb_traces}_traces.png") +# plt.show()