Skip to content

NR filter and edit cuts and selections logic#372

Open
cfuselli wants to merge 34 commits intomainfrom
nr_micro_clustering_carlo
Open

NR filter and edit cuts and selections logic#372
cfuselli wants to merge 34 commits intomainfrom
nr_micro_clustering_carlo

Conversation

@cfuselli
Copy link
Member

@cfuselli cfuselli commented Jan 29, 2026

This pull request makes several significant improvements and refactors to the microphysics simulation plugins, with a focus on standardizing data dependencies, expanding the available selection and cut plugins, and improving modularity for future extensions. The main changes include switching plugin dependencies from interactions_in_roi to clustered_interactions, adding a new NR (nuclear recoil) cut plugin and simulation class, and ensuring new fields (quanta_fields, electric_fields) are included in relevant summaries and outputs.

Refactoring and Standardization of Plugin Dependencies:

  • Updated multiple plugins (ElectricField, NestYields, BBFYields) to depend on clustered_interactions instead of interactions_in_roi, and changed their data_kind accordingly for consistency and future extensibility. [1] [2] [3] [4] [5] [6] [7]

Enhancements to Selection and Cut Plugins:

  • Added a new NRCut plugin that filters the microphysics summary for valid nuclear recoil (NR) events, with configurable parameters for photon/electron yields and S1/S2 area thresholds.
  • Introduced a new NRSimulation class that applies the NR cut, expanding the simulation capabilities for NR event studies.

Expansion of Data Fields in Summaries:

  • Updated the SelectionMerger plugin and related simulation classes to include quanta_fields and electric_fields in their summaries, ensuring downstream analyses have access to these quantities. [1] [2] [3]

General Plugin Improvements and Exports:

  • Added strax.exporter() and @export decorators to several plugins and files to improve discoverability and modularity, making it easier to extend or reuse these plugins. [1] [2]

Other Notable Changes:

  • Changed the output provided by the SelectionMerger plugin from interactions_in_roi to microphysics_summary, and renamed the output of MicroPhysicsSummary to microphysics_summary_AHA for clarity and consistency. [1] [2]

WenzDaniel and others added 24 commits October 21, 2025 02:34
* Update HISTORY.md for version 1.6.1 changes

* Bump version from 1.6.0 to 1.6.1

* Bump version to 1.6.1

* Bump version from 1.6.0 to 1.6.1

* Update PyPI publish action to use specific release

* Upgrade pypa/gh-action-pypi-publish version

Updated the version of the pypa/gh-action-pypi-publish action to v1.13.0.

* Update PyPI publish action version
* Add elife to cs2 corrections

* Update condition for cs2 and alt_cs2 assignment
* Bump version: 1.6.1 → 1.6.2

* Update HISTORY.md for version 1.6.2

* Update HISTORY.md to remove changelog link

