Skip to content

Commit

Permalink
Merge pull request #2 from ggmarshall/xtalk
Browse files Browse the repository at this point in the history
change calibrated to call other func
  • Loading branch information
tdixon97 authored May 3, 2024
2 parents 34dfc59 + 914ecbe commit 8bcfa13
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions src/pygama/evt/modules/geds.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,41 +169,21 @@ def apply_xtalk_correction_and_calibrate(
name of the lh5 object containing the name of the rawids
"""

# read lh5 files to numpy
xtalk_matrix_numpy = lh5.read_as(xtalk_matrix_name, xtalk_matrix_filename, "np")
print(f"Read {xtalk_rawid_name}, {xtalk_matrix_filename}")
xtalk_matrix_rawids = lh5.read_as(xtalk_rawid_name, xtalk_matrix_filename, "np")

positive_xtalk_matrix_numpy = lh5.read_as(
positive_xtalk_matrix_name, xtalk_matrix_filename, "np"
)
energies_corr = apply_xtalk_correction(
datainfo
tcm
table_names
*,
uncalibrated_energy_name = uncalibrated_energy_name,
calibrated_energy_name = calibrated_energy_name,
threshold = threshold,
xtalk_matrix_filename = xtalk_matrix_filename,
xtalk_rawid_name = xtalk_rawid_name,
xtalk_matrix_name = xtalk_matrix_name,
positive_xtalk_matrix_name = positive_xtalk_matrix_name,
).view_as("np")

# Combine positive and negative matrixs
# Now the matrix should have negative values corresponding to negative cross talk
# and positive values corresponding to positive cross talk .
# we also set nan to 0 and we transpose so that the row corresponds to response and column trigger
xtalk_matrix = np.nan_to_num(
np.where(
abs(xtalk_matrix_numpy) > abs(positive_xtalk_matrix_numpy),
xtalk_matrix_numpy,
positive_xtalk_matrix_numpy,
),
0,
).T

uncalibrated_energy_array = xtalk.build_energy_array(
uncalibrated_energy_name, tcm, datainfo, xtalk_matrix_rawids
)
calibrated_energy_array = xtalk.build_energy_array(
calibrated_energy_name, tcm, datainfo, xtalk_matrix_rawids
)
dt_array = xtalk.build_energy_array(
"dsp.dt_eff", tcm, datainfo, xtalk_matrix_rawids
)

energies_corr = xtalk.xtalk_corrected_energy(
uncalibrated_energy_array, calibrated_energy_array, xtalk_matrix, threshold
)
out_arr = np.full_like(energies_corr, np.nan)
par_dicts = Props.read_from(par_files)
pars = {
Expand Down

0 comments on commit 8bcfa13

Please sign in to comment.