diff --git a/sim2root/CoREASRawRoot/README.md b/sim2root/CoREASRawRoot/README.md index 425a02a0..460ffccf 100644 --- a/sim2root/CoREASRawRoot/README.md +++ b/sim2root/CoREASRawRoot/README.md @@ -13,7 +13,9 @@ The code will convert the specified CoREAS simulation into GRANDROOT format. ## How to run the whole CoreasToRawRoot + sim2root + efield2voltage -`python3 coreas_pipeline.py -d ` +`python3 coreas_pipeline.py -d `\ +optional: specify an output directory as well:\ +`python3 coreas_pipeline.py -d -o `\ ## Overview diff --git a/sim2root/CoREASRawRoot/convert2root.sh b/sim2root/CoREASRawRoot/convert2root.sh deleted file mode 100644 index 62b91fd9..00000000 --- a/sim2root/CoREASRawRoot/convert2root.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2root -#SBATCH --output=2root.out - -# Request resources (e.g., CPU cores, memory, and time) -#SBATCH --nodes=1 # Number of compute nodes -#SBATCH --ntasks=1 # Number of CPU cores -#SBATCH --mem=4G # Memory per node -#SBATCH --time=1:00:00 # Maximum job duration (hours:minutes:seconds) - -python3 unzip_and_convert2root.py -f /sps/grand/jelena/stshp+GP13/archive/proton_run01.tar.gz diff --git a/sim2root/CoREASRawRoot/coreas_pipeline.py b/sim2root/CoREASRawRoot/coreas_pipeline.py index 1f53a605..92850663 100644 --- a/sim2root/CoREASRawRoot/coreas_pipeline.py +++ b/sim2root/CoREASRawRoot/coreas_pipeline.py @@ -51,10 +51,11 @@ print("* - * - * - * - * - * - * - * - * - *") print(f"Converting Coreas Simulation {simID} to RawRoot format...") + # * - * - * - * - * - * - * # Run CoreasToRawROOT.py print("executing CoreasToRawROOT.py") CoreasToRawROOT = [ - 'python3', 'CoreasToRawROOT.py', '-d', str(options.directory) + "python3", "CoreasToRawROOT.py", "-d", f"{str(options.directory)}" ] subprocess.run(CoreasToRawROOT, check=True) print(f"Created Coreas_{simID}.root") @@ -62,26 +63,48 @@ print("* - * - * - * - * - * - * - * - * - *") print(f"Converting from RawRoot to GRANDroot format...") - # Run sim2root.py + # * - * - * - * - * - * - * print("executing sim2root.py") + # Run sim2root.py sim2root = [ - 'python3', '../Common/sim2root.py', f"Coreas_{simID}.root" + "python3", f"../Common/sim2root.py", f"Coreas_{simID}.root", "-o", f"{str(options.directory)}" ] subprocess.run(sim2root, check=True) - print(f"Created gr_Coreas_{simID}.root") + print(f"Created grandroot trees in {str(options.directory)}") + #! currently sim2root creates separate root files for each tree, so we need this for now: + sim2root_out = glob.glob(str(options.directory)+"/sim_*/tefield*")[0] print("* - * - * - * - * - * - * - * - * - *") print(f"Converting traces from efield to voltage...") + # * 1 * - * - * - * - * - * - * print("executing convert_efield2voltage.py") # Run convert_efield2voltage.py - sim2root = [ - 'python3', '../../scripts/convert_efield2voltage.py', f"gr_Coreas_{simID}.root",\ - f"-o {options.output}/efield_gr_Coreas_{simID}.root" + voltage = [ + "python3", "../../scripts/convert_efield2voltage.py", f"{sim2root_out}", "-o", f"{options.directory}/voltage_Coreas_{simID}.root" ] - subprocess.run(sim2root, check=True) + subprocess.run(voltage, check=True) print(f"Created efield_gr_Coreas_{simID}.root") print("********************************") + + # * 2 * - * - * - * - * - * - * + print("executing convert_efield2voltage.py --no_noise") + # Run convert_efield2voltage.py + voltage = [ + "python3", "../../scripts/convert_efield2voltage.py", f"{sim2root_out}", "--no_noise", "-o", f"{options.directory}/voltage_Coreas_{simID}_no_noise.root" + ] + subprocess.run(voltage, check=True) + print(f"Created efield_gr_Coreas_{simID}_no_noise.root") + + # * 3 * - * - * - * - * - * - * + print("executing convert_efield2voltage.py --no_noise --no_rf_chain") + # Run convert_efield2voltage.py + voltage = [ + "python3", "../../scripts/convert_efield2voltage.py", f"{sim2root_out}", "--no_noise", "--no_rf_chain", "-o", f"{options.directory}/voltage_Coreas_{simID}_no_noise_no_rfchain.root" + ] + subprocess.run(voltage, check=True) + print(f"Created efield_gr_Coreas_{simID}_no_noise_no_rfchain.root") + pass print(f"Finished analyzing files in {options.directory}") diff --git a/sim2root/CoREASRawRoot/unzip_and_convert2root.py b/sim2root/CoREASRawRoot/unzip_and_convert2root.py deleted file mode 100644 index f0c674c8..00000000 --- a/sim2root/CoREASRawRoot/unzip_and_convert2root.py +++ /dev/null @@ -1,62 +0,0 @@ -# author: @jelenakhlr -import os -import tarfile -import tempfile -import subprocess -from optparse import OptionParser - -path_to_grandlib = "/pbs/home/j/jpeterei/grandlib_dev_io_root/grand/" #! modfiy this path if necessary - -parser = OptionParser() -parser.add_option("--directory", "--dir", "-d", type="str", - help="Specify the full path to the directory of the MULTIPLE simulation sets.") -parser.add_option("--file", "-f", type="str", - help="Specify the full path to the SINGLE simulation set you want to analyze.") -(options, args) = parser.parse_args() - - -# # Create a temporary directory -temp_dir = "/sps/grand/jelena/stshp+GP13/temp/" -out_dir = "/sps/grand/jelena/stshp+GP13/root/" -print("Created temp directory", temp_dir) - -if __name__ == '__main__': - # Check that the user has specified a directory or a single file. - if options.directory: - input_directory = options.directory - for filename in os.listdir(input_directory): - if filename.endswith('.tar.gz'): - print(f"file {filename} unzipped to {temp_dir}") - file_path = os.path.join(input_directory, filename) - - # Extract the .tar.gz file into the temporary directory - with tarfile.open(file_path, 'r:gz') as tar: - tar.extractall(path=temp_dir) - elif options.file: - file_path = options.file - input_directory = os.path.dirname(file_path) - if file_path.endswith('.tar.gz'): - print(f"file {file_path} unzipped to {temp_dir}") - # Extract the .tar.gz file into the temporary directory - with tarfile.open(file_path, 'r:gz') as tar: - tar.extractall(path=temp_dir) - else: - print(f"ERROR: {file_path} is not a .tar.gz file") - exit() - else: - parser.print_help() - - - # Perform the analysis on the contents of the temporary directory. - print("Converting to GRANDroot format...") - coreas_pipeline = [ - 'python3', f'{path_to_grandlib}sim2root/CoREASRawRoot/coreas_pipeline.py', '-d', f"{temp_dir}*/run??/",\ - '-o', f'{outdir}' - ] - # python3 /pbs/home/j/jpeterei/grandlib_dev_io_root/grand/sim2root/CoREASRawRoot/coreas_pipeline.py -d /sps/grand/jelena/stshp+GP13/temp/*/run??/ -o /sps/grand/jelena/stshp+GP13/root/ - subprocess.run(coreas_pipeline, check=True) - print(f"Coreas simulations in GRANDroot format saved to {out_dir}") - - # Delete the temporary directory and its contents - # subprocess.run(['rm', '-r', temp_dir], check=True) - # print("Removed temp directory") diff --git a/sim2root/README.md b/sim2root/README.md index 9f9e76bd..5c187123 100644 --- a/sim2root/README.md +++ b/sim2root/README.md @@ -63,9 +63,27 @@ As input you need to give the ROOT file containing `RawRoot data TTrees`, as cre i.e. -`python3 sim2root.py ../ZHAireSRawRoot/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618/Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618.RawRoot` +`python3 sim2root.py ../ZHAireSRawRoot/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618/Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618.RawRoot -fo sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618` additional options are available on command line, see sim2root --help for more information +# 3) Simulation Pipe example (note that this assumes one event per directoy, and is not working on files with more than 1 event) +You will find two scripts illustrating how to use RawRoot files as starting point of a simulation pipe are in the "Common" directory. +Output File names are still not conforming to grand specifications. + +The example shows how to use the example RawRoot file given in /grand/sim2root/ZHAireSRawRoot/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618 to produce the grandroot files including +4 tvoltage files with the antenna response with and without the rf chain. You can use the RawRoot file of your liking. + +## 3a) GenerateGRANDRoot +python /ProduceGRANDRoot.py InputDirectory OutputDirectory + +python ProduceGRANDRoot.py /grand/sim2root/ZHAireSRawRoot/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618 /grand/sim2root/Common/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618 + +## 3b) GenerateVoltage +python ProduceVoltage.py InputDirectory OutputDiectory + +python /grand/sim2root/Common/ProduceVoltage/ProduceVoltage.py /grand/sim2root/Common/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618 /grand/sim2root/Common/sim_Xiaodushan_20221026_1200_1_SIBYLL23d_GP300_1618 + +Note that in this example we set the InputDiretory to be the same as the Outputdirectory to get all the files in the same place.