From eab5aebac2e9d9241cb01a478e90f818d3eba078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelena=20K=C3=B6hler?= <108803123+jelenakhlr@users.noreply.github.com> Date: Tue, 21 May 2024 10:05:13 +0200 Subject: [PATCH 1/9] add plot_dir there was a problem with saving the plots to the simulation directory when the user didn't have rights to write into the simulation dir. --- sim2root/Common/IllustrateSimPipe.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/sim2root/Common/IllustrateSimPipe.py b/sim2root/Common/IllustrateSimPipe.py index dab4da69..81af8136 100644 --- a/sim2root/Common/IllustrateSimPipe.py +++ b/sim2root/Common/IllustrateSimPipe.py @@ -45,6 +45,12 @@ def manage_args(): "directory", help="Simulation output data directory in GRANDROOT format." ) + parser.add_argument( + "--savefig_dir", + type=str, + default=None, + help="Directory to save figures. Defaults to simulation output directory if not specified." + ) parser.add_argument( "--verbose", choices=["debug", "info", "warning", "error", "critical"], @@ -65,7 +71,15 @@ def manage_args(): # retrieve argument return parser.parse_args() - +if savefig: + if savefig_dir is None: + # Use simulation output directory by default + plot_dir = directory + else: + # Use specified savefig_dir + plot_dir = savefig_dir +else: + pass def plot_core_positions(directory, t_0_shift=False): d_input = groot.DataDirectory(directory) @@ -115,7 +129,7 @@ def plot_core_positions(directory, t_0_shift=False): ax1.set_ylabel("Y (westing)(m)") plt.tight_layout() if(args.savefig): - plt.savefig(f"{directory}/CorePositions_{myrun}.png") + plt.savefig(f"{plot_dir}/CorePositions_{myrun}.png") plt.close(fig) else: plt.show() @@ -312,7 +326,7 @@ def plot_traces_all_levels(directory, t_0_shift=False): plt.tight_layout() if(args.savefig): - plt.savefig(f"{directory}/IllustrateSimPipe_{run_number}_{event_number}_{du_idx}_{savelabel}.png") + plt.savefig(f"{plot_dir}/IllustrateSimPipe_{run_number}_{event_number}_{du_idx}_{savelabel}.png") plt.close(fig) else: plt.show() @@ -449,7 +463,7 @@ def plot_time_map(directory, simulator=None): plt.tight_layout() if(args.savefig): - plt.savefig(f"{directory}/TimeMap_{run_number}_{event_number}.png") + plt.savefig(f"{plot_dir}/TimeMap_{run_number}_{event_number}.png") plt.close(fig) else: plt.show() @@ -513,7 +527,7 @@ def plot_raws(directory): plt.tight_layout() if(args.savefig): - plt.savefig(f"{directory}/rawtrace_{du}.png") + plt.savefig(f"{plot_dir}/rawtrace_{du}.png") plt.close() else: plt.show() From 3c62fdc35e25bc48c77124ed066dbbe352e3b6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelena=20K=C3=B6hler?= Date: Tue, 21 May 2024 12:51:04 +0200 Subject: [PATCH 2/9] update savefig options --- sim2root/Common/IllustrateSimPipe.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/sim2root/Common/IllustrateSimPipe.py b/sim2root/Common/IllustrateSimPipe.py index 81af8136..f3775632 100644 --- a/sim2root/Common/IllustrateSimPipe.py +++ b/sim2root/Common/IllustrateSimPipe.py @@ -45,12 +45,12 @@ def manage_args(): "directory", help="Simulation output data directory in GRANDROOT format." ) - parser.add_argument( + parser.add_argument( "--savefig_dir", type=str, default=None, help="Directory to save figures. Defaults to simulation output directory if not specified." - ) + ) parser.add_argument( "--verbose", choices=["debug", "info", "warning", "error", "critical"], @@ -71,15 +71,6 @@ def manage_args(): # retrieve argument return parser.parse_args() -if savefig: - if savefig_dir is None: - # Use simulation output directory by default - plot_dir = directory - else: - # Use specified savefig_dir - plot_dir = savefig_dir -else: - pass def plot_core_positions(directory, t_0_shift=False): d_input = groot.DataDirectory(directory) @@ -541,8 +532,21 @@ def plot_raws(directory): mlg.create_output_for_logger(args.verbose, log_stdout=True) logger.info(mlg.string_begin_script()) logger.info("Creating event plots in source directory "+args.directory) - directory = args.directory + savefig = args.savefig + savefig_dir = args.savefig_dir + + if savefig: + if savefig_dir is None: + # Use simulation output directory by default + plot_dir = directory + else: + # Use specified savefig_dir + plot_dir = savefig_dir + else: + pass + + plot_core_positions(directory) plot_time_map(directory, simulator=args.sim) plot_traces_all_levels(directory, t_0_shift=False) From 98d429ba3b61984c70c2aff8c050d6922c6d2e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelena=20K=C3=B6hler?= Date: Tue, 21 May 2024 14:04:32 +0200 Subject: [PATCH 3/9] add subdir for plots --- sim2root/Common/IllustrateSimPipe.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sim2root/Common/IllustrateSimPipe.py b/sim2root/Common/IllustrateSimPipe.py index f3775632..d24e7fa7 100644 --- a/sim2root/Common/IllustrateSimPipe.py +++ b/sim2root/Common/IllustrateSimPipe.py @@ -120,7 +120,7 @@ def plot_core_positions(directory, t_0_shift=False): ax1.set_ylabel("Y (westing)(m)") plt.tight_layout() if(args.savefig): - plt.savefig(f"{plot_dir}/CorePositions_{myrun}.png") + plt.savefig(f"{plot_dir}/plots/CorePositions_{myrun}.png") plt.close(fig) else: plt.show() @@ -317,7 +317,7 @@ def plot_traces_all_levels(directory, t_0_shift=False): plt.tight_layout() if(args.savefig): - plt.savefig(f"{plot_dir}/IllustrateSimPipe_{run_number}_{event_number}_{du_idx}_{savelabel}.png") + plt.savefig(f"{plot_dir}/plots/IllustrateSimPipe_{run_number}_{event_number}_{du_idx}_{savelabel}.png") plt.close(fig) else: plt.show() @@ -454,7 +454,7 @@ def plot_time_map(directory, simulator=None): plt.tight_layout() if(args.savefig): - plt.savefig(f"{plot_dir}/TimeMap_{run_number}_{event_number}.png") + plt.savefig(f"{plot_dir}/plots/TimeMap_{run_number}_{event_number}.png") plt.close(fig) else: plt.show() @@ -518,7 +518,7 @@ def plot_raws(directory): plt.tight_layout() if(args.savefig): - plt.savefig(f"{plot_dir}/rawtrace_{du}.png") + plt.savefig(f"{plot_dir}/plots/rawtrace_{du}.png") plt.close() else: plt.show() From 99eaaed84f24e5ec5dd023f1ab27b81f7d1ec2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20G=C3=BClzow?= Date: Thu, 23 May 2024 09:51:22 +0200 Subject: [PATCH 4/9] fix indentation and put savefig directory command at better point in the code --- sim2root/Common/IllustrateSimPipe.py | 53 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/sim2root/Common/IllustrateSimPipe.py b/sim2root/Common/IllustrateSimPipe.py index 81af8136..7fe030ef 100644 --- a/sim2root/Common/IllustrateSimPipe.py +++ b/sim2root/Common/IllustrateSimPipe.py @@ -45,42 +45,32 @@ def manage_args(): "directory", help="Simulation output data directory in GRANDROOT format." ) - parser.add_argument( - "--savefig_dir", - type=str, - default=None, - help="Directory to save figures. Defaults to simulation output directory if not specified." - ) + parser.add_argument( + "--savefig_dir", + type=str, + default=None, + help="Directory to save figures. Defaults to simulation output directory if not specified." + ) parser.add_argument( "--verbose", choices=["debug", "info", "warning", "error", "critical"], default="info", help="logger verbosity." ) + parser.add_argument( + "--savefig", + action="store_true", + default=False, + help="save figures to files insted of displaying them." + ) parser.add_argument( - "--savefig", - action="store_true", - default=False, - help="save figures to files insted of displaying them." - ) - parser.add_argument( - "--sim", - default="None", - help="specify simulator: Coreas vs. Zhaires" - ) + "--sim", + default="None", + help="specify simulator: Coreas vs. Zhaires" + ) # retrieve argument return parser.parse_args() -if savefig: - if savefig_dir is None: - # Use simulation output directory by default - plot_dir = directory - else: - # Use specified savefig_dir - plot_dir = savefig_dir -else: - pass - def plot_core_positions(directory, t_0_shift=False): d_input = groot.DataDirectory(directory) @@ -542,6 +532,17 @@ def plot_raws(directory): logger.info(mlg.string_begin_script()) logger.info("Creating event plots in source directory "+args.directory) + # change plot directory if specified + if args.savefig: + if args.savefig_dir is None: + # Use simulation output directory by default + plot_dir = args.directory + else: + # Use specified savefig_dir + plot_dir = args.savefig_dir + else: + pass + directory = args.directory plot_core_positions(directory) plot_time_map(directory, simulator=args.sim) From 7b3904bfd987def9c8a03d478866c1b5f2672074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clguelzow=E2=80=9D?= <“lukas.guelzow@kit.edu”> Date: Wed, 29 May 2024 15:28:38 +0200 Subject: [PATCH 5/9] fix conflict --- sim2root/Common/IllustrateSimPipe.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sim2root/Common/IllustrateSimPipe.py b/sim2root/Common/IllustrateSimPipe.py index 33ab81b6..ed7438b3 100644 --- a/sim2root/Common/IllustrateSimPipe.py +++ b/sim2root/Common/IllustrateSimPipe.py @@ -46,19 +46,11 @@ def manage_args(): help="Simulation output data directory in GRANDROOT format." ) parser.add_argument( -<<<<<<< HEAD "--savefig_dir", type=str, default=None, help="Directory to save figures. Defaults to simulation output directory if not specified." ) -======= - "--savefig_dir", - type=str, - default=None, - help="Directory to save figures. Defaults to simulation output directory if not specified." - ) ->>>>>>> 98d429ba3b61984c70c2aff8c050d6922c6d2e0f parser.add_argument( "--verbose", choices=["debug", "info", "warning", "error", "critical"], @@ -79,10 +71,6 @@ def manage_args(): # retrieve argument return parser.parse_args() -<<<<<<< HEAD -======= - ->>>>>>> 98d429ba3b61984c70c2aff8c050d6922c6d2e0f def plot_core_positions(directory, t_0_shift=False): d_input = groot.DataDirectory(directory) @@ -543,7 +531,6 @@ def plot_raws(directory): mlg.create_output_for_logger(args.verbose, log_stdout=True) logger.info(mlg.string_begin_script()) logger.info("Creating event plots in source directory "+args.directory) -<<<<<<< HEAD # change plot directory if specified if args.savefig: @@ -556,8 +543,6 @@ def plot_raws(directory): else: pass -======= ->>>>>>> 98d429ba3b61984c70c2aff8c050d6922c6d2e0f directory = args.directory savefig = args.savefig savefig_dir = args.savefig_dir From c80dbdff495336800b8ed0cd48757739ed849a02 Mon Sep 17 00:00:00 2001 From: lguelzow Date: Wed, 5 Jun 2024 14:23:30 +0200 Subject: [PATCH 6/9] increased possible number of directories --- sim2root/Common/sim2root.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sim2root/Common/sim2root.py b/sim2root/Common/sim2root.py index 168dbce6..2d6e1566 100755 --- a/sim2root/Common/sim2root.py +++ b/sim2root/Common/sim2root.py @@ -764,13 +764,13 @@ def form_directory_name(clargs, date, time, run_number, site): extra = clargs.extra.replace("_", "-") # Go through serial numbers in directory names to find a one that does not exist - for sn in range(1000): + for sn in range(5000): dir_name = Path(clargs.output_parent_directory, f"sim_{site}_{date}_{time}_RUN{run_number}_CD_{extra}_{sn:0>4}") if not dir_name.exists(): break - # If directories with serial number up to 1000 already created + # If directories with serial number up to 5000 already created else: - print("All directories with serial number up to 1000 already exist. Please clean up some directories!") + print("All directories with serial number up to 5000 already exist. Please clean up some directories!") exit(0) return dir_name @@ -781,7 +781,7 @@ def rename_files(clargs, path, start_event_number, end_event_number, run_number) # Go through run output files for fn_start in ["run", "runshowersim", "runefieldsim"]: # Go through serial numbers in directory names to find a one that does not exist - for sn in range(1000): + for sn in range(5000): fn_in = Path(path, f"{fn_start}.root") # Proper name of the file fn_out = Path(path, f"{fn_start}_{run_number}_L{clargs.analysis_level}_{sn:0>4}.root") @@ -790,14 +790,14 @@ def rename_files(clargs, path, start_event_number, end_event_number, run_number) fn_in.rename(fn_out) break else: - print(f"Could not find a free filename for {fn_in} until serial number 1000. Please clean up some files!") + print(f"Could not find a free filename for {fn_in} until serial number 5000. Please clean up some files!") exit(0) # Go through event output files for fn_start in ["shower", "showersim", "efield"]: # Go through serial numbers in directory names to find a one that does not exist - for sn in range(1000): + for sn in range(5000): fn_in = Path(path, f"{fn_start}.root") # Proper name of the file fn_out = Path(path, f"{fn_start}_{start_event_number}-{end_event_number}_L{clargs.analysis_level}_{sn:0>4}.root") @@ -806,7 +806,7 @@ def rename_files(clargs, path, start_event_number, end_event_number, run_number) fn_in.rename(fn_out) break else: - print(f"Could not find a free filename for {fn_in} until serial number 1000. Please clean up some files!") + print(f"Could not find a free filename for {fn_in} until serial number 5s000. Please clean up some files!") exit(0) From 243854dbe8a57860b7b810252ddbbc99164f28d8 Mon Sep 17 00:00:00 2001 From: luckyjim Date: Mon, 10 Jun 2024 18:04:54 +0200 Subject: [PATCH 7/9] default value of factor_hill is too small --- grand/basis/signal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grand/basis/signal.py b/grand/basis/signal.py index 063ae8b2..75877c19 100644 --- a/grand/basis/signal.py +++ b/grand/basis/signal.py @@ -52,7 +52,7 @@ def find_max_with_parabola_interp_3pt(x_trace, y_trace, idx_max): return x_max, y_max -def find_max_with_parabola_interp(x_trace, y_trace, idx_max, factor_hill=0.8): +def find_max_with_parabola_interp(x_trace, y_trace, idx_max, factor_hill=0.96): """Parabolic interpolation of the maximum with more than 3 points trace : all values >= 0 @@ -76,6 +76,7 @@ def find_max_with_parabola_interp(x_trace, y_trace, idx_max, factor_hill=0.8): :param factor_hill: :type factor_hill: """ + # y threshold mean around max (so 3 points) * factor_hill y_lim = (y_trace[idx_max - 1 : idx_max + 2].sum() / 3) * factor_hill logger.debug(f"y_lim={y_lim}") # 1 From 02f9251dc0d1f32382d60cd06f7abab794ad6cf2 Mon Sep 17 00:00:00 2001 From: "paul.minodier" Date: Mon, 1 Jul 2024 21:21:59 +0900 Subject: [PATCH 8/9] Fixed bugs in CoreasToRawRoot with t_pre, t_post, t_0 and xmax_grams --- sim2root/CoREASRawRoot/CoreasToRawROOT.py | 6 +++--- sim2root/CoREASRawRoot/CorsikaInfoFuncs.py | 20 ++------------------ 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/sim2root/CoREASRawRoot/CoreasToRawROOT.py b/sim2root/CoREASRawRoot/CoreasToRawROOT.py index 79a550f4..3d568b22 100644 --- a/sim2root/CoREASRawRoot/CoreasToRawROOT.py +++ b/sim2root/CoREASRawRoot/CoreasToRawROOT.py @@ -456,10 +456,10 @@ def CoreasToRawRoot(file, simID=None): # define time params: t_length = len(timestamp) - t_0 = timestamp[0] + t_length/2 + t_0 = timestamp[0] + t_length/2 * TimeBinSize t_pre = 800#ns - t_pre = t_length/2 - t_post = t_length/2 + t_pre = t_length/2 * TimeBinSize + t_post = t_length/2 * TimeBinSize # add to ROOT tree # in Zhaires converter: AntennaN[ant_ID] diff --git a/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py b/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py index a20fbf9e..6f15eec0 100644 --- a/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py +++ b/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py @@ -273,23 +273,7 @@ def read_long(pathLongFile): TODO: fix hillas_parameter - something's not working yet """ with open(pathLongFile, mode="r") as file: - # create a temporary file to write the corrected contents - temp_file = io.StringIO() - - for line in file: - # use a regex to search for a minus sign that is not part of an exponent - if search(r"(? Date: Tue, 2 Jul 2024 19:15:46 +0900 Subject: [PATCH 9/9] fixed parenthesis mistake --- sim2root/CoREASRawRoot/CorsikaInfoFuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py b/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py index 6f15eec0..21429982 100644 --- a/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py +++ b/sim2root/CoREASRawRoot/CorsikaInfoFuncs.py @@ -273,7 +273,7 @@ def read_long(pathLongFile): TODO: fix hillas_parameter - something's not working yet """ with open(pathLongFile, mode="r") as file: - lines=file.readlines + lines=file.readlines() n_steps = int(lines[0].rstrip().split()[3])