Removed the full changelog link from the HISTORY.md file.
Co-authored-by: Carlo Fuselli <cfuselli@nikhef.nl>
…G4 (#361)

* Modified load_root_file for supporting multiple primary positions in G4 root files.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add elife to cs2 corrections (#368)

* Add elife to cs2 corrections

* Update condition for cs2 and alt_cs2 assignment

* Release 1.6.2 (#369)

* Bump version: 1.6.1 → 1.6.2

* Update HISTORY.md for version 1.6.2

* Update HISTORY.md to remove changelog link

Removed the full changelog link from the HISTORY.md file.

* Fix root input to accept both 1D primary per event and 2D

* bump plugin version

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Saad el Morabit <selmorab@nikhef.nl>
Co-authored-by: Carlo Fuselli <cfuselli@nikhef.nl>
Co-authored-by: Minghao Liu <mhliu0001@sina.com>
* Added NR yields, updated defaut yields treatment

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix typo

* Update test simulation config from sr1_dev to sr2_dev

* Update simulation config file for microphysics context

* env var in tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix precommit

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Carlo Fuselli <cfuselli@nikhef.nl>
* Make NR flag more flexible

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* bump plugin version

* fix precommit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Carlo Fuselli <cfuselli@nikhef.nl>
@cfuselli cfuselli changed the title Fit NR filter into cuts and selections logic NR filter and edit cuts and selections logic Jan 29, 2026
@cfuselli cfuselli changed the base branch from nr_micro_clustering to main January 29, 2026 13:29
Copy link

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 pull request performs a comprehensive renaming of data kinds and function arguments from interactions_in_roi/delayed_interactions_in_roi to microphysics_summary/delayed_microphysics_summary across the fuse detector physics simulation framework. Additionally, it introduces significant architectural changes to the data pipeline, including moving yields calculation earlier in the processing chain and adding a new NR (Nuclear Recoil) event filtering capability.

Changes:

  • Renamed interactions_in_roi to microphysics_summary and delayed_interactions_in_roi to delayed_microphysics_summary throughout all plugins, function signatures, and data_kind declarations
  • Restructured the microphysics pipeline so that yields and electric field calculations occur on clustered_interactions (before selection cuts) rather than after ROI filtering
  • Added NRCut plugin for filtering nuclear recoil events based on expected signal characteristics
  • Added NRSimulation selection merger class that combines volume selection with NR-specific cuts

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
fuse/plugins/truth_information/surviving_clusters.py Updated data_kind and renamed compute method parameter from interactions_in_roi to microphysics_summary
fuse/plugins/truth_information/peak_truth.py Updated compute method signature and internal variable references to use microphysics_summary
fuse/plugins/truth_information/event_truth.py Updated compute method signature to use microphysics_summary parameter
fuse/plugins/truth_information/cluster_tagging.py Updated data_kind and all method signatures and internal references
fuse/plugins/micro_physics/yields.py Changed dependency from interactions_in_roi to clustered_interactions, moving yields calculation earlier in pipeline
fuse/plugins/micro_physics/microphysics_summary.py Updated depends_on reference (contains critical bug - circular dependency)
fuse/plugins/micro_physics/electric_field.py Changed to depend on and process clustered_interactions instead of interactions_in_roi
fuse/plugins/micro_physics/cuts_and_selections/physics_cases.py Added new NRCut plugin with filter logic for nuclear recoil events
fuse/plugins/micro_physics/cuts_and_selections/detector_volumes.py Added export decorator for VolumeSelection class
fuse/plugins/micro_physics/cuts_and_selections/apply_selections.py Updated SelectionMerger to provide microphysics_summary and added NRSimulation class
fuse/plugins/detector_physics/secondary_scintillation.py Updated data_kind mapping and compute method signature
fuse/plugins/detector_physics/s1_photon_propagation.py Updated compute method parameter name
fuse/plugins/detector_physics/s1_photon_hits.py Updated data_kind and compute method signature with all internal references
fuse/plugins/detector_physics/electron_propagation.py Updated compute method signature and all position/field references
fuse/plugins/detector_physics/electron_drift.py Updated data_kind and compute method with all internal variable references
fuse/plugins/detector_physics/delayed_electrons/photo_ionization_electrons.py Updated data_kind, documentation, and compute method signature
fuse/plugins/detector_physics/delayed_electrons/delayed_electrons_secondary_scintillation.py Updated data_kind mapping and method signatures
fuse/plugins/detector_physics/delayed_electrons/delayed_electrons_s1photonhits.py Updated data_kind and compute method
fuse/plugins/detector_physics/delayed_electrons/delayed_electrons_propagation.py Updated compute method signatures to pass renamed parameter to parent
fuse/plugins/detector_physics/delayed_electrons/delayed_electrons_merger.py Updated data_kind for all merger plugins
fuse/plugins/detector_physics/delayed_electrons/delayed_electrons_drift.py Updated data_kind and compute method signature
fuse/plugins/detector_physics/csv_input.py Updated data_kind assignment
fuse/common.py Updated color map key from interactions_in_roi to microphysics_summary

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

cfuselli and others added 5 commits January 29, 2026 07:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 142 to 156
for event_i in event_ids:
start_index = vertex_i
max_photons = 0
max_electrons = 0
prompt_photons = 0
number_of_nr_interactions = 0
start_time = mps["time"][vertex_i]

for vertex_i in range(start_index, len(mps)):
vertex = mps[vertex_i]

_is_a_new_event = event_i < vertex["eventid"]
if _is_a_new_event:
# Next event starts break for loop and check next event
break
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The filter_events function assumes that all vertices with the same eventid are contiguous in the input array (lines 150-156). However, the clustered_interactions data is sorted by time (as seen in merge_cluster.py and merge_lineage.py), not by eventid. If interactions from different events have overlapping times, they may not be grouped by eventid, causing this function to process events incorrectly. Consider either: 1) sorting the input by eventid before processing, or 2) documenting the assumption that events are time-separated, or 3) using a different algorithm that doesn't assume contiguous event groups (e.g., processing all vertices and building event-based masks separately).

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI commented Jan 29, 2026

@cfuselli I've opened a new pull request, #373, to work on those changes. Once the pull request is ready, I'll request review from you.

cfuselli and others added 4 commits January 29, 2026 08:29
… vertex (#373)

* Initial plan

* Fix slice index bug to include last vertex when NR ROI check fails

Co-authored-by: cfuselli <62354392+cfuselli@users.noreply.github.com>

* Use explicit boolean flag for better code clarity

Co-authored-by: cfuselli <62354392+cfuselli@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: cfuselli <62354392+cfuselli@users.noreply.github.com>
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.

7 participants