From 69b867d9de65e6fc3be78713607da1f3af107035 Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Thu, 25 Apr 2024 07:56:51 -0500 Subject: [PATCH 1/7] Draft for plotting script for performance plots of reconstruction --- scripts/Reco/performance_reco.py | 481 +++++++++++++++++++++++++++++++ 1 file changed, 481 insertions(+) create mode 100755 scripts/Reco/performance_reco.py diff --git a/scripts/Reco/performance_reco.py b/scripts/Reco/performance_reco.py new file mode 100755 index 00000000..1586405d --- /dev/null +++ b/scripts/Reco/performance_reco.py @@ -0,0 +1,481 @@ +import ROOT +import numpy as np +import matplotlib.pyplot as mp +import os +import argparse +import cppyy.ll + +# plotstyle +red_cbf = '#d55e00' +blue_cbf = '#0072b2' +orange_cbf = '#e69f00' +magenta_cbf = '#cc79a7' +black_cbf = '#000000' +green_cbf = '#009e73' +mp.style.use('seaborn-poster') + +mp.rc('axes', labelsize = 12) # fontsize of the x and y labels +mp.rc('xtick', labelsize = 12) # fontsize of the tick labels +mp.rc('ytick', labelsize = 12) # fontsize of the tick labels + +### Actual function that loops through the spills +def draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_filename, only_true_tms_muons = False): + if not os.path.exists(input_filename): raise ValueError(f"Cannor find input_filename {input_filename}") + if readout_filename != "" and not os.path.exists(readout_filename): raise ValueError(f"Cannot find readout_filename {readout_filename}") + if spill_number < -1: raise ValueError(f"Got spill_number = {spill_number}") + if time_slice < -1: raise ValueError(f"Got time_slice = {time_slice}") + + # Make sure we read in the correct file and have the output directory + use_readout = True + if readout_filename == "": use_readout = False + if not os.path.exists(out_dir): + os.makedirs(out_dir) + if not os.path.exists(out_dir): + raise ValueError(f"Could not make out_dir {out_dir}") + + # Read in the Reco_Tree that contains the TMS_Tracks + r = ROOT.TChain("Reco_Tree") + r.Add(input_filename) + print("N entries:", r.GetEntries()) + if not r.GetEntries() > 0: + print("Didn't get any entries, are you sure the input_filename is right?\n", input_filename) + + truth = ROOT.TChain("Truth_Info") + truth.Add(input_filename) + if not truth.GetEntries() > 0: + print("Didn't get any entries in Truth_Info, are you sure the input_filename is right?\n", input_filename) + + # Not used yet + readout = None + if use_readout: + readout = ROOT.TChain("TMS") + readout.Add(readout_filename) + if not readout.GetEntries() > 0: + print("Didnt't get any entries in TMS, are you sure the readout_filename is right?\n", readout_filename) + + max_n_spills = 10000 # TODO (old) add some meta info to output file with n spill info for file + + simplify_tracks = False + + spill_number_cache = dict() + n_events = r.GetEntries() + + Position_TMS_Start = np.empty((n_events, 3), dtype = float) * -9999. + Position_TMS_End = np.empty((n_events, 3), dtype = float) * -9999. + Reco_Start = np.empty((n_events, 3), dtype = float) * -9999. + Reco_End = np.empty((n_events, 3), dtype = float) * -9999. + + for current_spill_number in range(max_n_spills): + for i in range(n_events): + try: + spill_number = spill_number_cache[i] + event = None + true_event = None + except KeyError: + r.GetEntry(i) + event = r + truth.GetEntry(i) + true_event = truth + spill_number = event.SpillNo + spill_number_cache[i] = spill_number + if spill_number < current_spill_number: continue + if spill_number > current_spill_number: break + if event == None: + r.GetEntry(i) + event = r + if true_event == None: + truth.GetEntry(i) + true_event = truth + + nTracks = event.nTracks + if nTracks <= 0: continue + + PositionTMSStart = np.frombuffer(true_event.PositionTMSStart, dtype = np.float32) + PositionTMSEnd = np.frombuffer(true_event.PositionTMSEnd, dtype = np.float32) + StartPos = np.frombuffer(event.StartPos, dtype = np.float32) + EndPos = np.frombuffer(event.EndPos, dtype = np.float32) + + if PositionTMSStart[0] > -8000. and not StartPos.size == 0: + Position_TMS_Start[i, 0] = PositionTMSStart[0] + Position_TMS_Start[i, 1] = PositionTMSStart[1] + Position_TMS_Start[i, 2] = PositionTMSStart[2] + Reco_Start[i, 0] = StartPos[0] + Reco_Start[i, 1] = StartPos[1] + Reco_Start[i, 2] = StartPos[2] + if PositionTMSStart[0] > -8000. and not EndPos.size == 0: + Position_TMS_End[i, 0] = PositionTMSEnd[0] + Position_TMS_End[i, 1] = PositionTMSEnd[1] + Position_TMS_End[i, 2] = PositionTMSEnd[2] + Reco_End[i, 0] = EndPos[0] + Reco_End[i, 1] = EndPos[1] + Reco_End[i, 2] = EndPos[2] + + # subtract reconstruction from truth for all directions + Diff_Start_x = Position_TMS_Start[:, 0] - Reco_Start[:, 0] + Diff_Start_y = Position_TMS_Start[:, 1] - Reco_Start[:, 1] + Diff_Start_z = Position_TMS_Start[:, 2] - Reco_Start[:, 2] + Diff_End_x = Position_TMS_End[:, 0] - Reco_End[:, 0] + Diff_End_y = Position_TMS_End[:, 1] - Reco_End[:, 1] + Diff_End_z = Position_TMS_End[:, 2] - Reco_End[:, 2] + + # create histograms for the differences + Diff_Start_x_hist, Diff_Start_x_bins = np.histogram(Diff_Start_x, bins = 50) + Diff_Start_y_hist, Diff_Start_y_bins = np.histogram(Diff_Start_y, bins = 50) + Diff_Start_z_hist, Diff_Start_z_bins = np.histogram(Diff_Start_z, bins = 50) + Diff_End_x_hist, Diff_End_x_bins = np.histogram(Diff_End_x, bins = 50) + Diff_End_y_hist, Diff_End_y_bins = np.histogram(Diff_End_y, bins = 50) + Diff_End_z_hist, Diff_End_z_bins = np.histogram(Diff_End_z, bins = 50) + + Diff_Start_x_histX, Diff_Start_x_histY = histogram_arr_handle(Diff_Start_x_hist, Diff_Start_x_bins) + Diff_Start_y_histX, Diff_Start_y_histY = histogram_arr_handle(Diff_Start_y_hist, Diff_Start_y_bins) + Diff_Start_z_histX, Diff_Start_z_histY = histogram_arr_handle(Diff_Start_z_hist, Diff_Start_z_bins) + Diff_End_x_histX, Diff_End_x_histY = histogram_arr_handle(Diff_End_x_hist, Diff_End_x_bins) + Diff_End_y_histX, Diff_End_y_histY = histogram_arr_handle(Diff_End_y_hist, Diff_End_y_bins) + Diff_End_z_histX, Diff_End_z_histY = histogram_arr_handle(Diff_End_z_hist, Diff_End_z_bins) + + # plot + mp.plot(Diff_Start_x_histX, Diff_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_x_histX, 0, Diff_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Difference_Start_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_y_histX, Diff_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_y_histX, 0, Diff_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Difference_Start_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_z_histX, Diff_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_z_histX, 0, Diff_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Difference_Start_Z_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_x_histX, Diff_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_x_histX, 0, Diff_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Difference_End_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_y_histX, Diff_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_y_histX, 0, Diff_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Difference_End_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_z_histX, Diff_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_z_histX, 0, Diff_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Difference_End_Z_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_x_histX, Diff_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_x_histX, 0, Diff_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('x') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Difference_Start_X_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_y_histX, Diff_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_y_histX, 0, Diff_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('y') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Difference_Start_Y_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_z_histX, Diff_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_z_histX, 0, Diff_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('z') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Difference_Start_Z_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_x_histX, Diff_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_x_histX, 0, Diff_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('x') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Difference_End_X_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_y_histX, Diff_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_y_histX, 0, Diff_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('y') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Difference_End_Y_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_z_histX, Diff_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_z_histX, 0, Diff_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction') + mp.ylabel('#') + mp.title('z') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Difference_End_Z_hist_log.png', bbox_inches = 'tight') + mp.close() + + # create histograms for all directions for truth and reconstruction + Position_TMS_Start_x_hist, Position_TMS_Start_x_bins = np.histogram(Position_TMS_Start[:, 0], bins = 192)#, range = (-3400., 3400.)) + Position_TMS_Start_y_hist, Position_TMS_Start_y_bins = np.histogram(Position_TMS_Start[:, 1], bins = 100)#, range = (-4110., -910.)) + Position_TMS_Start_z_hist, Position_TMS_Start_z_bins = np.histogram(Position_TMS_Start[:, 2], bins = 100)#, range = (11360., 18320.)) + Position_TMS_End_x_hist, Position_TMS_End_x_bins = np.histogram(Position_TMS_End[:, 0], bins = 192)#, range = (-3400., 3400.)) + Position_TMS_End_y_hist, Position_TMS_End_y_bins = np.histogram(Position_TMS_End[:, 1], bins = 100)#, range = (-4110., -910.)) + Position_TMS_End_z_hist, Position_TMS_End_z_bins = np.histogram(Position_TMS_End[:, 2], bins = 100)#, range = (11360., 18320.)) + Reco_Start_x_hist, Reco_Start_x_bins = np.histogram(Reco_Start[:, 0], bins = 192)#, range = (-3400., 3400.)) + Reco_Start_y_hist, Reco_Start_y_bins = np.histogram(Reco_Start[:, 1], bins = 20)#, range = (-4110., -910.)) + Reco_Start_z_hist, Reco_Start_z_bins = np.histogram(Reco_Start[:, 2], bins = 100)#, range = (11360., 18320.)) + Reco_End_x_hist, Reco_End_x_bins = np.histogram(Reco_End[:, 0], bins = 192)#, range = (-3400., 3400.)) + Reco_End_y_hist, Reco_End_y_bins = np.histogram(Reco_End[:, 1], bins = 20)#, range = (-4110., -910.)) + Reco_End_z_hist, Reco_End_z_bins = np.histogram(Reco_End[:, 2], bins = 100)#, range = (11360., 18320.)) + + # make the histograms usable + Position_TMS_Start_x_histX, Position_TMS_Start_x_histY = histogram_arr_handle(Position_TMS_Start_x_hist, Position_TMS_Start_x_bins) + Position_TMS_Start_y_histX, Position_TMS_Start_y_histY = histogram_arr_handle(Position_TMS_Start_y_hist, Position_TMS_Start_y_bins) + Position_TMS_Start_z_histX, Position_TMS_Start_z_histY = histogram_arr_handle(Position_TMS_Start_z_hist, Position_TMS_Start_z_bins) + Position_TMS_End_x_histX, Position_TMS_End_x_histY = histogram_arr_handle(Position_TMS_End_x_hist, Position_TMS_End_x_bins) + Position_TMS_End_y_histX, Position_TMS_End_y_histY = histogram_arr_handle(Position_TMS_End_y_hist, Position_TMS_End_y_bins) + Position_TMS_End_z_histX, Position_TMS_End_z_histY = histogram_arr_handle(Position_TMS_End_z_hist, Position_TMS_End_z_bins) + Reco_Start_x_histX, Reco_Start_x_histY = histogram_arr_handle(Reco_Start_x_hist, Reco_Start_x_bins) + Reco_Start_y_histX, Reco_Start_y_histY = histogram_arr_handle(Reco_Start_y_hist, Reco_Start_y_bins) + Reco_Start_z_histX, Reco_Start_z_histY = histogram_arr_handle(Reco_Start_z_hist, Reco_Start_z_bins) + Reco_End_x_histX, Reco_End_x_histY = histogram_arr_handle(Reco_End_x_hist, Reco_End_x_bins) + Reco_End_y_histX, Reco_End_y_histY = histogram_arr_handle(Reco_End_y_hist, Reco_End_y_bins) + Reco_End_z_histX, Reco_End_z_histY = histogram_arr_handle(Reco_End_z_hist, Reco_End_z_bins) + + # now plot this + mp.plot(Position_TMS_Start_x_histX, Position_TMS_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_x_histX, Reco_Start_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_Start_x_histX, 0, Position_TMS_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_Start_x_histX, 0, Reco_Start_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Track_Start_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_Start_y_histX, Position_TMS_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_y_histX, Reco_Start_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_Start_y_histX, 0, Position_TMS_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_Start_y_histX, 0, Reco_Start_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Track_Start_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_Start_z_histX, Position_TMS_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_z_histX, Reco_Start_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_Start_z_histX, 0, Position_TMS_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_Start_z_histX, 0, Reco_Start_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Track_Start_Z_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_End_x_histX, Position_TMS_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_End_x_histX, Reco_End_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_End_x_histX, 0, Position_TMS_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_End_x_histX, 0, Reco_End_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Track_End_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_End_y_histX, Position_TMS_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_End_y_histX, Reco_End_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_End_y_histX, 0, Position_TMS_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_End_y_histX, 0, Reco_End_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Track_End_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_End_z_histX, Position_TMS_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_End_z_histX, Reco_End_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_End_z_histX, 0, Position_TMS_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_End_z_histX, 0, Reco_End_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Track_End_Z_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_Start_x_histX, Position_TMS_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_x_histX, Reco_Start_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_Start_x_histX, 0, Position_TMS_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_Start_x_histX, 0, Reco_Start_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS') + mp.ylabel('#') + mp.title('x') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Track_Start_X_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_Start_y_histX, Position_TMS_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_y_histX, Reco_Start_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_Start_y_histX, 0, Position_TMS_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_Start_y_histX, 0, Reco_Start_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS') + mp.ylabel('#') + mp.title('y') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Track_Start_Y_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_Start_z_histX, Position_TMS_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_z_histX, Reco_Start_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_Start_z_histX, 0, Position_TMS_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_Start_z_histX, 0, Reco_Start_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS') + mp.ylabel('#') + mp.title('z') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Track_Start_Z_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_End_x_histX, Position_TMS_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_End_x_histX, Reco_End_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_End_x_histX, 0, Position_TMS_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_End_x_histX, 0, Reco_End_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS') + mp.ylabel('#') + mp.title('x') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Track_End_X_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_End_y_histX, Position_TMS_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_End_y_histX, Reco_End_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_End_y_histX, 0, Position_TMS_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_End_y_histX, 0, Reco_End_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS') + mp.ylabel('#') + mp.title('y') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Track_End_Y_hist_log.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Position_TMS_End_z_histX, Position_TMS_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Reco_End_z_histX, Reco_End_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Position_TMS_End_z_histX, 0, Position_TMS_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Reco_End_z_histX, 0, Reco_End_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS') + mp.ylabel('#') + mp.title('z') + mp.yscale('log') + mp.savefig('performance_plots_NERSC/Track_End_Z_hist_log.png', bbox_inches = 'tight') + mp.close() + + return + +def histogram_arr_handle(bins, edges):#(u bins,v edges) + """Function to calculated x- and y-values from np.histogram + + @param[in] bins: bin-values from np.histogram to be transformed into y-values + @param[in] edges: edge-values from np.histogram to be transformed into x-values + + @return: 1d-array containing the x-values and 1d-array containing the y-values + """ + x_output = np.zeros(2 * len(bins)) + y_output = np.zeros(2 * len(bins)) + #v edges to u*2 x-values + x_output[0] = edges[0] + counter = 1 + for i in range(1, len(x_output)-1, 2): + x_output[i] = edges[counter] + x_output[i + 1] = edges[counter] + counter = counter + 1 + x_output[-1] = edges[-1] + + #u bins to u*2 y-values + counter = 0 + for i in range(0, len(y_output), 2): + y_output[i] = bins[counter] + y_output[i + 1] = bins[counter] + counter = counter + 1 + + return x_output, y_output + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description = "Draws spills.") + parser.add_argument('--outdir', "-o", type = str, help = "The output dir. Will be made if it doesn't exist. Default = spills/", default = "spills") + parser.add_argument('--name', "-n", type = str, help = "The name of the output files. Will be __.png. Default = spill", default = "spill") + parser.add_argument('--input_filename', "-f", type = str, help = "The file with the events to draw.") + parser.add_argument('--spillnum', "-s", type = int, help = "The spill to draw. -1 for all", default = -1) + parser.add_argument('--timeslice', "-t", type = int, help = "The time slice to draw. -1 for all", default = -1) + parser.add_argument('--readout_filename', "-r", type = str, help = "(optional) A file with the raw readout.", default = "") + parser.add_argument('--only_true_tms_muons', help = "Only draw events with true muons inside the TMS", action = argparse.BooleanOptionalAction) + + args = parser.parse_args() + + out_dir = args.outdir + name = args.name + input_filename = args.input_filename + spill_number = args.spillnum + time_slice = args.timeslice + readout_filename = args.readout_filename + only_true_tms_muons = args.only_true_tms_muons + draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_filename, only_true_tms_muons) + From d1d3abbdd9021032a29326e4fb7bbd13203ec7e6 Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Thu, 25 Apr 2024 11:27:27 -0500 Subject: [PATCH 2/7] Updating performance plotting script, adding different truth, solving 0 bin problem, dependence difference on real position --- src/TMS_Reco.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TMS_Reco.cpp b/src/TMS_Reco.cpp index 1f4f14d1..c5e4f1b1 100644 --- a/src/TMS_Reco.cpp +++ b/src/TMS_Reco.cpp @@ -1279,7 +1279,7 @@ void TMS_TrackFinder::CalculateRecoY(TMS_Hit &OneHit, TMS_Hit &OtherHit) { // geom->GetCurrentMatrix()->LocalToMaster(localOne, positionOne); // This gives us the position of the bars in x, y and z. Use only the y for now! // geom->GetCurrentMatrix()->LocalToMaster(localOther, positionOther); - OneHit.SetRecoY(-1350 - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(OneHit.GetNotZ() - OtherHit.GetNotZ())); //positionOne[1], positionOther[1] //0.5 * (OneHit.GetY() + OtherHit.GetY()) + OneHit.SetRecoY(-1350 - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(OneHit.GetNotZ() - OtherHit.GetNotZ())); //positionOne[1], positionOther[1] //0.5 * (OneHit.GetY() + OtherHit.GetY())//-1350 // USING THIS -1350 ALSO IN CompareY FUNCTION. CHANGE THERE AS WELL IF CHANGED HERE!!!!! return; } From 14e86e7a716f34ba00de64266b44b86568e12529 Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Mon, 29 Apr 2024 05:11:16 -0500 Subject: [PATCH 3/7] Took out wrong truth in performance_reco script --- performance_reco.py | 414 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 414 insertions(+) create mode 100755 performance_reco.py diff --git a/performance_reco.py b/performance_reco.py new file mode 100755 index 00000000..12986d95 --- /dev/null +++ b/performance_reco.py @@ -0,0 +1,414 @@ +import ROOT +import numpy as np +import matplotlib.pyplot as mp +import os +import argparse +import cppyy.ll +import matplotlib.cm as cm + +# plotstyle +red_cbf = '#d55e00' +blue_cbf = '#0072b2' +orange_cbf = '#e69f00' +magenta_cbf = '#cc79a7' +black_cbf = '#000000' +green_cbf = '#009e73' +mp.style.use('seaborn-poster') + +mp.rc('axes', labelsize = 12) # fontsize of the x and y labels +mp.rc('xtick', labelsize = 12) # fontsize of the tick labels +mp.rc('ytick', labelsize = 12) # fontsize of the tick labels + +### Actual function that loops through the spills +def draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_filename, only_true_tms_muons = False): + if not os.path.exists(input_filename): raise ValueError(f"Cannor find input_filename {input_filename}") + if readout_filename != "" and not os.path.exists(readout_filename): raise ValueError(f"Cannot find readout_filename {readout_filename}") + if spill_number < -1: raise ValueError(f"Got spill_number = {spill_number}") + if time_slice < -1: raise ValueError(f"Got time_slice = {time_slice}") + + # Make sure we read in the correct file and have the output directory + use_readout = True + if readout_filename == "": use_readout = False + if not os.path.exists(out_dir): + os.makedirs(out_dir) + if not os.path.exists(out_dir): + raise ValueError(f"Could not make out_dir {out_dir}") + + # Read in the Reco_Tree that contains the TMS_Tracks + r = ROOT.TChain("Reco_Tree") + r.Add(input_filename) + print("N entries:", r.GetEntries()) + if not r.GetEntries() > 0: + print("Didn't get any entries, are you sure the input_filename is right?\n", input_filename) + + truth = ROOT.TChain("Truth_Info") + truth.Add(input_filename) + if not truth.GetEntries() > 0: + print("Didn't get any entries in Truth_Info, are you sure the input_filename is right?\n", input_filename) + + # Not used yet + readout = None + if use_readout: + readout = ROOT.TChain("TMS") + readout.Add(readout_filename) + if not readout.GetEntries() > 0: + print("Didnt't get any entries in TMS, are you sure the readout_filename is right?\n", readout_filename) + + max_n_spills = 10000 # TODO (old) add some meta info to output file with n spill info for file + + simplify_tracks = False + + spill_number_cache = dict() + n_events = r.GetEntries() + + Reco_Start = np.ones((n_events, 3), dtype = float) * -9999. + Reco_End = np.ones((n_events, 3), dtype = float) * -9999. + Primary_True_Start = np.ones((n_events, 3), dtype = float) * -9999. + Primary_True_End = np.ones((n_events, 3), dtype = float) * -9999. + + for current_spill_number in range(max_n_spills): + for i in range(n_events): + try: + spill_number = spill_number_cache[i] + event = None + true_event = None + except KeyError: + r.GetEntry(i) + event = r + truth.GetEntry(i) + true_event = truth + spill_number = event.SpillNo + spill_number_cache[i] = spill_number + if spill_number < current_spill_number: continue + if spill_number > current_spill_number: break + if event == None: + r.GetEntry(i) + event = r + if true_event == None: + truth.GetEntry(i) + true_event = truth + + nTracks = event.nTracks + if nTracks <= 0: continue + + StartPos = np.frombuffer(event.StartPos, dtype = np.float32) + EndPos = np.frombuffer(event.EndPos, dtype = np.float32) + RecoTrackPrimaryParticleTruePositionTrackStart = np.frombuffer(true_event.RecoTrackPrimaryParticleTruePositionTrackStart, dtype = np.float32) + RecoTrackPrimaryParticleTruePositionTrackEnd = np.frombuffer(true_event.RecoTrackPrimaryParticleTruePositionTrackEnd, dtype = np.float32) + + if RecoTrackPrimaryParticleTruePositionTrackStart[0] > -8000. and not StartPos.size == 0: + Reco_Start[i, 0] = StartPos[0] + Reco_Start[i, 1] = StartPos[1] + Reco_Start[i, 2] = StartPos[2] + Primary_True_Start[i, 0] = RecoTrackPrimaryParticleTruePositionTrackStart[0] + Primary_True_Start[i, 1] = RecoTrackPrimaryParticleTruePositionTrackStart[1] + Primary_True_Start[i, 2] = RecoTrackPrimaryParticleTruePositionTrackStart[2] + if RecoTrackPrimaryParticleTruePositionTrackEnd[0] > -8000. and not EndPos.size == 0: + Reco_End[i, 0] = EndPos[0] + Reco_End[i, 1] = EndPos[1] + Reco_End[i, 2] = EndPos[2] + Primary_True_End[i, 0] = RecoTrackPrimaryParticleTruePositionTrackEnd[0] + Primary_True_End[i, 1] = RecoTrackPrimaryParticleTruePositionTrackEnd[1] + Primary_True_End[i, 2] = RecoTrackPrimaryParticleTruePositionTrackEnd[2] + + # filter out not filled indice + boolean_Reco_Start = (Reco_Start[:, 0] != -9999.) + Reco_Start = Reco_Start[boolean_Reco_Start] + boolean_Reco_End = (Reco_End[:, 0] != -9999.) + Reco_End = Reco_End[boolean_Reco_End] + boolean_Primary_Start = (Primary_True_Start[:, 0] != -9999.) + Primary_True_Start = Primary_True_Start[boolean_Primary_Start] + boolean_Primary_End = (Primary_True_End[:, 0] != -9999.) + Primary_True_End = Primary_True_End[boolean_Primary_End] + + # subtract reconstruction from truth for all directions + Diff_Start_x = Primary_True_Start[:, 0] - Reco_Start[:, 0] + Diff_Start_y = Primary_True_Start[:, 1] - Reco_Start[:, 1] + Diff_Start_z = Primary_True_Start[:, 2] - Reco_Start[:, 2] + Diff_End_x = Primary_True_End[:, 0] - Reco_End[:, 0] + Diff_End_y = Primary_True_End[:, 1] - Reco_End[:, 1] + Diff_End_z = Primary_True_End[:, 2] - Reco_End[:, 2] + + # create histograms for the differences + Diff_Start_x_hist, Diff_Start_x_bins = np.histogram(Diff_Start_x, bins = 50) + Diff_Start_y_hist, Diff_Start_y_bins = np.histogram(Diff_Start_y, bins = 50) + Diff_Start_z_hist, Diff_Start_z_bins = np.histogram(Diff_Start_z, bins = 50) + Diff_End_x_hist, Diff_End_x_bins = np.histogram(Diff_End_x, bins = 50) + Diff_End_y_hist, Diff_End_y_bins = np.histogram(Diff_End_y, bins = 50) + Diff_End_z_hist, Diff_End_z_bins = np.histogram(Diff_End_z, bins = 50) + + Diff_Start_x_histX, Diff_Start_x_histY = histogram_arr_handle(Diff_Start_x_hist, Diff_Start_x_bins) + Diff_Start_y_histX, Diff_Start_y_histY = histogram_arr_handle(Diff_Start_y_hist, Diff_Start_y_bins) + Diff_Start_z_histX, Diff_Start_z_histY = histogram_arr_handle(Diff_Start_z_hist, Diff_Start_z_bins) + Diff_End_x_histX, Diff_End_x_histY = histogram_arr_handle(Diff_End_x_hist, Diff_End_x_bins) + Diff_End_y_histX, Diff_End_y_histY = histogram_arr_handle(Diff_End_y_hist, Diff_End_y_bins) + Diff_End_z_histX, Diff_End_z_histY = histogram_arr_handle(Diff_End_z_hist, Diff_End_z_bins) + + # plot + mp.plot(Diff_Start_x_histX, Diff_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_x_histX, 0, Diff_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction [mm]') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Difference_Start_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_y_histX, Diff_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_y_histX, 0, Diff_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction [mm]') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Difference_Start_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_Start_z_histX, Diff_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_Start_z_histX, 0, Diff_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction [mm]') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Difference_Start_Z_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_x_histX, Diff_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_x_histX, 0, Diff_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction [mm]') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Difference_End_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_y_histX, Diff_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_y_histX, 0, Diff_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction [mm]') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Difference_End_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Diff_End_z_histX, Diff_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) + mp.fill_between(Diff_End_z_histX, 0, Diff_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.xlabel('Difference truth – reconstruction [mm]') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Difference_End_Z_hist.png', bbox_inches = 'tight') + mp.close() + + # create histograms for all directions for truth and reconstruction + Reco_Start_x_hist, Reco_Start_x_bins = np.histogram(Reco_Start[:, 0], bins = 48)#, range = (-3400., 3400.)) + Reco_Start_y_hist, Reco_Start_y_bins = np.histogram(Reco_Start[:, 1], bins = 20)#, range = (-4110., -910.)) + Reco_Start_z_hist, Reco_Start_z_bins = np.histogram(Reco_Start[:, 2], bins = 100)#, range = (11360., 18320.)) + Reco_End_x_hist, Reco_End_x_bins = np.histogram(Reco_End[:, 0], bins = 48)#, range = (-3400., 3400.)) + Reco_End_y_hist, Reco_End_y_bins = np.histogram(Reco_End[:, 1], bins = 20)#, range = (-4110., -910.)) + Reco_End_z_hist, Reco_End_z_bins = np.histogram(Reco_End[:, 2], bins = 100)#, range = (11360., 18320.)) + Primary_True_Start_x_hist, Primary_True_Start_x_bins = np.histogram(Primary_True_Start[:, 0], bins = 48) + Primary_True_Start_y_hist, Primary_True_Start_y_bins = np.histogram(Primary_True_Start[:, 1], bins = 20) + Primary_True_Start_z_hist, Primary_True_Start_z_bins = np.histogram(Primary_True_Start[:, 2], bins = 100) + Primary_True_End_x_hist, Primary_True_End_x_bins = np.histogram(Primary_True_End[:, 0], bins = 48) + Primary_True_End_y_hist, Primary_True_End_y_bins = np.histogram(Primary_True_End[:, 1], bins = 20) + Primary_True_End_z_hist, Primary_True_End_z_bins = np.histogram(Primary_True_End[:, 2], bins = 100) + + # make the histograms usable + Reco_Start_x_histX, Reco_Start_x_histY = histogram_arr_handle(Reco_Start_x_hist, Reco_Start_x_bins) + Reco_Start_y_histX, Reco_Start_y_histY = histogram_arr_handle(Reco_Start_y_hist, Reco_Start_y_bins) + Reco_Start_z_histX, Reco_Start_z_histY = histogram_arr_handle(Reco_Start_z_hist, Reco_Start_z_bins) + Reco_End_x_histX, Reco_End_x_histY = histogram_arr_handle(Reco_End_x_hist, Reco_End_x_bins) + Reco_End_y_histX, Reco_End_y_histY = histogram_arr_handle(Reco_End_y_hist, Reco_End_y_bins) + Reco_End_z_histX, Reco_End_z_histY = histogram_arr_handle(Reco_End_z_hist, Reco_End_z_bins) + Primary_True_Start_x_histX, Primary_True_Start_x_histY = histogram_arr_handle(Primary_True_Start_x_hist, Primary_True_Start_x_bins) + Primary_True_Start_y_histX, Primary_True_Start_y_histY = histogram_arr_handle(Primary_True_Start_y_hist, Primary_True_Start_y_bins) + Primary_True_Start_z_histX, Primary_True_Start_z_histY = histogram_arr_handle(Primary_True_Start_z_hist, Primary_True_Start_z_bins) + Primary_True_End_x_histX, Primary_True_End_x_histY = histogram_arr_handle(Primary_True_End_x_hist, Primary_True_End_x_bins) + Primary_True_End_y_histX, Primary_True_End_y_histY = histogram_arr_handle(Primary_True_End_y_hist, Primary_True_End_y_bins) + Primary_True_End_z_histX, Primary_True_End_z_histY = histogram_arr_handle(Primary_True_End_z_hist, Primary_True_End_z_bins) + + # now plot this + mp.plot(Primary_True_Start_x_histX, Primary_True_Start_x_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_x_histX, Reco_Start_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Primary_True_Start_x_histX, 0, Primary_True_Start_x_histY, color = blue_cbf, alpha = 0.6, hatch = '//') + mp.fill_between(Reco_Start_x_histX, 0, Reco_Start_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS [mm]') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Track_Start_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Primary_True_Start_y_histX, Primary_True_Start_y_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_y_histX, Reco_Start_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Primary_True_Start_y_histX, 0, Primary_True_Start_y_histY, color = blue_cbf, alpha = 0.6, hatch = '//') + mp.fill_between(Reco_Start_y_histX, 0, Reco_Start_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS [mm]') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Track_Start_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Primary_True_Start_z_histX, Primary_True_Start_z_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') + mp.plot(Reco_Start_z_histX, Reco_Start_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Primary_True_Start_z_histX, 0, Primary_True_Start_z_histY, color = blue_cbf, alpha = 0.6, hatch = '//') + mp.fill_between(Reco_Start_z_histX, 0, Reco_Start_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('Start in TMS [mm]') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Track_Start_Z_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Primary_True_End_x_histX, Primary_True_End_x_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') + mp.plot(Reco_End_x_histX, Reco_End_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Primary_True_End_x_histX, 0, Primary_True_End_x_histY, color = blue_cbf, alpha = 0.6, hatch = '//') + mp.fill_between(Reco_End_x_histX, 0, Reco_End_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS [mm]') + mp.ylabel('#') + mp.title('x') + mp.savefig('performance_plots_NERSC/Track_End_X_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Primary_True_End_y_histX, Primary_True_End_y_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') + mp.plot(Reco_End_y_histX, Reco_End_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Primary_True_End_y_histX, 0, Primary_True_End_y_histY, color = blue_cbf, alpha = 0.6, hatch = '//') + mp.fill_between(Reco_End_y_histX, 0, Reco_End_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS [mm]') + mp.ylabel('#') + mp.title('y') + mp.savefig('performance_plots_NERSC/Track_End_Y_hist.png', bbox_inches = 'tight') + mp.close() + + mp.plot(Primary_True_End_z_histX, Primary_True_End_z_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') + mp.plot(Reco_End_z_histX, Reco_End_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') + mp.fill_between(Primary_True_End_z_histX, 0, Primary_True_End_z_histY, color = blue_cbf, alpha = 0.6, hatch = '//') + mp.fill_between(Reco_End_z_histX, 0, Reco_End_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) + mp.grid(True, linestyle = '--', alpha = 0.2) + mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) + mp.xlabel('End in TMS [mm]') + mp.ylabel('#') + mp.title('z') + mp.savefig('performance_plots_NERSC/Track_End_Z_hist.png', bbox_inches = 'tight') + mp.close() + + ### plot difference in dependence of hit position + # create 2d histograms + dependence_Start_x_hist, dependence_Start_x_binsX, dependence_Start_x_binsY = np.histogram2d(Primary_True_Start[:, 0], Diff_Start_x, bins = [Primary_True_Start_x_bins, Diff_Start_x_bins]) + dependence_Start_y_hist, dependence_Start_y_binsX, dependence_Start_y_binsY = np.histogram2d(Primary_True_Start[:, 1], Diff_Start_y, bins = [Primary_True_Start_y_bins, Diff_Start_y_bins]) + dependence_Start_z_hist, dependence_Start_z_binsX, dependence_Start_z_binsY = np.histogram2d(Primary_True_Start[:, 2], Diff_Start_z, bins = [Primary_True_Start_z_bins, Diff_Start_z_bins]) + dependence_End_x_hist, dependence_End_x_binsX, dependence_End_x_binsY = np.histogram2d(Primary_True_End[:, 0], Diff_End_x, bins = [Primary_True_End_x_bins, Diff_End_x_bins]) + dependence_End_y_hist, dependence_End_y_binsX, dependence_End_y_binsY = np.histogram2d(Primary_True_End[:, 1], Diff_End_y, bins = [Primary_True_End_y_bins, Diff_End_y_bins]) + dependence_End_z_hist, dependence_End_z_binsX, dependence_End_z_binsY = np.histogram2d(Primary_True_End[:, 2], Diff_End_z, bins = [Primary_True_End_z_bins, Diff_End_z_bins]) + + cmap = cm.get_cmap('cividis'); + + im = mp.pcolormesh(dependence_Start_x_binsX, dependence_Start_x_binsY, np.transpose(dependence_Start_x_hist), cmap = cmap); + mp.xlabel('Start in TMS (X) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('x') + mp.colorbar(im); + mp.savefig('performance_plots_NERSC/Start_X_real_and_difference.png', bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_Start_y_binsX, dependence_Start_y_binsY, np.transpose(dependence_Start_y_hist), cmap = cmap); + mp.xlabel('Start in TMS (Y) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('y') + mp.colorbar(im); + mp.savefig('performance_plots_NERSC/Start_Y_real_and_difference.png', bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_Start_z_binsX, dependence_Start_z_binsY, np.transpose(dependence_Start_z_hist), cmap = cmap); + mp.xlabel('Start in TMS (Z) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('z') + mp.colorbar(im); + mp.savefig('performance_plots_NERSC/Start_Z_real_and_difference.png', bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_End_x_binsX, dependence_End_x_binsY, np.transpose(dependence_End_x_hist), cmap = cmap); + mp.xlabel('End in TMS (X) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('x') + mp.colorbar(im); + mp.savefig('performance_plots_NERSC/End_X_real_and_difference.png', bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_End_y_binsX, dependence_End_y_binsY, np.transpose(dependence_End_y_hist), cmap = cmap); + mp.xlabel('End in TMS (Y) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('y') + mp.colorbar(im); + mp.savefig('performance_plots_NERSC/End_Y_real_and_difference.png', bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_End_z_binsX, dependence_End_z_binsY, np.transpose(dependence_End_z_hist), cmap = cmap); + mp.xlabel('End in TMS (Z) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('z') + mp.colorbar(im); + mp.savefig('performance_plots_NERSC/End_Z_real_and_difference.png', bbox_inches = 'tight'); + mp.close(); + + + return + +def histogram_arr_handle(bins, edges):#(u bins,v edges) + """Function to calculated x- and y-values from np.histogram + + @param[in] bins: bin-values from np.histogram to be transformed into y-values + @param[in] edges: edge-values from np.histogram to be transformed into x-values + + @return: 1d-array containing the x-values and 1d-array containing the y-values + """ + x_output = np.zeros(2 * len(bins)) + y_output = np.zeros(2 * len(bins)) + #v edges to u*2 x-values + x_output[0] = edges[0] + counter = 1 + for i in range(1, len(x_output)-1, 2): + x_output[i] = edges[counter] + x_output[i + 1] = edges[counter] + counter = counter + 1 + x_output[-1] = edges[-1] + + #u bins to u*2 y-values + counter = 0 + for i in range(0, len(y_output), 2): + y_output[i] = bins[counter] + y_output[i + 1] = bins[counter] + counter = counter + 1 + + return x_output, y_output + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description = "Draws spills.") + parser.add_argument('--outdir', "-o", type = str, help = "The output dir. Will be made if it doesn't exist. Default = spills/", default = "spills") + parser.add_argument('--name', "-n", type = str, help = "The name of the output files. Will be __.png. Default = spill", default = "spill") + parser.add_argument('--input_filename', "-f", type = str, help = "The file with the events to draw.") + parser.add_argument('--spillnum', "-s", type = int, help = "The spill to draw. -1 for all", default = -1) + parser.add_argument('--timeslice', "-t", type = int, help = "The time slice to draw. -1 for all", default = -1) + parser.add_argument('--readout_filename', "-r", type = str, help = "(optional) A file with the raw readout.", default = "") + parser.add_argument('--only_true_tms_muons', help = "Only draw events with true muons inside the TMS", action = argparse.BooleanOptionalAction) + + args = parser.parse_args() + + out_dir = args.outdir + name = args.name + input_filename = args.input_filename + spill_number = args.spillnum + time_slice = args.timeslice + readout_filename = args.readout_filename + only_true_tms_muons = args.only_true_tms_muons + draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_filename, only_true_tms_muons) + From ca887cfd41e0b3aa6c8563393b7ac1f1593086dc Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Mon, 29 Apr 2024 07:42:05 -0500 Subject: [PATCH 4/7] Trying to fix the y position in the reconstruction --- config/TMS_Default_Config.toml | 2 +- src/TMS_Reco.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/config/TMS_Default_Config.toml b/config/TMS_Default_Config.toml index 0fc6796e..71da1a7d 100644 --- a/config/TMS_Default_Config.toml +++ b/config/TMS_Default_Config.toml @@ -110,7 +110,7 @@ # Draw PDF of "event display". Slows down reco considerably [Applications] DrawPDF = false - MaximumNEvents = -1 + MaximumNEvents = 10000 # Variables that have to do with the geometry or location of the detector [Geometry] diff --git a/src/TMS_Reco.cpp b/src/TMS_Reco.cpp index c5e4f1b1..41922d36 100644 --- a/src/TMS_Reco.cpp +++ b/src/TMS_Reco.cpp @@ -745,8 +745,8 @@ std::vector TMS_TrackFinder::TrackMatching3D() { #ifdef DEBUG std::cout << "3D matching" << std::endl; std::cout << "size Candidates: U: " << HoughCandidatesU.size() << " | V: " << HoughCandidatesV.size() << " | X: " << HoughCandidatesX.size() << std::endl; - #endif + std::vector returned; bool TimeSlicing = TMS_Manager::GetInstance().Get_Reco_TIME_RunTimeSlicer(); @@ -1271,15 +1271,15 @@ std::vector TMS_TrackFinder::TrackMatching3D() { } void TMS_TrackFinder::CalculateRecoY(TMS_Hit &OneHit, TMS_Hit &OtherHit) { -// TGeoManager *geom = TMS_Geom::GetInstance().GetGeometry(); -// Double_t localOne[3] = {OneHit.GetNotZ(), 0, OneHit.GetZ()}; -// Double_t localOther[3] = {OtherHit.GetNotZ(), 0, OtherHit.GetZ()}; -// Double_t positionOne[3]; -// Double_t positionOther[3]; -// geom->GetCurrentMatrix()->LocalToMaster(localOne, positionOne); // This gives us the position of the bars in x, y and z. Use only the y for now! -// geom->GetCurrentMatrix()->LocalToMaster(localOther, positionOther); + TGeoManager *geom = TMS_Geom::GetInstance().GetGeometry(); + Double_t localOne[3] = {OneHit.GetNotZ(), 0, OneHit.GetZ()}; + Double_t localOther[3] = {OtherHit.GetNotZ(), 0, OtherHit.GetZ()}; + Double_t positionOne[3]; + Double_t positionOther[3]; + geom->GetCurrentMatrix()->LocalToMaster(localOne, positionOne); // This gives us the position of the bars in x, y and z. Use only the y for now! + geom->GetCurrentMatrix()->LocalToMaster(localOther, positionOther); - OneHit.SetRecoY(-1350 - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(OneHit.GetNotZ() - OtherHit.GetNotZ())); //positionOne[1], positionOther[1] //0.5 * (OneHit.GetY() + OtherHit.GetY())//-1350 + OneHit.SetRecoY(0.5 * (positionOne[1] + positionOther[1]) - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(OneHit.GetNotZ() - OtherHit.GetNotZ())); //positionOne[1], positionOther[1] //0.5 * (OneHit.GetY() + OtherHit.GetY())//-1350 // USING THIS -1350 ALSO IN CompareY FUNCTION. CHANGE THERE AS WELL IF CHANGED HERE!!!!! return; } From c2d51f6917e0a40a80d26d82ddceeb76d161cc92 Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Tue, 30 Apr 2024 04:53:38 -0500 Subject: [PATCH 5/7] Trying to fix reco y calculation --- src/TMS_Reco.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TMS_Reco.cpp b/src/TMS_Reco.cpp index 41922d36..256c6fdd 100644 --- a/src/TMS_Reco.cpp +++ b/src/TMS_Reco.cpp @@ -726,7 +726,17 @@ void TMS_TrackFinder::FindPseudoXTrack() { double TMS_TrackFinder::CompareY(TMS_Hit &UHit, TMS_Hit &VHit, TMS_Hit &XHit) { // Calculate UV reconstruction of y and X hit y position - double UV_y = -1350 - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(UHit.GetNotZ() - VHit.GetNotZ()); + TGeoManager *geom = TMS_Geom::GetInstance().GetGeometry(); + Double_t localU[3] = {UHit.GetNotZ(), 0, UHit.GetZ()}; + Double_t localV[3] = {VHit.GetNotZ(), 0, VHit.GetZ()}; + Double_t positionU[3]; + Double_t positionV[3]; + geom->GetCurrentMatrix()->LocalToMaster(localU, positionU); // This gives us the position of the bars in x, y and z. Use only the y for now! + geom->GetCurrentMatrix()->LocalToMaster(localV, positionV); + TMS_Geom::GetInstance().Scale(positionU[0], positionU[1], positionU[2]); + TMS_Geom::GetInstance().Scale(positionV[0], positionV[1], positionV[2]); + + double UV_y = 0.5 * (positionU[1] + positionV[1]) - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(UHit.GetNotZ() - VHit.GetNotZ()); //-1350 double X_y = XHit.GetNotZ(); double compared_y = -999999; @@ -1278,6 +1288,8 @@ void TMS_TrackFinder::CalculateRecoY(TMS_Hit &OneHit, TMS_Hit &OtherHit) { Double_t positionOther[3]; geom->GetCurrentMatrix()->LocalToMaster(localOne, positionOne); // This gives us the position of the bars in x, y and z. Use only the y for now! geom->GetCurrentMatrix()->LocalToMaster(localOther, positionOther); + TMS_Geom::GetInstance().Scale(positionOne[0], positionOne[1], positionOne[2]); + TMS_Geom::GetInstance().Scale(positionOther[0], positionOther[1], positionOther[2]); OneHit.SetRecoY(0.5 * (positionOne[1] + positionOther[1]) - 0.5 * TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_TiltAngle() * std::abs(OneHit.GetNotZ() - OtherHit.GetNotZ())); //positionOne[1], positionOther[1] //0.5 * (OneHit.GetY() + OtherHit.GetY())//-1350 // USING THIS -1350 ALSO IN CompareY FUNCTION. CHANGE THERE AS WELL IF CHANGED HERE!!!!! From 75982b52c2b68f1ddd8e5cdf331c9a8e28968ddf Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Tue, 30 Apr 2024 04:57:24 -0500 Subject: [PATCH 6/7] Preparing for pull request as usual --- config/TMS_Default_Config.toml | 2 +- performance_reco.py | 414 --------------------------------- 2 files changed, 1 insertion(+), 415 deletions(-) delete mode 100755 performance_reco.py diff --git a/config/TMS_Default_Config.toml b/config/TMS_Default_Config.toml index 71da1a7d..0fc6796e 100644 --- a/config/TMS_Default_Config.toml +++ b/config/TMS_Default_Config.toml @@ -110,7 +110,7 @@ # Draw PDF of "event display". Slows down reco considerably [Applications] DrawPDF = false - MaximumNEvents = 10000 + MaximumNEvents = -1 # Variables that have to do with the geometry or location of the detector [Geometry] diff --git a/performance_reco.py b/performance_reco.py deleted file mode 100755 index 12986d95..00000000 --- a/performance_reco.py +++ /dev/null @@ -1,414 +0,0 @@ -import ROOT -import numpy as np -import matplotlib.pyplot as mp -import os -import argparse -import cppyy.ll -import matplotlib.cm as cm - -# plotstyle -red_cbf = '#d55e00' -blue_cbf = '#0072b2' -orange_cbf = '#e69f00' -magenta_cbf = '#cc79a7' -black_cbf = '#000000' -green_cbf = '#009e73' -mp.style.use('seaborn-poster') - -mp.rc('axes', labelsize = 12) # fontsize of the x and y labels -mp.rc('xtick', labelsize = 12) # fontsize of the tick labels -mp.rc('ytick', labelsize = 12) # fontsize of the tick labels - -### Actual function that loops through the spills -def draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_filename, only_true_tms_muons = False): - if not os.path.exists(input_filename): raise ValueError(f"Cannor find input_filename {input_filename}") - if readout_filename != "" and not os.path.exists(readout_filename): raise ValueError(f"Cannot find readout_filename {readout_filename}") - if spill_number < -1: raise ValueError(f"Got spill_number = {spill_number}") - if time_slice < -1: raise ValueError(f"Got time_slice = {time_slice}") - - # Make sure we read in the correct file and have the output directory - use_readout = True - if readout_filename == "": use_readout = False - if not os.path.exists(out_dir): - os.makedirs(out_dir) - if not os.path.exists(out_dir): - raise ValueError(f"Could not make out_dir {out_dir}") - - # Read in the Reco_Tree that contains the TMS_Tracks - r = ROOT.TChain("Reco_Tree") - r.Add(input_filename) - print("N entries:", r.GetEntries()) - if not r.GetEntries() > 0: - print("Didn't get any entries, are you sure the input_filename is right?\n", input_filename) - - truth = ROOT.TChain("Truth_Info") - truth.Add(input_filename) - if not truth.GetEntries() > 0: - print("Didn't get any entries in Truth_Info, are you sure the input_filename is right?\n", input_filename) - - # Not used yet - readout = None - if use_readout: - readout = ROOT.TChain("TMS") - readout.Add(readout_filename) - if not readout.GetEntries() > 0: - print("Didnt't get any entries in TMS, are you sure the readout_filename is right?\n", readout_filename) - - max_n_spills = 10000 # TODO (old) add some meta info to output file with n spill info for file - - simplify_tracks = False - - spill_number_cache = dict() - n_events = r.GetEntries() - - Reco_Start = np.ones((n_events, 3), dtype = float) * -9999. - Reco_End = np.ones((n_events, 3), dtype = float) * -9999. - Primary_True_Start = np.ones((n_events, 3), dtype = float) * -9999. - Primary_True_End = np.ones((n_events, 3), dtype = float) * -9999. - - for current_spill_number in range(max_n_spills): - for i in range(n_events): - try: - spill_number = spill_number_cache[i] - event = None - true_event = None - except KeyError: - r.GetEntry(i) - event = r - truth.GetEntry(i) - true_event = truth - spill_number = event.SpillNo - spill_number_cache[i] = spill_number - if spill_number < current_spill_number: continue - if spill_number > current_spill_number: break - if event == None: - r.GetEntry(i) - event = r - if true_event == None: - truth.GetEntry(i) - true_event = truth - - nTracks = event.nTracks - if nTracks <= 0: continue - - StartPos = np.frombuffer(event.StartPos, dtype = np.float32) - EndPos = np.frombuffer(event.EndPos, dtype = np.float32) - RecoTrackPrimaryParticleTruePositionTrackStart = np.frombuffer(true_event.RecoTrackPrimaryParticleTruePositionTrackStart, dtype = np.float32) - RecoTrackPrimaryParticleTruePositionTrackEnd = np.frombuffer(true_event.RecoTrackPrimaryParticleTruePositionTrackEnd, dtype = np.float32) - - if RecoTrackPrimaryParticleTruePositionTrackStart[0] > -8000. and not StartPos.size == 0: - Reco_Start[i, 0] = StartPos[0] - Reco_Start[i, 1] = StartPos[1] - Reco_Start[i, 2] = StartPos[2] - Primary_True_Start[i, 0] = RecoTrackPrimaryParticleTruePositionTrackStart[0] - Primary_True_Start[i, 1] = RecoTrackPrimaryParticleTruePositionTrackStart[1] - Primary_True_Start[i, 2] = RecoTrackPrimaryParticleTruePositionTrackStart[2] - if RecoTrackPrimaryParticleTruePositionTrackEnd[0] > -8000. and not EndPos.size == 0: - Reco_End[i, 0] = EndPos[0] - Reco_End[i, 1] = EndPos[1] - Reco_End[i, 2] = EndPos[2] - Primary_True_End[i, 0] = RecoTrackPrimaryParticleTruePositionTrackEnd[0] - Primary_True_End[i, 1] = RecoTrackPrimaryParticleTruePositionTrackEnd[1] - Primary_True_End[i, 2] = RecoTrackPrimaryParticleTruePositionTrackEnd[2] - - # filter out not filled indice - boolean_Reco_Start = (Reco_Start[:, 0] != -9999.) - Reco_Start = Reco_Start[boolean_Reco_Start] - boolean_Reco_End = (Reco_End[:, 0] != -9999.) - Reco_End = Reco_End[boolean_Reco_End] - boolean_Primary_Start = (Primary_True_Start[:, 0] != -9999.) - Primary_True_Start = Primary_True_Start[boolean_Primary_Start] - boolean_Primary_End = (Primary_True_End[:, 0] != -9999.) - Primary_True_End = Primary_True_End[boolean_Primary_End] - - # subtract reconstruction from truth for all directions - Diff_Start_x = Primary_True_Start[:, 0] - Reco_Start[:, 0] - Diff_Start_y = Primary_True_Start[:, 1] - Reco_Start[:, 1] - Diff_Start_z = Primary_True_Start[:, 2] - Reco_Start[:, 2] - Diff_End_x = Primary_True_End[:, 0] - Reco_End[:, 0] - Diff_End_y = Primary_True_End[:, 1] - Reco_End[:, 1] - Diff_End_z = Primary_True_End[:, 2] - Reco_End[:, 2] - - # create histograms for the differences - Diff_Start_x_hist, Diff_Start_x_bins = np.histogram(Diff_Start_x, bins = 50) - Diff_Start_y_hist, Diff_Start_y_bins = np.histogram(Diff_Start_y, bins = 50) - Diff_Start_z_hist, Diff_Start_z_bins = np.histogram(Diff_Start_z, bins = 50) - Diff_End_x_hist, Diff_End_x_bins = np.histogram(Diff_End_x, bins = 50) - Diff_End_y_hist, Diff_End_y_bins = np.histogram(Diff_End_y, bins = 50) - Diff_End_z_hist, Diff_End_z_bins = np.histogram(Diff_End_z, bins = 50) - - Diff_Start_x_histX, Diff_Start_x_histY = histogram_arr_handle(Diff_Start_x_hist, Diff_Start_x_bins) - Diff_Start_y_histX, Diff_Start_y_histY = histogram_arr_handle(Diff_Start_y_hist, Diff_Start_y_bins) - Diff_Start_z_histX, Diff_Start_z_histY = histogram_arr_handle(Diff_Start_z_hist, Diff_Start_z_bins) - Diff_End_x_histX, Diff_End_x_histY = histogram_arr_handle(Diff_End_x_hist, Diff_End_x_bins) - Diff_End_y_histX, Diff_End_y_histY = histogram_arr_handle(Diff_End_y_hist, Diff_End_y_bins) - Diff_End_z_histX, Diff_End_z_histY = histogram_arr_handle(Diff_End_z_hist, Diff_End_z_bins) - - # plot - mp.plot(Diff_Start_x_histX, Diff_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_Start_x_histX, 0, Diff_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction [mm]') - mp.ylabel('#') - mp.title('x') - mp.savefig('performance_plots_NERSC/Difference_Start_X_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_Start_y_histX, Diff_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_Start_y_histX, 0, Diff_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction [mm]') - mp.ylabel('#') - mp.title('y') - mp.savefig('performance_plots_NERSC/Difference_Start_Y_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_Start_z_histX, Diff_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_Start_z_histX, 0, Diff_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction [mm]') - mp.ylabel('#') - mp.title('z') - mp.savefig('performance_plots_NERSC/Difference_Start_Z_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_End_x_histX, Diff_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_End_x_histX, 0, Diff_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction [mm]') - mp.ylabel('#') - mp.title('x') - mp.savefig('performance_plots_NERSC/Difference_End_X_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_End_y_histX, Diff_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_End_y_histX, 0, Diff_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction [mm]') - mp.ylabel('#') - mp.title('y') - mp.savefig('performance_plots_NERSC/Difference_End_Y_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_End_z_histX, Diff_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_End_z_histX, 0, Diff_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction [mm]') - mp.ylabel('#') - mp.title('z') - mp.savefig('performance_plots_NERSC/Difference_End_Z_hist.png', bbox_inches = 'tight') - mp.close() - - # create histograms for all directions for truth and reconstruction - Reco_Start_x_hist, Reco_Start_x_bins = np.histogram(Reco_Start[:, 0], bins = 48)#, range = (-3400., 3400.)) - Reco_Start_y_hist, Reco_Start_y_bins = np.histogram(Reco_Start[:, 1], bins = 20)#, range = (-4110., -910.)) - Reco_Start_z_hist, Reco_Start_z_bins = np.histogram(Reco_Start[:, 2], bins = 100)#, range = (11360., 18320.)) - Reco_End_x_hist, Reco_End_x_bins = np.histogram(Reco_End[:, 0], bins = 48)#, range = (-3400., 3400.)) - Reco_End_y_hist, Reco_End_y_bins = np.histogram(Reco_End[:, 1], bins = 20)#, range = (-4110., -910.)) - Reco_End_z_hist, Reco_End_z_bins = np.histogram(Reco_End[:, 2], bins = 100)#, range = (11360., 18320.)) - Primary_True_Start_x_hist, Primary_True_Start_x_bins = np.histogram(Primary_True_Start[:, 0], bins = 48) - Primary_True_Start_y_hist, Primary_True_Start_y_bins = np.histogram(Primary_True_Start[:, 1], bins = 20) - Primary_True_Start_z_hist, Primary_True_Start_z_bins = np.histogram(Primary_True_Start[:, 2], bins = 100) - Primary_True_End_x_hist, Primary_True_End_x_bins = np.histogram(Primary_True_End[:, 0], bins = 48) - Primary_True_End_y_hist, Primary_True_End_y_bins = np.histogram(Primary_True_End[:, 1], bins = 20) - Primary_True_End_z_hist, Primary_True_End_z_bins = np.histogram(Primary_True_End[:, 2], bins = 100) - - # make the histograms usable - Reco_Start_x_histX, Reco_Start_x_histY = histogram_arr_handle(Reco_Start_x_hist, Reco_Start_x_bins) - Reco_Start_y_histX, Reco_Start_y_histY = histogram_arr_handle(Reco_Start_y_hist, Reco_Start_y_bins) - Reco_Start_z_histX, Reco_Start_z_histY = histogram_arr_handle(Reco_Start_z_hist, Reco_Start_z_bins) - Reco_End_x_histX, Reco_End_x_histY = histogram_arr_handle(Reco_End_x_hist, Reco_End_x_bins) - Reco_End_y_histX, Reco_End_y_histY = histogram_arr_handle(Reco_End_y_hist, Reco_End_y_bins) - Reco_End_z_histX, Reco_End_z_histY = histogram_arr_handle(Reco_End_z_hist, Reco_End_z_bins) - Primary_True_Start_x_histX, Primary_True_Start_x_histY = histogram_arr_handle(Primary_True_Start_x_hist, Primary_True_Start_x_bins) - Primary_True_Start_y_histX, Primary_True_Start_y_histY = histogram_arr_handle(Primary_True_Start_y_hist, Primary_True_Start_y_bins) - Primary_True_Start_z_histX, Primary_True_Start_z_histY = histogram_arr_handle(Primary_True_Start_z_hist, Primary_True_Start_z_bins) - Primary_True_End_x_histX, Primary_True_End_x_histY = histogram_arr_handle(Primary_True_End_x_hist, Primary_True_End_x_bins) - Primary_True_End_y_histX, Primary_True_End_y_histY = histogram_arr_handle(Primary_True_End_y_hist, Primary_True_End_y_bins) - Primary_True_End_z_histX, Primary_True_End_z_histY = histogram_arr_handle(Primary_True_End_z_hist, Primary_True_End_z_bins) - - # now plot this - mp.plot(Primary_True_Start_x_histX, Primary_True_Start_x_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') - mp.plot(Reco_Start_x_histX, Reco_Start_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Primary_True_Start_x_histX, 0, Primary_True_Start_x_histY, color = blue_cbf, alpha = 0.6, hatch = '//') - mp.fill_between(Reco_Start_x_histX, 0, Reco_Start_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS [mm]') - mp.ylabel('#') - mp.title('x') - mp.savefig('performance_plots_NERSC/Track_Start_X_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Primary_True_Start_y_histX, Primary_True_Start_y_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') - mp.plot(Reco_Start_y_histX, Reco_Start_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Primary_True_Start_y_histX, 0, Primary_True_Start_y_histY, color = blue_cbf, alpha = 0.6, hatch = '//') - mp.fill_between(Reco_Start_y_histX, 0, Reco_Start_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS [mm]') - mp.ylabel('#') - mp.title('y') - mp.savefig('performance_plots_NERSC/Track_Start_Y_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Primary_True_Start_z_histX, Primary_True_Start_z_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') - mp.plot(Reco_Start_z_histX, Reco_Start_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Primary_True_Start_z_histX, 0, Primary_True_Start_z_histY, color = blue_cbf, alpha = 0.6, hatch = '//') - mp.fill_between(Reco_Start_z_histX, 0, Reco_Start_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS [mm]') - mp.ylabel('#') - mp.title('z') - mp.savefig('performance_plots_NERSC/Track_Start_Z_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Primary_True_End_x_histX, Primary_True_End_x_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') - mp.plot(Reco_End_x_histX, Reco_End_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Primary_True_End_x_histX, 0, Primary_True_End_x_histY, color = blue_cbf, alpha = 0.6, hatch = '//') - mp.fill_between(Reco_End_x_histX, 0, Reco_End_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS [mm]') - mp.ylabel('#') - mp.title('x') - mp.savefig('performance_plots_NERSC/Track_End_X_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Primary_True_End_y_histX, Primary_True_End_y_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') - mp.plot(Reco_End_y_histX, Reco_End_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Primary_True_End_y_histX, 0, Primary_True_End_y_histY, color = blue_cbf, alpha = 0.6, hatch = '//') - mp.fill_between(Reco_End_y_histX, 0, Reco_End_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS [mm]') - mp.ylabel('#') - mp.title('y') - mp.savefig('performance_plots_NERSC/Track_End_Y_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Primary_True_End_z_histX, Primary_True_End_z_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') - mp.plot(Reco_End_z_histX, Reco_End_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Primary_True_End_z_histX, 0, Primary_True_End_z_histY, color = blue_cbf, alpha = 0.6, hatch = '//') - mp.fill_between(Reco_End_z_histX, 0, Reco_End_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS [mm]') - mp.ylabel('#') - mp.title('z') - mp.savefig('performance_plots_NERSC/Track_End_Z_hist.png', bbox_inches = 'tight') - mp.close() - - ### plot difference in dependence of hit position - # create 2d histograms - dependence_Start_x_hist, dependence_Start_x_binsX, dependence_Start_x_binsY = np.histogram2d(Primary_True_Start[:, 0], Diff_Start_x, bins = [Primary_True_Start_x_bins, Diff_Start_x_bins]) - dependence_Start_y_hist, dependence_Start_y_binsX, dependence_Start_y_binsY = np.histogram2d(Primary_True_Start[:, 1], Diff_Start_y, bins = [Primary_True_Start_y_bins, Diff_Start_y_bins]) - dependence_Start_z_hist, dependence_Start_z_binsX, dependence_Start_z_binsY = np.histogram2d(Primary_True_Start[:, 2], Diff_Start_z, bins = [Primary_True_Start_z_bins, Diff_Start_z_bins]) - dependence_End_x_hist, dependence_End_x_binsX, dependence_End_x_binsY = np.histogram2d(Primary_True_End[:, 0], Diff_End_x, bins = [Primary_True_End_x_bins, Diff_End_x_bins]) - dependence_End_y_hist, dependence_End_y_binsX, dependence_End_y_binsY = np.histogram2d(Primary_True_End[:, 1], Diff_End_y, bins = [Primary_True_End_y_bins, Diff_End_y_bins]) - dependence_End_z_hist, dependence_End_z_binsX, dependence_End_z_binsY = np.histogram2d(Primary_True_End[:, 2], Diff_End_z, bins = [Primary_True_End_z_bins, Diff_End_z_bins]) - - cmap = cm.get_cmap('cividis'); - - im = mp.pcolormesh(dependence_Start_x_binsX, dependence_Start_x_binsY, np.transpose(dependence_Start_x_hist), cmap = cmap); - mp.xlabel('Start in TMS (X) [mm]') - mp.ylabel('Difference truth - reco [mm]') - mp.title('x') - mp.colorbar(im); - mp.savefig('performance_plots_NERSC/Start_X_real_and_difference.png', bbox_inches = 'tight'); - mp.close(); - - im = mp.pcolormesh(dependence_Start_y_binsX, dependence_Start_y_binsY, np.transpose(dependence_Start_y_hist), cmap = cmap); - mp.xlabel('Start in TMS (Y) [mm]') - mp.ylabel('Difference truth - reco [mm]') - mp.title('y') - mp.colorbar(im); - mp.savefig('performance_plots_NERSC/Start_Y_real_and_difference.png', bbox_inches = 'tight'); - mp.close(); - - im = mp.pcolormesh(dependence_Start_z_binsX, dependence_Start_z_binsY, np.transpose(dependence_Start_z_hist), cmap = cmap); - mp.xlabel('Start in TMS (Z) [mm]') - mp.ylabel('Difference truth - reco [mm]') - mp.title('z') - mp.colorbar(im); - mp.savefig('performance_plots_NERSC/Start_Z_real_and_difference.png', bbox_inches = 'tight'); - mp.close(); - - im = mp.pcolormesh(dependence_End_x_binsX, dependence_End_x_binsY, np.transpose(dependence_End_x_hist), cmap = cmap); - mp.xlabel('End in TMS (X) [mm]') - mp.ylabel('Difference truth - reco [mm]') - mp.title('x') - mp.colorbar(im); - mp.savefig('performance_plots_NERSC/End_X_real_and_difference.png', bbox_inches = 'tight'); - mp.close(); - - im = mp.pcolormesh(dependence_End_y_binsX, dependence_End_y_binsY, np.transpose(dependence_End_y_hist), cmap = cmap); - mp.xlabel('End in TMS (Y) [mm]') - mp.ylabel('Difference truth - reco [mm]') - mp.title('y') - mp.colorbar(im); - mp.savefig('performance_plots_NERSC/End_Y_real_and_difference.png', bbox_inches = 'tight'); - mp.close(); - - im = mp.pcolormesh(dependence_End_z_binsX, dependence_End_z_binsY, np.transpose(dependence_End_z_hist), cmap = cmap); - mp.xlabel('End in TMS (Z) [mm]') - mp.ylabel('Difference truth - reco [mm]') - mp.title('z') - mp.colorbar(im); - mp.savefig('performance_plots_NERSC/End_Z_real_and_difference.png', bbox_inches = 'tight'); - mp.close(); - - - return - -def histogram_arr_handle(bins, edges):#(u bins,v edges) - """Function to calculated x- and y-values from np.histogram - - @param[in] bins: bin-values from np.histogram to be transformed into y-values - @param[in] edges: edge-values from np.histogram to be transformed into x-values - - @return: 1d-array containing the x-values and 1d-array containing the y-values - """ - x_output = np.zeros(2 * len(bins)) - y_output = np.zeros(2 * len(bins)) - #v edges to u*2 x-values - x_output[0] = edges[0] - counter = 1 - for i in range(1, len(x_output)-1, 2): - x_output[i] = edges[counter] - x_output[i + 1] = edges[counter] - counter = counter + 1 - x_output[-1] = edges[-1] - - #u bins to u*2 y-values - counter = 0 - for i in range(0, len(y_output), 2): - y_output[i] = bins[counter] - y_output[i + 1] = bins[counter] - counter = counter + 1 - - return x_output, y_output - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description = "Draws spills.") - parser.add_argument('--outdir', "-o", type = str, help = "The output dir. Will be made if it doesn't exist. Default = spills/", default = "spills") - parser.add_argument('--name', "-n", type = str, help = "The name of the output files. Will be __.png. Default = spill", default = "spill") - parser.add_argument('--input_filename', "-f", type = str, help = "The file with the events to draw.") - parser.add_argument('--spillnum', "-s", type = int, help = "The spill to draw. -1 for all", default = -1) - parser.add_argument('--timeslice', "-t", type = int, help = "The time slice to draw. -1 for all", default = -1) - parser.add_argument('--readout_filename', "-r", type = str, help = "(optional) A file with the raw readout.", default = "") - parser.add_argument('--only_true_tms_muons', help = "Only draw events with true muons inside the TMS", action = argparse.BooleanOptionalAction) - - args = parser.parse_args() - - out_dir = args.outdir - name = args.name - input_filename = args.input_filename - spill_number = args.spillnum - time_slice = args.timeslice - readout_filename = args.readout_filename - only_true_tms_muons = args.only_true_tms_muons - draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_filename, only_true_tms_muons) - From 6ca527e37a93838271852989a6935b419220573d Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Tue, 30 Apr 2024 04:59:14 -0500 Subject: [PATCH 7/7] Updating file path naming in performance_reco script --- scripts/Reco/performance_reco.py | 348 +++++++++++++------------------ 1 file changed, 140 insertions(+), 208 deletions(-) diff --git a/scripts/Reco/performance_reco.py b/scripts/Reco/performance_reco.py index 1586405d..439f007d 100755 --- a/scripts/Reco/performance_reco.py +++ b/scripts/Reco/performance_reco.py @@ -4,6 +4,7 @@ import os import argparse import cppyy.ll +import matplotlib.cm as cm # plotstyle red_cbf = '#d55e00' @@ -60,10 +61,10 @@ def draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_ spill_number_cache = dict() n_events = r.GetEntries() - Position_TMS_Start = np.empty((n_events, 3), dtype = float) * -9999. - Position_TMS_End = np.empty((n_events, 3), dtype = float) * -9999. - Reco_Start = np.empty((n_events, 3), dtype = float) * -9999. - Reco_End = np.empty((n_events, 3), dtype = float) * -9999. + Reco_Start = np.ones((n_events, 3), dtype = float) * -9999. + Reco_End = np.ones((n_events, 3), dtype = float) * -9999. + Primary_True_Start = np.ones((n_events, 3), dtype = float) * -9999. + Primary_True_End = np.ones((n_events, 3), dtype = float) * -9999. for current_spill_number in range(max_n_spills): for i in range(n_events): @@ -89,34 +90,44 @@ def draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_ nTracks = event.nTracks if nTracks <= 0: continue - - PositionTMSStart = np.frombuffer(true_event.PositionTMSStart, dtype = np.float32) - PositionTMSEnd = np.frombuffer(true_event.PositionTMSEnd, dtype = np.float32) + StartPos = np.frombuffer(event.StartPos, dtype = np.float32) EndPos = np.frombuffer(event.EndPos, dtype = np.float32) + RecoTrackPrimaryParticleTruePositionTrackStart = np.frombuffer(true_event.RecoTrackPrimaryParticleTruePositionTrackStart, dtype = np.float32) + RecoTrackPrimaryParticleTruePositionTrackEnd = np.frombuffer(true_event.RecoTrackPrimaryParticleTruePositionTrackEnd, dtype = np.float32) - if PositionTMSStart[0] > -8000. and not StartPos.size == 0: - Position_TMS_Start[i, 0] = PositionTMSStart[0] - Position_TMS_Start[i, 1] = PositionTMSStart[1] - Position_TMS_Start[i, 2] = PositionTMSStart[2] + if RecoTrackPrimaryParticleTruePositionTrackStart[0] > -8000. and not StartPos.size == 0: Reco_Start[i, 0] = StartPos[0] Reco_Start[i, 1] = StartPos[1] - Reco_Start[i, 2] = StartPos[2] - if PositionTMSStart[0] > -8000. and not EndPos.size == 0: - Position_TMS_End[i, 0] = PositionTMSEnd[0] - Position_TMS_End[i, 1] = PositionTMSEnd[1] - Position_TMS_End[i, 2] = PositionTMSEnd[2] + Reco_Start[i, 2] = StartPos[2] + Primary_True_Start[i, 0] = RecoTrackPrimaryParticleTruePositionTrackStart[0] + Primary_True_Start[i, 1] = RecoTrackPrimaryParticleTruePositionTrackStart[1] + Primary_True_Start[i, 2] = RecoTrackPrimaryParticleTruePositionTrackStart[2] + if RecoTrackPrimaryParticleTruePositionTrackEnd[0] > -8000. and not EndPos.size == 0: Reco_End[i, 0] = EndPos[0] Reco_End[i, 1] = EndPos[1] Reco_End[i, 2] = EndPos[2] + Primary_True_End[i, 0] = RecoTrackPrimaryParticleTruePositionTrackEnd[0] + Primary_True_End[i, 1] = RecoTrackPrimaryParticleTruePositionTrackEnd[1] + Primary_True_End[i, 2] = RecoTrackPrimaryParticleTruePositionTrackEnd[2] + + # filter out not filled indice + boolean_Reco_Start = (Reco_Start[:, 0] != -9999.) + Reco_Start = Reco_Start[boolean_Reco_Start] + boolean_Reco_End = (Reco_End[:, 0] != -9999.) + Reco_End = Reco_End[boolean_Reco_End] + boolean_Primary_Start = (Primary_True_Start[:, 0] != -9999.) + Primary_True_Start = Primary_True_Start[boolean_Primary_Start] + boolean_Primary_End = (Primary_True_End[:, 0] != -9999.) + Primary_True_End = Primary_True_End[boolean_Primary_End] # subtract reconstruction from truth for all directions - Diff_Start_x = Position_TMS_Start[:, 0] - Reco_Start[:, 0] - Diff_Start_y = Position_TMS_Start[:, 1] - Reco_Start[:, 1] - Diff_Start_z = Position_TMS_Start[:, 2] - Reco_Start[:, 2] - Diff_End_x = Position_TMS_End[:, 0] - Reco_End[:, 0] - Diff_End_y = Position_TMS_End[:, 1] - Reco_End[:, 1] - Diff_End_z = Position_TMS_End[:, 2] - Reco_End[:, 2] + Diff_Start_x = Primary_True_Start[:, 0] - Reco_Start[:, 0] + Diff_Start_y = Primary_True_Start[:, 1] - Reco_Start[:, 1] + Diff_Start_z = Primary_True_Start[:, 2] - Reco_Start[:, 2] + Diff_End_x = Primary_True_End[:, 0] - Reco_End[:, 0] + Diff_End_y = Primary_True_End[:, 1] - Reco_End[:, 1] + Diff_End_z = Primary_True_End[:, 2] - Reco_End[:, 2] # create histograms for the differences Diff_Start_x_hist, Diff_Start_x_bins = np.histogram(Diff_Start_x, bins = 50) @@ -137,296 +148,217 @@ def draw_spill(out_dir, name, input_filename, spill_number, time_slice, readout_ mp.plot(Diff_Start_x_histX, Diff_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) mp.fill_between(Diff_Start_x_histX, 0, Diff_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') + mp.xlabel('Difference truth – reconstruction [mm]') mp.ylabel('#') mp.title('x') - mp.savefig('performance_plots_NERSC/Difference_Start_X_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Difference_Start_X_hist.png' % out_dir, bbox_inches = 'tight') mp.close() mp.plot(Diff_Start_y_histX, Diff_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) mp.fill_between(Diff_Start_y_histX, 0, Diff_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') + mp.xlabel('Difference truth – reconstruction [mm]') mp.ylabel('#') mp.title('y') - mp.savefig('performance_plots_NERSC/Difference_Start_Y_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Difference_Start_Y_hist.png' % out_dir, bbox_inches = 'tight') mp.close() mp.plot(Diff_Start_z_histX, Diff_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) mp.fill_between(Diff_Start_z_histX, 0, Diff_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') + mp.xlabel('Difference truth – reconstruction [mm]') mp.ylabel('#') mp.title('z') - mp.savefig('performance_plots_NERSC/Difference_Start_Z_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Difference_Start_Z_hist.png' % out_dir, bbox_inches = 'tight') mp.close() mp.plot(Diff_End_x_histX, Diff_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) mp.fill_between(Diff_End_x_histX, 0, Diff_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') + mp.xlabel('Difference truth – reconstruction [mm]') mp.ylabel('#') mp.title('x') - mp.savefig('performance_plots_NERSC/Difference_End_X_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Difference_End_X_hist.png' % out_dir, bbox_inches = 'tight') mp.close() mp.plot(Diff_End_y_histX, Diff_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) mp.fill_between(Diff_End_y_histX, 0, Diff_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') + mp.xlabel('Difference truth – reconstruction [mm]') mp.ylabel('#') mp.title('y') - mp.savefig('performance_plots_NERSC/Difference_End_Y_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Difference_End_Y_hist.png' % out_dir, bbox_inches = 'tight') mp.close() mp.plot(Diff_End_z_histX, Diff_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) mp.fill_between(Diff_End_z_histX, 0, Diff_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') + mp.xlabel('Difference truth – reconstruction [mm]') mp.ylabel('#') mp.title('z') - mp.savefig('performance_plots_NERSC/Difference_End_Z_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_Start_x_histX, Diff_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_Start_x_histX, 0, Diff_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') - mp.ylabel('#') - mp.title('x') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Difference_Start_X_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_Start_y_histX, Diff_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_Start_y_histX, 0, Diff_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') - mp.ylabel('#') - mp.title('y') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Difference_Start_Y_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_Start_z_histX, Diff_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_Start_z_histX, 0, Diff_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') - mp.ylabel('#') - mp.title('z') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Difference_Start_Z_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_End_x_histX, Diff_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_End_x_histX, 0, Diff_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') - mp.ylabel('#') - mp.title('x') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Difference_End_X_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_End_y_histX, Diff_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_End_y_histX, 0, Diff_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') - mp.ylabel('#') - mp.title('y') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Difference_End_Y_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Diff_End_z_histX, Diff_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2) - mp.fill_between(Diff_End_z_histX, 0, Diff_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.xlabel('Difference truth – reconstruction') - mp.ylabel('#') - mp.title('z') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Difference_End_Z_hist_log.png', bbox_inches = 'tight') - mp.close() + mp.savefig('%s/Difference_End_Z_hist.png' % out_dir, bbox_inches = 'tight') + mp.close() # create histograms for all directions for truth and reconstruction - Position_TMS_Start_x_hist, Position_TMS_Start_x_bins = np.histogram(Position_TMS_Start[:, 0], bins = 192)#, range = (-3400., 3400.)) - Position_TMS_Start_y_hist, Position_TMS_Start_y_bins = np.histogram(Position_TMS_Start[:, 1], bins = 100)#, range = (-4110., -910.)) - Position_TMS_Start_z_hist, Position_TMS_Start_z_bins = np.histogram(Position_TMS_Start[:, 2], bins = 100)#, range = (11360., 18320.)) - Position_TMS_End_x_hist, Position_TMS_End_x_bins = np.histogram(Position_TMS_End[:, 0], bins = 192)#, range = (-3400., 3400.)) - Position_TMS_End_y_hist, Position_TMS_End_y_bins = np.histogram(Position_TMS_End[:, 1], bins = 100)#, range = (-4110., -910.)) - Position_TMS_End_z_hist, Position_TMS_End_z_bins = np.histogram(Position_TMS_End[:, 2], bins = 100)#, range = (11360., 18320.)) - Reco_Start_x_hist, Reco_Start_x_bins = np.histogram(Reco_Start[:, 0], bins = 192)#, range = (-3400., 3400.)) - Reco_Start_y_hist, Reco_Start_y_bins = np.histogram(Reco_Start[:, 1], bins = 20)#, range = (-4110., -910.)) + Reco_Start_x_hist, Reco_Start_x_bins = np.histogram(Reco_Start[:, 0], bins = 48)#, range = (-3400., 3400.)) + Reco_Start_y_hist, Reco_Start_y_bins = np.histogram(Reco_Start[:, 1], bins = 40)#, range = (-4110., -910.)) Reco_Start_z_hist, Reco_Start_z_bins = np.histogram(Reco_Start[:, 2], bins = 100)#, range = (11360., 18320.)) - Reco_End_x_hist, Reco_End_x_bins = np.histogram(Reco_End[:, 0], bins = 192)#, range = (-3400., 3400.)) - Reco_End_y_hist, Reco_End_y_bins = np.histogram(Reco_End[:, 1], bins = 20)#, range = (-4110., -910.)) + Reco_End_x_hist, Reco_End_x_bins = np.histogram(Reco_End[:, 0], bins = 48)#, range = (-3400., 3400.)) + Reco_End_y_hist, Reco_End_y_bins = np.histogram(Reco_End[:, 1], bins = 40)#, range = (-4110., -910.)) Reco_End_z_hist, Reco_End_z_bins = np.histogram(Reco_End[:, 2], bins = 100)#, range = (11360., 18320.)) + Primary_True_Start_x_hist, Primary_True_Start_x_bins = np.histogram(Primary_True_Start[:, 0], bins = 48) + Primary_True_Start_y_hist, Primary_True_Start_y_bins = np.histogram(Primary_True_Start[:, 1], bins = 20) + Primary_True_Start_z_hist, Primary_True_Start_z_bins = np.histogram(Primary_True_Start[:, 2], bins = 100) + Primary_True_End_x_hist, Primary_True_End_x_bins = np.histogram(Primary_True_End[:, 0], bins = 48) + Primary_True_End_y_hist, Primary_True_End_y_bins = np.histogram(Primary_True_End[:, 1], bins = 20) + Primary_True_End_z_hist, Primary_True_End_z_bins = np.histogram(Primary_True_End[:, 2], bins = 100) # make the histograms usable - Position_TMS_Start_x_histX, Position_TMS_Start_x_histY = histogram_arr_handle(Position_TMS_Start_x_hist, Position_TMS_Start_x_bins) - Position_TMS_Start_y_histX, Position_TMS_Start_y_histY = histogram_arr_handle(Position_TMS_Start_y_hist, Position_TMS_Start_y_bins) - Position_TMS_Start_z_histX, Position_TMS_Start_z_histY = histogram_arr_handle(Position_TMS_Start_z_hist, Position_TMS_Start_z_bins) - Position_TMS_End_x_histX, Position_TMS_End_x_histY = histogram_arr_handle(Position_TMS_End_x_hist, Position_TMS_End_x_bins) - Position_TMS_End_y_histX, Position_TMS_End_y_histY = histogram_arr_handle(Position_TMS_End_y_hist, Position_TMS_End_y_bins) - Position_TMS_End_z_histX, Position_TMS_End_z_histY = histogram_arr_handle(Position_TMS_End_z_hist, Position_TMS_End_z_bins) Reco_Start_x_histX, Reco_Start_x_histY = histogram_arr_handle(Reco_Start_x_hist, Reco_Start_x_bins) Reco_Start_y_histX, Reco_Start_y_histY = histogram_arr_handle(Reco_Start_y_hist, Reco_Start_y_bins) Reco_Start_z_histX, Reco_Start_z_histY = histogram_arr_handle(Reco_Start_z_hist, Reco_Start_z_bins) Reco_End_x_histX, Reco_End_x_histY = histogram_arr_handle(Reco_End_x_hist, Reco_End_x_bins) Reco_End_y_histX, Reco_End_y_histY = histogram_arr_handle(Reco_End_y_hist, Reco_End_y_bins) Reco_End_z_histX, Reco_End_z_histY = histogram_arr_handle(Reco_End_z_hist, Reco_End_z_bins) - + Primary_True_Start_x_histX, Primary_True_Start_x_histY = histogram_arr_handle(Primary_True_Start_x_hist, Primary_True_Start_x_bins) + Primary_True_Start_y_histX, Primary_True_Start_y_histY = histogram_arr_handle(Primary_True_Start_y_hist, Primary_True_Start_y_bins) + Primary_True_Start_z_histX, Primary_True_Start_z_histY = histogram_arr_handle(Primary_True_Start_z_hist, Primary_True_Start_z_bins) + Primary_True_End_x_histX, Primary_True_End_x_histY = histogram_arr_handle(Primary_True_End_x_hist, Primary_True_End_x_bins) + Primary_True_End_y_histX, Primary_True_End_y_histY = histogram_arr_handle(Primary_True_End_y_hist, Primary_True_End_y_bins) + Primary_True_End_z_histX, Primary_True_End_z_histY = histogram_arr_handle(Primary_True_End_z_hist, Primary_True_End_z_bins) + # now plot this - mp.plot(Position_TMS_Start_x_histX, Position_TMS_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Primary_True_Start_x_histX, Primary_True_Start_x_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') mp.plot(Reco_Start_x_histX, Reco_Start_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_Start_x_histX, 0, Position_TMS_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Primary_True_Start_x_histX, 0, Primary_True_Start_x_histY, color = blue_cbf, alpha = 0.6, hatch = '//') mp.fill_between(Reco_Start_x_histX, 0, Reco_Start_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS') + mp.xlabel('Start in TMS [mm]') mp.ylabel('#') mp.title('x') - mp.savefig('performance_plots_NERSC/Track_Start_X_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Track_Start_X_hist.png' % out_dir, bbox_inches = 'tight') mp.close() - mp.plot(Position_TMS_Start_y_histX, Position_TMS_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Primary_True_Start_y_histX, Primary_True_Start_y_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') mp.plot(Reco_Start_y_histX, Reco_Start_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_Start_y_histX, 0, Position_TMS_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Primary_True_Start_y_histX, 0, Primary_True_Start_y_histY, color = blue_cbf, alpha = 0.6, hatch = '//') mp.fill_between(Reco_Start_y_histX, 0, Reco_Start_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS') + mp.xlabel('Start in TMS [mm]') mp.ylabel('#') mp.title('y') - mp.savefig('performance_plots_NERSC/Track_Start_Y_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Track_Start_Y_hist.png' % out_dir, bbox_inches = 'tight') mp.close() - mp.plot(Position_TMS_Start_z_histX, Position_TMS_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Primary_True_Start_z_histX, Primary_True_Start_z_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') mp.plot(Reco_Start_z_histX, Reco_Start_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_Start_z_histX, 0, Position_TMS_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Primary_True_Start_z_histX, 0, Primary_True_Start_z_histY, color = blue_cbf, alpha = 0.6, hatch = '//') mp.fill_between(Reco_Start_z_histX, 0, Reco_Start_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS') + mp.xlabel('Start in TMS [mm]') mp.ylabel('#') mp.title('z') - mp.savefig('performance_plots_NERSC/Track_Start_Z_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Track_Start_Z_hist.png' % out_dir, bbox_inches = 'tight') mp.close() - mp.plot(Position_TMS_End_x_histX, Position_TMS_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Primary_True_End_x_histX, Primary_True_End_x_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') mp.plot(Reco_End_x_histX, Reco_End_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_End_x_histX, 0, Position_TMS_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Primary_True_End_x_histX, 0, Primary_True_End_x_histY, color = blue_cbf, alpha = 0.6, hatch = '//') mp.fill_between(Reco_End_x_histX, 0, Reco_End_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS') + mp.xlabel('End in TMS [mm]') mp.ylabel('#') mp.title('x') - mp.savefig('performance_plots_NERSC/Track_End_X_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Track_End_X_hist.png' % out_dir, bbox_inches = 'tight') mp.close() - mp.plot(Position_TMS_End_y_histX, Position_TMS_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Primary_True_End_y_histX, Primary_True_End_y_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') mp.plot(Reco_End_y_histX, Reco_End_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_End_y_histX, 0, Position_TMS_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Primary_True_End_y_histX, 0, Primary_True_End_y_histY, color = blue_cbf, alpha = 0.6, hatch = '//') mp.fill_between(Reco_End_y_histX, 0, Reco_End_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS') + mp.xlabel('End in TMS [mm]') mp.ylabel('#') mp.title('y') - mp.savefig('performance_plots_NERSC/Track_End_Y_hist.png', bbox_inches = 'tight') + mp.savefig('%s/Track_End_Y_hist.png' % out_dir, bbox_inches = 'tight') mp.close() - mp.plot(Position_TMS_End_z_histX, Position_TMS_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') + mp.plot(Primary_True_End_z_histX, Primary_True_End_z_histY, color = blue_cbf, linestyle = '-.', linewidth = 2, label = 'truth') mp.plot(Reco_End_z_histX, Reco_End_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_End_z_histX, 0, Position_TMS_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) + mp.fill_between(Primary_True_End_z_histX, 0, Primary_True_End_z_histY, color = blue_cbf, alpha = 0.6, hatch = '//') mp.fill_between(Reco_End_z_histX, 0, Reco_End_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) mp.grid(True, linestyle = '--', alpha = 0.2) mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS') + mp.xlabel('End in TMS [mm]') mp.ylabel('#') mp.title('z') - mp.savefig('performance_plots_NERSC/Track_End_Z_hist.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Position_TMS_Start_x_histX, Position_TMS_Start_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') - mp.plot(Reco_Start_x_histX, Reco_Start_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_Start_x_histX, 0, Position_TMS_Start_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.fill_between(Reco_Start_x_histX, 0, Reco_Start_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS') - mp.ylabel('#') - mp.title('x') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Track_Start_X_hist_log.png', bbox_inches = 'tight') + mp.savefig('%s/Track_End_Z_hist.png' % out_dir, bbox_inches = 'tight') mp.close() - mp.plot(Position_TMS_Start_y_histX, Position_TMS_Start_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') - mp.plot(Reco_Start_y_histX, Reco_Start_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_Start_y_histX, 0, Position_TMS_Start_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.fill_between(Reco_Start_y_histX, 0, Reco_Start_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS') - mp.ylabel('#') - mp.title('y') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Track_Start_Y_hist_log.png', bbox_inches = 'tight') - mp.close() + ### plot difference in dependence of hit position + # create 2d histograms + dependence_Start_x_hist, dependence_Start_x_binsX, dependence_Start_x_binsY = np.histogram2d(Primary_True_Start[:, 0], Diff_Start_x, bins = [Primary_True_Start_x_bins, Diff_Start_x_bins]) + dependence_Start_y_hist, dependence_Start_y_binsX, dependence_Start_y_binsY = np.histogram2d(Primary_True_Start[:, 1], Diff_Start_y, bins = [Primary_True_Start_y_bins, Diff_Start_y_bins]) + dependence_Start_z_hist, dependence_Start_z_binsX, dependence_Start_z_binsY = np.histogram2d(Primary_True_Start[:, 2], Diff_Start_z, bins = [Primary_True_Start_z_bins, Diff_Start_z_bins]) + dependence_End_x_hist, dependence_End_x_binsX, dependence_End_x_binsY = np.histogram2d(Primary_True_End[:, 0], Diff_End_x, bins = [Primary_True_End_x_bins, Diff_End_x_bins]) + dependence_End_y_hist, dependence_End_y_binsX, dependence_End_y_binsY = np.histogram2d(Primary_True_End[:, 1], Diff_End_y, bins = [Primary_True_End_y_bins, Diff_End_y_bins]) + dependence_End_z_hist, dependence_End_z_binsX, dependence_End_z_binsY = np.histogram2d(Primary_True_End[:, 2], Diff_End_z, bins = [Primary_True_End_z_bins, Diff_End_z_bins]) - mp.plot(Position_TMS_Start_z_histX, Position_TMS_Start_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') - mp.plot(Reco_Start_z_histX, Reco_Start_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_Start_z_histX, 0, Position_TMS_Start_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.fill_between(Reco_Start_z_histX, 0, Reco_Start_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('Start in TMS') - mp.ylabel('#') - mp.title('z') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Track_Start_Z_hist_log.png', bbox_inches = 'tight') - mp.close() + cmap = cm.get_cmap('cividis'); - mp.plot(Position_TMS_End_x_histX, Position_TMS_End_x_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') - mp.plot(Reco_End_x_histX, Reco_End_x_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_End_x_histX, 0, Position_TMS_End_x_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.fill_between(Reco_End_x_histX, 0, Reco_End_x_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS') - mp.ylabel('#') + im = mp.pcolormesh(dependence_Start_x_binsX, dependence_Start_x_binsY, np.transpose(dependence_Start_x_hist), cmap = cmap); + mp.xlabel('Start in TMS (X) [mm]') + mp.ylabel('Difference truth - reco [mm]') mp.title('x') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Track_End_X_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Position_TMS_End_y_histX, Position_TMS_End_y_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') - mp.plot(Reco_End_y_histX, Reco_End_y_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_End_y_histX, 0, Position_TMS_End_y_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.fill_between(Reco_End_y_histX, 0, Reco_End_y_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS') - mp.ylabel('#') + mp.colorbar(im); + mp.savefig('%s/Start_X_real_and_difference.png' % out_dir, bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_Start_y_binsX, dependence_Start_y_binsY, np.transpose(dependence_Start_y_hist), cmap = cmap); + mp.xlabel('Start in TMS (Y) [mm]') + mp.ylabel('Difference truth - reco [mm]') mp.title('y') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Track_End_Y_hist_log.png', bbox_inches = 'tight') - mp.close() - - mp.plot(Position_TMS_End_z_histX, Position_TMS_End_z_histY, color = blue_cbf, linestyle = '--', linewidth = 2, label = 'truth') - mp.plot(Reco_End_z_histX, Reco_End_z_histY, color = red_cbf, linestyle = ':', linewidth = 2, label = 'reco') - mp.fill_between(Position_TMS_End_z_histX, 0, Position_TMS_End_z_histY, alpha = 0.6, hatch = '//', color = blue_cbf) - mp.fill_between(Reco_End_z_histX, 0, Reco_End_z_histY, alpha = 0.6, hatch = '\\\\', color = red_cbf) - mp.grid(True, linestyle = '--', alpha = 0.2) - mp.legend(loc = 'best', fontsize = 'x-large', markerscale = 1.0, columnspacing = 0.5, handlelength = 0.8) - mp.xlabel('End in TMS') - mp.ylabel('#') + mp.colorbar(im); + mp.savefig('%s/Start_Y_real_and_difference.png' % out_dir, bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_Start_z_binsX, dependence_Start_z_binsY, np.transpose(dependence_Start_z_hist), cmap = cmap); + mp.xlabel('Start in TMS (Z) [mm]') + mp.ylabel('Difference truth - reco [mm]') mp.title('z') - mp.yscale('log') - mp.savefig('performance_plots_NERSC/Track_End_Z_hist_log.png', bbox_inches = 'tight') - mp.close() + mp.colorbar(im); + mp.savefig('%s/Start_Z_real_and_difference.png' % out_dir, bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_End_x_binsX, dependence_End_x_binsY, np.transpose(dependence_End_x_hist), cmap = cmap); + mp.xlabel('End in TMS (X) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('x') + mp.colorbar(im); + mp.savefig('%s/End_X_real_and_difference.png' % out_dir, bbox_inches = 'tight'); + mp.close(); + im = mp.pcolormesh(dependence_End_y_binsX, dependence_End_y_binsY, np.transpose(dependence_End_y_hist), cmap = cmap); + mp.xlabel('End in TMS (Y) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('y') + mp.colorbar(im); + mp.savefig('%s/End_Y_real_and_difference.png' % out_dir, bbox_inches = 'tight'); + mp.close(); + + im = mp.pcolormesh(dependence_End_z_binsX, dependence_End_z_binsY, np.transpose(dependence_End_z_hist), cmap = cmap); + mp.xlabel('End in TMS (Z) [mm]') + mp.ylabel('Difference truth - reco [mm]') + mp.title('z') + mp.colorbar(im); + mp.savefig('%s/End_Z_real_and_difference.png' % out_dir, bbox_inches = 'tight'); + mp.close(); + return def histogram_arr_handle(bins, edges):#(u bins,v edges)