Skip to content

Conversation

@johbackm
Copy link
Contributor

First (beta) version of a working version of LEO fits for PySP2. Work is still needed on the details/tweaks, but the essentials should be there to expand on.

@johbackm
Copy link
Contributor Author

johbackm commented Oct 14, 2025

Ah. I need to change the tests as well. Now beam_shape test removed for now.

Copy link
Collaborator

@rcjackson rcjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is really good. Some more documentation is needed, as well as unit tests for each of the LEO fit types. In addition, I request that commented out code be removed from the final version (comment notes are fine).

my_high_gain_scatterers['PkHt_ch0'].values))/ \
np.sum(my_high_gain_scatterers['PkHt_ch0'].values))
#high_gain_split_position = my_high_gain_scatterers['PkSplitPos_ch3'].values
#low_gain_split_position = my_low_gain_scatterers['PkSplitPos_ch7'].values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

#normalize the profile to range [~0,1]
profile_ch4 = (data_ch4 - base_ch4) / peak_height_ch4
#insert the profile as it was recorded (no shifting due to PEAK POSITION or PSD POSITION)
#my_high_gain_profiles_[i,:] = profile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More commented out code to remove at this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

# moving_average_window, axis=0)
#moving_median_high_gain_base = np.nanpercentile(moving_high_gain_base, 10,axis=1)
#moving_median_low_gain_base = np.nanpercentile(moving_low_gain_base, 10,axis=1)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Past 4 lines here are commented out code that should not be in the final product if not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

#leo_Base_ch0[iloc_high_gain[:-moving_average_window+1]] = moving_median_high_gain_base
#leo_Base_ch4 = np.zeros(scatter_low_gain_accepted.shape)*np.nan
#leo_Base_ch4[iloc_low_gain[:-moving_average_window+1]] = moving_median_low_gain_base

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this block of commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

* LAST BIN TO USE FOR LEO FIT (from split detector) (DONE)
* do also for LG.
* TAKE BASELINE SCAT FROM ACTUAL TRACERS IN LEO_FIT
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this into the docstring section under a new "Notes" section to inform the user about what is done and what needs to be implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it has already been implemented and those notes were mostly for my self.

#Low gain
for i in range(my_binary.sizes['event_index']):
#max_value = data_ch0[i,:].max() - data_ch0[i,:].min()
#bins_ = bins[num_base_pts_2_avg:leo_fit_max_pos[i]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented lines of code to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

from .DMTGlobals import DMTGlobals

def calc_diams_masses(input_ds, debug=True, factor=1.0, Globals=None):
def calc_diams_masses(input_ds, debug=True, factor=1.0, Globals=None, leo_fits=False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for the leo_fits flag in the docstring below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added text to the documentation.

print("Number of incandescence particles rejected for min. peak height = %d" % rejectMinIncandTotal)
print("Number of incandescence particles rejected for peak width = %d" % rejectIncandWidthTotal)
#print("Number of incandescence particles rejected for fat peak = %d" % rejectFatPeakTotal)
#print("Number of incandescence particles rejected for peak pos. = %d" % rejectFtPosTotal)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep as much debug output as possible, so if these two new rejection criteria are recorded, I would keep them in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those commented out lines are from the scattering channels. So I removed them. They are shown earlier. The lines that are not commented out (98-100) are rejection criteria that have not previously been shown for incandescence.

leo_Scat_not_sat = 1e-18 * (Globals.c0Scat1 + Globals.c1Scat1*leo_PkHt_ch0 + Globals.c2Scat1*leo_PkHt_ch0**2)
leo_Scat_sat = 1e-18 * (Globals.c0Scat2 + Globals.c1Scat2*leo_PkHt_ch4 + Globals.c2Scat2*leo_PkHt_ch4**2)
leo_Scatter = np.where(PkHt_ch0 < Globals.ScatMaxPeakHt1, leo_Scat_not_sat, leo_Scat_sat)
#leo_Scatter = np.where(accepted_incand, leo_Scatter, np.nan)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove if not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

#coeff, beam_profile = pysp2.util.beam_shape(
# my_binary, beam_position_from='peak maximum', Globals=pysp2.util.DMTGlobals())
#np.testing.assert_almost_equal(coeff, [9.83851858e-01, 4.64317390e+01,
# 1.14337852e+01, 4.46761788e-03])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make unit tests for each of your beam_position_from flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Now I've added those as well.

@johbackm
Copy link
Contributor Author

Now all the requested changes should have been done, including unit tests for the leo_fit() function.

@rcjackson
Copy link
Collaborator

This looks good to go. I am merging. I will cut a new PySP2 release here shortly.

@rcjackson rcjackson merged commit 38498aa into ARM-DOE:main Nov 12, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants