diff --git a/ana/esa25eventdisplay/hcal_ch_mapping.csv b/ana/esa25eventdisplay/hcal_ch_mapping.csv new file mode 100644 index 000000000..70a87df9b --- /dev/null +++ b/ana/esa25eventdisplay/hcal_ch_mapping.csv @@ -0,0 +1,49 @@ +iLink,Ch,SiPM,Layer,Bar,End +1,36,0,1,0,0 +1,37,1,1,1,0 +1,38,2,1,2,0 +1,39,3,1,3,0 +1,40,4,2,0,0 +1,41,5,2,1,0 +1,42,6,2,2,0 +1,43,7,2,3,0 +1,45,8,3,0,0 +1,46,9,3,1,0 +1,47,10,3,2,0 +1,48,11,3,3,0 +1,49,12,4,0,0 +1,50,13,4,1,0 +1,51,14,4,2,0 +1,52,15,4,3,0 +1,54,16,5,0,0 +1,55,17,5,1,0 +1,56,18,5,2,0 +1,57,19,5,3,0 +1,58,20,6,0,0 +1,59,21,6,1,0 +1,60,22,6,2,0 +1,61,23,6,3,0 +0,22,24,6,0,1 +0,23,25,6,1,1 +0,24,26,6,2,1 +0,25,27,6,3,1 +0,18,28,5,0,1 +0,19,29,5,1,1 +0,20,30,5,2,1 +0,21,31,5,3,1 +0,13,32,4,0,1 +0,14,33,4,1,1 +0,15,34,4,2,1 +0,16,35,4,3,1 +0,9,36,3,0,1 +0,10,37,3,1,1 +0,11,38,3,2,1 +0,12,39,3,3,1 +0,4,40,2,0,1 +0,5,41,2,1,1 +0,6,42,2,2,1 +0,7,43,2,3,1 +0,0,44,1,0,1 +0,1,45,1,1,1 +0,2,46,1,2,1 +0,3,47,1,3,1 diff --git a/ana/esa25eventdisplay/hcal_event_display.py b/ana/esa25eventdisplay/hcal_event_display.py new file mode 100644 index 000000000..8d5ae5986 --- /dev/null +++ b/ana/esa25eventdisplay/hcal_event_display.py @@ -0,0 +1,119 @@ +import pandas as pd +import numpy as np +import hist +import matplotlib.pyplot as plt +from pathlib import Path +import argparse +import os + +parser = argparse.ArgumentParser() +parser.add_argument('data', type=Path, help='decoded CSV file from rogue-decoder') +parser.add_argument('outputdir', type=Path, help='plot output directory') +parser.add_argument('runnumber', help='run number') +parser.add_argument('nsamples', help='number of samples') +parser.add_argument('n_events', help='number of events to be plotted') +args = parser.parse_args() + +mapping_file = open("hcal_ch_mapping.csv","r") + +if not os.path.isdir(args.outputdir): + raise Exception("Output directory does not exist") + +chmap = {} + +for line in mapping_file: + line = line[:-1] + s = line.split(",") + if s[0] == "iLink": + continue + #print(line) + chmap[(int(s[3]),int(s[4]), int(s[5]))] = (int(s[0]),int(s[1])) + + +samples = pd.read_csv(args.data) + +timestamps = list(set(samples['timestamp'])) +print(timestamps) + +#bunchCounts =[t & 0xFF for t in timestamps] +#pulseId =[t >> 8 for t in timestamps] + + + +#events = sorted(list(set(samples['event']))) +#print(events) + +event_i = 0 + +for timestamp in timestamps: + if int(args.n_events) != -1 and event_i >= int(args.n_events): + print("Quitting, exceeded n_events") + break + + print("Plotting event_i = " + str(event_i)) + + fig, axs = plt.subplots(4,6, figsize=(12,10)) + + x = range(0,8) + + event = samples[samples["timestamp"] == timestamp] + + for layer in range(1,7): + for bar in range(0,4): + ilink_right,ch_right = chmap[(layer,bar,0)] + if ilink_right == 1: + ch_right -= 36 + ilink_left,ch_left = chmap[(layer,bar,1)] + if ilink_left == 1: + ch_left -= 36 + + adc_left = [] + adc_right = [] + + for i in range(0, int(args.nsamples)): + #row_right = event[event["timestamp"] & 0xFF == bunchCount] + row_right = event[event["i_sample"] == i] + print(row_right) + row_right = row_right[row_right["channel"] == str(ch_right)] + print(row_right) + row_right = row_right[row_right["i_link"] == ilink_right] + print(row_right) + print(timestamp) + print(ilink_right) + print(ch_right) + adc_right.append(int(row_right['adc'])) + + #row_left = samples[samples["timestamp"] & 0xFF == bunchCount] + row_left = event[event["i_sample"] == i] + row_left = row_left[row_left["channel"] == str(ch_left)] + row_left = row_left[row_left["i_link"] == ilink_left] + adc_left.append(int(row_left['adc'])) + + + axs[3-bar, layer-1].plot(x, adc_left, color="red", marker="*", label="Left") + axs[3-bar, layer-1].plot(x, adc_right, color="blue", marker="*", label="Right") + + axs[3-bar, layer-1].set_xlim(0,int(args.nsamples)-1) + axs[3-bar, layer-1].set_ylim(0,1023) + if bar == 0: + axs[3-bar, layer-1].set_xlabel("L"+str(layer)) + else: + axs[3-bar,layer-1].set_xticklabels([]) + + if layer == 1: + axs[3-bar,layer-1].set_ylabel("Bar "+str(bar)) + else: + axs[3-bar,layer-1].set_yticklabels([]) + + if layer == 6 and bar == 3: + axs[3-bar,layer-1].legend() + + + + fig.suptitle("Run " + args.runnumber + " event " + str(event_i)) + plt.tight_layout() + #plt.show() + plt.savefig(str(args.outputdir)+"/run_"+args.runnumber+"_event_"+str(event_i)+".png",dpi=300) + + + event_i += 1 diff --git a/ana/esa25eventdisplay/hcal_hist.py b/ana/esa25eventdisplay/hcal_hist.py new file mode 100644 index 000000000..4740137e6 --- /dev/null +++ b/ana/esa25eventdisplay/hcal_hist.py @@ -0,0 +1,179 @@ +import pandas as pd +import numpy as np +import hist +import matplotlib.pyplot as plt +from pathlib import Path +import argparse +import os + +parser = argparse.ArgumentParser() +parser.add_argument('data', type=Path, help='decoded CSV file from rogue-decoder') +parser.add_argument('outputdir', type=Path, help='plot output directory') +parser.add_argument('runnumber', help='run number') +parser.add_argument('nsamples', help='number of samples') +parser.add_argument('n_events', help='number of events to be plotted') +args = parser.parse_args() + +mapping_file = open("hcal_ch_mapping.csv","r") + +if not os.path.isdir(args.outputdir): + raise Exception("Output directory does not exist") + +chmap = {} + +for line in mapping_file: + line = line[:-1] + s = line.split(",") + if s[0] == "iLink": + continue + #print(line) + chmap[(int(s[3]),int(s[4]), int(s[5]))] = (int(s[0]),int(s[1])) + + +samples = pd.read_csv(args.data) + +timestamps = list(set(samples['timestamp'])) + +hists_x = {} +hists_y = {} +maxadc = {} +for k in chmap.keys(): + hists_x[k] = [] + hists_y[k] = [] + maxadc[k] = [] + + +event_i = 0 +for timestamp in timestamps: + if int(args.n_events) != -1 and event_i >= int(args.n_events): + print("Quitting, exceeded n_events") + break + + print("Plotting event_i = " + str(event_i)) + + x = range(0,8) + + event = samples[samples["timestamp"] == timestamp] + + for layer in range(1,7): + for bar in range(0,4): + ilink_right,ch_right = chmap[(layer,bar,0)] + if ilink_right == 1: + ch_right -= 36 + ilink_left,ch_left = chmap[(layer,bar,1)] + if ilink_left == 1: + ch_left -= 36 + + adc_left = [] + adc_right = [] + + for i in range(0, int(args.nsamples)): + row_right = event[event["i_sample"] == i] + row_right = row_right[row_right["channel"] == str(ch_right)] + row_right = row_right[row_right["i_link"] == ilink_right] + adc = int(row_right['adc']) + adc_right.append(adc) + hists_x[(layer,bar,0)].append(i) + hists_y[(layer,bar,0)].append(adc) + + row_left = event[event["i_sample"] == i] + row_left = row_left[row_left["channel"] == str(ch_left)] + row_left = row_left[row_left["i_link"] == ilink_left] + adc = int(row_left['adc']) + adc_left.append(adc) + hists_x[(layer,bar,1)].append(i) + hists_y[(layer,bar,1)].append(adc) + + maxadc[(layer,bar,0)].append(max(adc_right)) + maxadc[(layer,bar,1)].append(max(adc_left)) + + + """ + axs[3-bar, layer-1].plot(x, adc_left, color="red", marker="*", label="Left") + axs[3-bar, layer-1].plot(x, adc_right, color="blue", marker="*", label="Right") + + axs[3-bar, layer-1].set_xlim(0,int(args.nsamples)-1) + axs[3-bar, layer-1].set_ylim(0,1023) + if bar == 0: + axs[3-bar, layer-1].set_xlabel("L"+str(layer)) + else: + axs[3-bar,layer-1].set_xticklabels([]) + + if layer == 1: + axs[3-bar,layer-1].set_ylabel("Bar "+str(bar)) + else: + axs[3-bar,layer-1].set_yticklabels([]) + + if layer == 6 and bar == 3: + axs[3-bar,layer-1].legend() + """ + + event_i += 1 + +fig, axs = plt.subplots(4,6, figsize=(12,10)) +for layer in range(1,7): + for bar in range(0,4): + axs[3-bar, layer-1].hist2d(hists_x[(layer,bar,0)],hists_y[(layer,bar,0)]) + + if bar == 0: + axs[3-bar, layer-1].set_xlabel("L"+str(layer)) + if layer == 1: + axs[3-bar,layer-1].set_ylabel("Bar "+str(bar)) + + if layer == 6 and bar == 3: + axs[3-bar,layer-1].legend() + +fig.suptitle("Run " + args.runnumber + ", right SiPMs") +plt.tight_layout() +plt.savefig(str(args.outputdir)+"/hist2d_right_run_"+args.runnumber+".png",dpi=300) +plt.clf() +fig, axs = plt.subplots(4,6, figsize=(12,10)) +for layer in range(1,7): + for bar in range(0,4): + axs[3-bar, layer-1].hist2d(hists_x[(layer,bar,1)],hists_y[(layer,bar,1)]) + + if bar == 0: + axs[3-bar, layer-1].set_xlabel("L"+str(layer)) + if layer == 1: + axs[3-bar,layer-1].set_ylabel("Bar "+str(bar)) + if layer == 6 and bar == 3: + axs[3-bar,layer-1].legend() + +fig.suptitle("Run " + args.runnumber + ", left SiPMs") +plt.tight_layout() +plt.savefig(str(args.outputdir)+"/hist2d_left_run_"+args.runnumber+".png",dpi=300) +plt.clf() +fig, axs = plt.subplots(4,6, figsize=(12,10)) +for layer in range(1,7): + for bar in range(0,4): + axs[3-bar, layer-1].hist(maxadc[(layer,bar,0)]) + + if bar == 0: + axs[3-bar, layer-1].set_xlabel("L"+str(layer)) + if layer == 1: + axs[3-bar,layer-1].set_ylabel("Bar "+str(bar)) + + if layer == 6 and bar == 3: + axs[3-bar,layer-1].legend() + +fig.suptitle("Run " + args.runnumber + ", maxADC, right SiPMs") +plt.tight_layout() +plt.savefig(str(args.outputdir)+"/maxadc_right_run_"+args.runnumber+".png",dpi=300) +plt.clf() +fig, axs = plt.subplots(4,6, figsize=(12,10)) +for layer in range(1,7): + for bar in range(0,4): + axs[3-bar, layer-1].hist(maxadc[(layer,bar,1)]) + + if bar == 0: + axs[3-bar, layer-1].set_xlabel("L"+str(layer)) + if layer == 1: + axs[3-bar,layer-1].set_ylabel("Bar "+str(bar)) + + if layer == 6 and bar == 3: + axs[3-bar,layer-1].legend() + +fig.suptitle("Run " + args.runnumber + ", maxADC, left SiPMs") +plt.tight_layout() +plt.savefig(str(args.outputdir)+"/maxadc_left_run_"+args.runnumber+".png",dpi=300) +