Skip to content

Commit

Permalink
some improvements on that
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanna Jakob committed Aug 7, 2024
1 parent be872f7 commit 1f89e44
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions saltax/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def xenonnt_salted_fuse(
instr_file_name = saltax.instr_file_name(
runid=runid, recoil=recoil, generator_name=generator_name, mode=simu_mode, **kwargs
)

# If runid is not None, then we need to either load instruction or generate it
if runid is not None:
# Try to load instruction from file and generate if not found
Expand Down
17 changes: 13 additions & 4 deletions saltax/instructions/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
method="RegularGridInterpolator",
)
SE_INSTRUCTIONS_DIR = "/project/lgrandi/yuanlq/salt/se_instructions/"
#AMBE_INSTRUCTIONS_FILE = "/project/lgrandi/yuanlq/salt/ambe_instructions/minghao_aptinput.csv"
AMBE_INSTRUCTIONS_FILE = "/project2/lgrandi/jjakob/AmBeSprinkling/AmBe_fuse_input.csv"
#AMBE_INSTRUCTIONS_TYPE = "wfsim"
AMBE_INSTRUCTIONS_TYPE = "fuse"
# BASE_DIR = "/project2/lgrandi/yuanlq/shared/saltax_instr/"
BASE_DIR = os.path.abspath(__file__)[:-12] + "../../generated/"
Expand Down Expand Up @@ -205,6 +207,8 @@ def instr_file_name(
default: BASE_DIR
:return: instruction file name
"""
if generator_name=="ambe":
generator_name += ("_" + AMBE_INSTRUCTIONS_TYPE)
if en_range is not None:
en_range = str(en_range[0]) + "_" + str(en_range[1])
else:
Expand Down Expand Up @@ -236,7 +240,7 @@ def instr_file_name(

return filename

def fill_fuse_instruction_i(i, selected_ambe,times_offset):
def fill_fuse_instruction_i(i, cluster_i, selected_ambe,times_offset):
instr_i = np.zeros(len(selected_ambe), dtype=FUSE_DTYPE)
instr_i["t"] = times_offset[i] + selected_ambe["t"]
instr_i["eventid"] = i + 1
Expand All @@ -249,7 +253,10 @@ def fill_fuse_instruction_i(i, selected_ambe,times_offset):
instr_i["e_field"] = selected_ambe["e_field"]
instr_i["ed"] = selected_ambe["ed"]
instr_i["nestid"] = selected_ambe["nestid"]
instr_i["cluster_id"] = selected_ambe["cluster_id"]
instr_i["cluster_id"] = cluster_i + np.arange(1, 1 + len(selected_ambe))#selected_ambe["cluster_id"]

# Filter out 0 amplitudes
instr_i = instr_i[(instr_i["photons"] > 0) | (instr_i["electrons"] > 0)]

return instr_i

Expand All @@ -267,7 +274,7 @@ def fill_wfsim_instruction_i(i, selected_ambe,times_offset):
instr_i["n_excitons"] = selected_ambe["n_excitons"]

# Filter out 0 amplitudes
instr_i = instr_i[instr_i["amp"] > 0] # probably not a good idea to do that here if there is ever an instruction that is all zero
instr_i = instr_i[instr_i["amp"] > 0] # should also work if all amp's are zero

return instr_i

Expand Down Expand Up @@ -406,6 +413,7 @@ def generator_ambe(
# assign instructions
if instructions_type == 'fuse':
instr = np.zeros(0, dtype=FUSE_DTYPE)
cluster_id = 0
if instructions_type == 'wfsim':
instr = np.zeros(0, dtype=wfsim.instruction_dtype)

Expand All @@ -417,7 +425,8 @@ def generator_ambe(

# instruction for i-th event
if instructions_type == 'fuse':
instr_i = fill_fuse_instruction_i(i, selected_ambe, times_offset)
instr_i = fill_fuse_instruction_i(i, cluster_id, selected_ambe, times_offset)
cluster_id += len(selected_ambe)
elif instructions_type == 'wfsim':
instr_i = fill_wfsim_instruction_i(i, selected_ambe, times_offset)
else:
Expand Down
14 changes: 8 additions & 6 deletions saltax/plugins/f_raw_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,25 @@ def output_chunk(self, chunk_start, chunk_end):
Truncate the instructions to the chunk time range.
"""
# Load the csv file
log.debug(f"Loaded detector simulation instructions from a csv file in {self.input_type} format!")
log.warning(f"Loaded detector simulation instructions from a csv file in {self.input_type} format!")
instructions = self._load_csv_file()

print(f"Loaded detector simulation instructions from a csv file in {self.input_type} format!")

if self.input_type == "wfsim":
# Translate the wfsim instructions to the fuse format
log.debug("Translating the wfsim instructions to the fuse format!")
log.warning("Translating the wfsim instructions to the fuse format!")
instructions = self.translator.translate(instructions)
log.debug("Instructions translated to the fuse format!")
log.warning("Instructions translated to the fuse format!")

# truncate instructions to the chunk time range
log.debug("Truncating instructions to the chunk time range!")
log.warning("Truncating instructions to the chunk time range!")
log.debug(
"We will further truncate the instructions to the range [%d, %d]",
chunk_start + self.ns_no_instruction_after_chunk_start,
chunk_end - self.ns_no_instruction_before_chunk_end,
)

log.warning(f"We have the following list of keys: {list(instructions.keys())}")
# See if we have any instructions after the chunk end
mask_next = instructions["t"] > chunk_end
if np.any(mask_next):
Expand All @@ -225,7 +227,7 @@ def output_chunk(self, chunk_start, chunk_end):

def _load_csv_file(self):
"""Load the simulation instructions from a csv file in wfsim format."""
log.debug(f"Loading detector simulation instructions from a csv file in {self.input_type} format!")
log.warning(f"Loading detector simulation instructions from {self.input_file} in {self.input_type} format!")
df = pd.read_csv(self.input_file)

return df
Expand Down

0 comments on commit 1f89e44

Please sign in to comment.