Skip to content

Add fitting of afterpulse spectrum to derive single pe application. #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 21, 2025

Conversation

GernotMaier
Copy link
Contributor

@GernotMaier GernotMaier commented Mar 20, 2025

Review after merging of #1419

Add option to fit afterpulse spectrum to the derive single pe application. Fitted is a exponential function with linear decay term. Decay factor (k) can be fixed; this might be necessary if measurements of afterpulses do not reach large single pe amplitudes,

New configuration parameters for derive_photon_electron_spectrum.py:

  • fit_afterpulse - turn on afterpulse fitting
  • fit_afterpulse_decay_factor - this will fix the decay factor k to the given value (for LSTN, 15 is a good value)
  • afterpulse_amplitude_range - fit function will be used in this range to predict afterpulse amplitudes forwarded to norm_spe

The integration test in tests/integration_tests/config/derive_photon_electron_spectrum_lst_ecsv.yml has been adopted and applies a fit now. Updated test files to include errors on afterpulse measurements.

There is a bit of fine tuning for LSTN right now; expect that some smaller changes will be necessary when using other data.

Added also a fix in run_applications handling Paths/str for the output path naming.

@GernotMaier GernotMaier self-assigned this Mar 20, 2025
@GernotMaier GernotMaier requested a review from Copilot March 20, 2025 09:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds the capability to fit the afterpulse spectrum as part of the single photon electron spectrum derivation. Key changes include:

  • Integration of an exponential decay fit with an optional fixed decay factor parameter.
  • Updates to unit tests to support the new parameters and function signatures.
  • Improvements in command-line configuration and output path resolution for the derived spectra.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

File Description
tests/unit_tests/camera/test_single_photon_electron_spectrum.py Updated test cases to pass the new parameters required by the updated spectrum derivation functions.
src/simtools/camera/single_photon_electron_spectrum.py Modified key functions (_derive_spectrum_norm_spe, _get_input_data, fit_afterpulse_spectrum, afterpulse_fit_function, etc.) to support new afterpulse fitting features.
src/simtools/applications/derive_photon_electron_spectrum.py Updated command-line arguments to reflect the new fitting options and amplitude range for afterpulse analysis.
src/simtools/applications/run_application.py Adjusted output path construction and list comprehension to correctly handle string replacements in configuration.
Files not reviewed (1)
  • tests/resources/LST_afterpulses.ecsv: Language not supported
Comments suppressed due to low confidence (1)

src/simtools/camera/single_photon_electron_spectrum.py:244

  • [nitpick] In the docstring for afterpulse_fit_function, the parameter is referred to as 'fix_K' instead of 'fix_k'. Consider updating the docstring for parameter naming consistency.
def afterpulse_fit_function(self, fix_k):

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@GernotMaier GernotMaier requested a review from orelgueta March 20, 2025 10:51
@GernotMaier GernotMaier marked this pull request as ready for review March 21, 2025 10:06
Copy link
Contributor

@orelgueta orelgueta left a comment

Choose a reason for hiding this comment

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

Minor comments, not approving yet though

"--threshold_afterpulse_spectrum",
help="Threshold for afterpulse ratio calculation",
"--afterpulse_amplitude_range",
help="Amplitude range in pe for afterpulse calculation",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this range for calculating the afterpulse? (we don't actually calculate it.)
Perhaps it is the range for fitting? In the other PR the limit from below was defaulted to 4.0 which makes more sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • fit is done in the range of available data points (so no user input on this)
  • afterpulse_amplitude_range is the range over which the fitted function is used to calculate afterpulses and forward it to norm_spe

Any suggestion on how to name it better? I don't have a good idea...

Copy link
Contributor

Choose a reason for hiding this comment

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

Name is fine (or it could be afterpulse_spectrum_range if you want). Perhaps the point is about the word "calculation", because I don't expect we calculate the afterpulsing spectrum. Either way, it's not a big deal, you can leave it as is as well.

Base automatically changed from single-pe-setting-workflow-simplified to main March 21, 2025 12:39

This comment has been minimized.

Copy link

Passed

Analysis Details

0 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 0 Code Smells

Coverage and Duplications

  • Coverage 100.00% Coverage (95.90% Estimated after merge)
  • Duplications 0.00% Duplicated Code (0.00% Estimated after merge)

Project ID: gammasim_simtools_AY_ssha9WiFxsX-2oy_w

View in SonarQube

@GernotMaier GernotMaier merged commit 85f82fe into main Mar 21, 2025
14 checks passed
@GernotMaier GernotMaier deleted the single-pe-fit branch March 21, 2025 14:27
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