Skip to content
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

refactor: Split particle selection in Examples #3969

Merged
merged 14 commits into from
Jan 21, 2025

Conversation

andiwand
Copy link
Contributor

@andiwand andiwand commented Dec 9, 2024

  • split particle selection into three stages: after generation, after simulation, after digitization
  • this allows to perform cuts on the particle collections independent from the algorithms processing them
  • after digitization cuts allow to cut on measurement count
  • elevates particle selection into reconstruction chain

blocked by

Summary by CodeRabbit

Release Notes: Particle Processing and Naming Convention Update

Overview

This release introduces significant improvements to particle processing workflows, focusing on more precise particle selection and standardized naming conventions.

Key Changes

Particle Selection

  • Added new functions for particle selection at different stages:
    • addGenParticleSelection: Selects particles during generation
    • addSimParticleSelection: Selects particles during simulation
    • addDigiParticleSelection: Selects particles during digitization

Naming Conventions

  • Updated particle-related variable names from particles_input to particles_generated
  • Standardized input/output particle identifiers across multiple scripts and workflows

Particle Filtering

  • Simplified particle selection logic
  • Removed inline particle selection configurations
  • Enhanced modularity in particle processing

Impact

  • Improved clarity in particle handling
  • More flexible and consistent particle selection
  • Better separation of concerns in simulation workflows

@andiwand andiwand added this to the next milestone Dec 9, 2024
Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

In this comprehensive update, the codebase undergoes a systematic transformation of particle-related workflows across multiple scripts and modules. The primary focus is on standardizing particle naming conventions, introducing more modular particle selection functions, and refactoring how particles are processed during simulation, digitization, and tracking stages. Key changes include renaming input/output particle identifiers from "particles_input" to "particles_generated" and introducing new functions like addGenParticleSelection and addDigiParticleSelection.

Changes

File Path Change Summary
CI/physmon/workflows/physmon_simulation.py Renamed particle parameters from "particles_input" to "particles_generated"
Examples/Python/python/acts/examples/simulation.py Added new particle selection functions and modified existing selection logic
Examples/Scripts/Python/* Updated particle input/output naming and added modular particle selection functions

Sequence Diagram

sequenceDiagram
    participant PG as Particle Generator
    participant GS as Gen Particle Selection
    participant FA as Fatras
    participant DS as Digi Particle Selection
    participant TR as Tracking

    PG->>GS: Generate Particles
    GS->>FA: Selected Particles
    FA->>DS: Simulated Particles
    DS->>TR: Digitized Particles
Loading

Possibly related PRs

Suggested Labels

automerge, Track Fitting

Suggested Reviewers

  • paulgessinger

Poem

Particles dance, their paths rewrite,
From input's old to generated's light
Selection functions bloom and grow
Through simulation's gentle flow
Code's harmony, a Jedi's delight! 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Component - Examples Affects the Examples module label Dec 9, 2024
Copy link

github-actions bot commented Dec 9, 2024

📊: Physics performance monitoring for 71d59ad

Full contents

physmon summary

@github-actions github-actions bot added the Infrastructure Changes to build tools, continous integration, ... label Dec 9, 2024
@andiwand andiwand added the 🛑 blocked This item is blocked by another item label Jan 16, 2025
kodiakhq bot pushed a commit that referenced this pull request Jan 20, 2025
)

This allows us having multiple aliases pointing to the same object in the whiteboard which was not possible before because of the usage of `std::unordered_map` which is now replaced with `std::unordered_multimap`

Pulled out of #3969

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
	- Enhanced object aliasing capabilities in the framework.
	- Added support for multiple aliases per object name.

- **Refactor**
	- Updated data structures to support more flexible alias management.
	- Modified alias handling logic in WhiteBoard and Sequencer components.

- **Bug Fixes**
	- Improved error checking and logging for object aliases.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@andiwand andiwand removed the 🛑 blocked This item is blocked by another item label Jan 21, 2025
@andiwand andiwand marked this pull request as ready for review January 21, 2025 14:20
@andiwand andiwand requested a review from benjaminhuth January 21, 2025 14:23
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
Examples/Scripts/Python/full_chain_itk_Gbts.py (2)

55-63: Wise separation of concerns, this is!

Early particle selection after generation, implement you do. Clear criteria for selection:

  • rho: (0.0 mm, 28.0 mm)
  • absZ: (0.0 mm, 1.0 m)
  • eta: (-4.0, 4.0)
  • pt: (150 MeV, None)

Improve efficiency of subsequent processing steps, this will.


83-91: Strong with the force, this selection after digitization is!

Particle selection criteria after digitization, well-defined they are:

  • pt: (1.0 GeV, None)
  • eta: (-4.0, 4.0)
  • measurements: (9, None)
  • removeNeutral: true

Enhance reconstruction chain efficiency, this will. Wise to filter based on measurement counts, it is!

Examples/Scripts/Python/full_chain_itk.py (1)

87-95: Measurement-based selection, a powerful addition this is!

After digitization, selecting particles based on measurement counts, a good practice it is. Neutral particles, removed they are, as track them we cannot.

Consider adding documentation about the chosen threshold values, help future Padawans it will.

Examples/Scripts/Python/seeding.py (1)

102-110: Strong with the Force, this implementation is!

Clear selection criteria for particles after digitization, specified they are. Minimum PT threshold and measurement requirements, wise choices they are.

Add comments explaining the chosen thresholds, help future maintainers it will:

     addDigiParticleSelection(
         s,
         ParticleSelectorConfig(
+            # Minimum PT threshold ensures good track quality
             pt=(1.0 * u.GeV, None),
+            # Standard tracker acceptance region
             eta=(-2.5, 2.5),
+            # Minimum measurements needed for reliable track reconstruction
             measurements=(9, None),
+            # Remove neutral particles as they don't leave tracker hits
             removeNeutral=True,
         ),
     )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc18b59 and 1650786.

📒 Files selected for processing (30)
  • CI/physmon/workflows/physmon_simulation.py (4 hunks)
  • CI/physmon/workflows/physmon_trackfinding_1muon.py (2 hunks)
  • CI/physmon/workflows/physmon_trackfinding_4muon_50vertices.py (2 hunks)
  • CI/physmon/workflows/physmon_trackfinding_ttbar_pu200.py (3 hunks)
  • Examples/Python/python/acts/examples/reconstruction.py (2 hunks)
  • Examples/Python/python/acts/examples/simulation.py (13 hunks)
  • Examples/Python/tests/conftest.py (3 hunks)
  • Examples/Python/tests/root_file_hashes.txt (1 hunks)
  • Examples/Python/tests/test_examples.py (2 hunks)
  • Examples/Python/tests/test_propagation.py (1 hunks)
  • Examples/Python/tests/test_reader.py (3 hunks)
  • Examples/Scripts/Optimization/ckf.py (3 hunks)
  • Examples/Scripts/Python/ckf_tracks.py (3 hunks)
  • Examples/Scripts/Python/digitization.py (1 hunks)
  • Examples/Scripts/Python/event_recording.py (1 hunks)
  • Examples/Scripts/Python/full_chain_itk.py (3 hunks)
  • Examples/Scripts/Python/full_chain_itk_Gbts.py (3 hunks)
  • Examples/Scripts/Python/full_chain_odd.py (5 hunks)
  • Examples/Scripts/Python/full_chain_odd_LRT.py (5 hunks)
  • Examples/Scripts/Python/full_chain_test.py (1 hunks)
  • Examples/Scripts/Python/hashing_seeding.py (3 hunks)
  • Examples/Scripts/Python/material_validation.py (2 hunks)
  • Examples/Scripts/Python/material_validation_itk.py (2 hunks)
  • Examples/Scripts/Python/propagation.py (2 hunks)
  • Examples/Scripts/Python/seeding.py (2 hunks)
  • Examples/Scripts/Python/telescope_track_params_lookup_generation.py (2 hunks)
  • Examples/Scripts/Python/truth_tracking_gsf.py (3 hunks)
  • Examples/Scripts/Python/truth_tracking_gx2f.py (3 hunks)
  • Examples/Scripts/Python/truth_tracking_kalman.py (3 hunks)
  • Examples/Scripts/Python/vertex_fitting.py (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • Examples/Python/python/acts/examples/reconstruction.py
  • Examples/Python/tests/root_file_hashes.txt
👮 Files not reviewed due to content moderation or server errors (4)
  • Examples/Scripts/Python/truth_tracking_gsf.py
  • Examples/Scripts/Python/truth_tracking_gx2f.py
  • Examples/Scripts/Python/truth_tracking_kalman.py
  • Examples/Scripts/Python/hashing_seeding.py
🧰 Additional context used
🪛 Ruff (0.8.2)
Examples/Scripts/Python/full_chain_odd_LRT.py

18-18: Redefinition of unused ParticleSelectorConfig from line 16

Remove definition: ParticleSelectorConfig

(F811)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: macos
🔇 Additional comments (34)
Examples/Scripts/Python/event_recording.py (1)

44-44: Approve the naming convention change, I do!

More descriptive, the new parameter name is. Reflects the generation stage of particles, it does. With the PR's objectives to split particle selection, aligned this change is.

Examples/Scripts/Python/digitization.py (2)

52-52: Consistent with the new naming convention, this change is!

From "particles_input" to "particles_generated", renamed the parameter is. Wise decision, this is.


56-58: A new whiteboard alias, introduced you have!

For selection stage, prepared this change is. Clear separation between generated and selected particles, it provides. The Force of good design, strong with this one is!

Examples/Python/tests/test_propagation.py (1)

65-66: In harmony with the Force, these changes are!

Updated consistently, all particle-related parameters are. From input to generated, the transition is complete:

  • inputParticles → "particles_generated"
  • outputTrackParameters → "params_particles_generated"
  • inputTrackParameters → "params_particles_generated"

A clear path through the stages of particle processing, this creates.

Also applies to: 74-74

Examples/Scripts/Python/telescope_track_params_lookup_generation.py (2)

50-50: Consistent with the new ways, these changes are!

To "particles_generated", renamed the parameters are. Throughout the codebase, harmony this brings.

Also applies to: 68-68


50-53: Removed preSelectParticles parameter, noticed I have!

A significant architectural change, this represents. To separate stages of particle selection, moved this functionality has been. Verify the new selection mechanism's implementation, we must.

Examples/Scripts/Python/material_validation.py (1)

45-46: Consistent with the force, these changes are!

Renamed parameters from "particles_input" to "particles_generated", align with the broader refactoring effort, they do. Maintain consistency across the codebase, this will.

Also applies to: 55-55

Examples/Scripts/Python/material_validation_itk.py (1)

52-53: Consistent naming conventions, maintain we must!

Renamed parameters from "particles_input" to "particles_generated", follow the path of consistency, they do. Harmony in the codebase, this brings.

Also applies to: 62-62

Examples/Scripts/Python/propagation.py (1)

36-37: In balance with other changes, these modifications are!

Renamed parameters from "particles_input" to "particles_generated", maintain consistency across the propagation code, they do. Clear path for particle tracking, this creates.

Also applies to: 53-53

CI/physmon/workflows/physmon_simulation.py (1)

60-60: Consistent naming, this change brings! Hmmmm.

From "particles_input" to "particles_generated", renamed these parameters are. Better clarity about particle state in pipeline, this provides.

Also applies to: 69-69, 80-80, 95-95

Examples/Scripts/Python/full_chain_itk.py (1)

60-68: Wise separation of concerns, this is! Hmmmm.

Early particle selection after generation, implemented well it is. Clear geometric and kinematic cuts, specified they are.

Examples/Scripts/Python/vertex_fitting.py (1)

36-36: Consistency in naming, achieved it is!

Throughout the vertex fitting workflow, aligned with new naming convention, these changes are. Harmony in the codebase, this brings.

Also applies to: 71-71, 77-77

CI/physmon/workflows/physmon_trackfinding_1muon.py (1)

86-94: Different measurement threshold, notice I do!

Different from other files, this configuration is:

  • 9 measurements required, instead of 7
  • Secondary particles, removed they are not
  • Rest of configuration, consistent it remains

Verify these differences intentional they are, you must.

Consider standardizing selection criteria across all tracking workflows, unless specific requirements justify the differences.

Examples/Scripts/Python/ckf_tracks.py (3)

32-33: Approve the import changes, I do!

Clear separation of concerns, these imports bring. A more modular approach to particle selection, they enable.


75-75: Consistent naming convention, this change follows!

From "particles_input" to "particles_generated", the transition makes. More descriptive of the actual stage in the particle processing pipeline, it is.


94-101: A well-structured particle selection configuration, this is!

Wise choices in selection criteria, you have made:

  • Minimum pt of 0.5 GeV
  • At least 9 measurements required
  • Neutral particles, removed they are

Clear and maintainable, the code becomes.

CI/physmon/workflows/physmon_trackfinding_4muon_50vertices.py (1)

83-90: Stricter particle selection criteria, I observe!

Higher pt threshold of 0.9 GeV, you have chosen. For a complex scenario with 4 muons and 50 vertices, appropriate this is. Clean track reconstruction, it shall enable.

CI/physmon/workflows/physmon_trackfinding_ttbar_pu200.py (2)

66-72: A wise geometric selection at generator level, you implement!

Restrict particles to:

  • rho < 24 mm
  • |z| < 1.0 m

Early selection at generator level, efficient processing it ensures. For high pileup scenario of ttbar with PU200, crucial this is.


89-96: Complementary kinematic selection at digitization level, you add!

Work together in harmony, the two selection stages do:

  1. First, geometric boundaries they respect
  2. Then, kinematic quality they ensure

A balanced approach to particle selection, achieved it is.

Examples/Scripts/Optimization/ckf.py (1)

183-190: Consistent with base implementation, these selection criteria are!

Match the criteria in ckf_tracks.py, they do:

  • Same pt threshold of 0.5 GeV
  • Same measurement requirement of 9
  • Same neutral particle removal

Consistency across optimization and standard scripts, maintain we must. Debugging and maintenance, easier it makes.

Examples/Python/tests/test_reader.py (2)

56-57: Approve the renaming of particle output, I do!

More descriptive the new naming is, better reflecting the generation stage of particles. Consistent with the PR's objective of splitting particle selection, this change is.

Also applies to: 62-62


320-322: Wise changes in EDM4hepReader configuration, these are!

Clear separation between generation and simulation stages, the new naming provides. With the PR's objective of splitting particle selection, this aligns perfectly.

Also applies to: 332-332

Examples/Python/tests/conftest.py (2)

214-215: Consistent naming in parameter extraction, observe I do!

Well aligned with the new particle selection stages, these changes are. Clarity and consistency, they bring to the codebase.


228-228: Harmonious with the new naming convention, this change is!

Propagation algorithm now speaks the same language as other components, it does.

Examples/Scripts/Python/full_chain_odd.py (3)

19-24: Strong with the Force, these new selection functions are!

Clear separation of particle selection stages, these additions provide:

  • Generation stage: addGenParticleSelection
  • Simulation stage: addSimParticleSelection
  • Digitization stage: addDigiParticleSelection

Line range hint 198-208: Well structured, the EDM4hep particle selection is!

Clear separation between generated and simulated particles, I observe. Wise selection criteria for simulation stage, you have chosen:

  • Rho and Z constraints for tracking volume
  • Reasonable eta range
  • Minimum pT threshold
  • Neutral particle removal

Also applies to: 211-219


311-319: Masterful digitization selection criteria, these are!

Appropriate for the digitization stage, these requirements are:

  • Higher pT threshold (1 GeV)
  • Reasonable eta range
  • Minimum measurement count
  • Neutral particle removal
Examples/Scripts/Python/full_chain_odd_LRT.py (1)

19-24: Mirror the standard chain's wisdom, these changes do!

Consistent implementation of three-stage particle selection between standard and LRT variants, I sense. Strong consistency in the Force, this brings.

Examples/Python/python/acts/examples/simulation.py (4)

54-79: Clean and well-structured implementation, hmmmm!

A helper function well-designed, it is. All particle selection parameters, it handles with care.


383-410: Wise changes in particle selection after generation, I sense!

Clear and descriptive naming convention, you have chosen. The force of modular design, strong with this one it is.


657-685: Duplicate code, I sense. Refactor we must!

Similar structure between particle selection functions, there is. A single function with a string argument, more elegant it would be.

Consider this refactor pattern:

def addParticleSelection(s: acts.examples.Sequencer,
                        config: ParticleSelectorConfig,
                        kind: str = "simulated",  # or "generated" or "digitized"
                        logLevel: Optional[acts.logging.Level] = None) -> None:
    customLogLevel = acts.examples.defaultLogging(s, logLevel)
    
    selector = acts.examples.ParticleSelector(
        **acts.examples.defaultKWArgs(**_getParticleSelectionKWargs(config)),
        level=customLogLevel(),
        inputParticles=f"particles_{kind}",
        outputParticles=f"tmp_particles_{kind}_selected",
    )
    s.addAlgorithm(selector)
    
    s.addWhiteboardAlias("particles_selected", selector.config.outputParticles)
    s.addWhiteboardAlias(
        f"particles_{kind}_selected", selector.config.outputParticles
    )

# Then provide convenience functions:
def addGenParticleSelection(*args, **kwargs):
    return addParticleSelection(*args, kind="generated", **kwargs)

def addSimParticleSelection(*args, **kwargs):
    return addParticleSelection(*args, kind="simulated", **kwargs)

def addDigiParticleSelection(*args, **kwargs):
    return addParticleSelection(*args, kind="digitized", **kwargs)

778-807: Particle selection after digitization, well implemented it is!

Consistent with other selection functions while handling digitization specifics, this implementation is. The force of good design practices, strong with this one it is.

Examples/Scripts/Python/full_chain_test.py (1)

404-404: Aligned with new naming convention, this change is!

From "particles_input" to "particles_generated", the path leads. Consistency in the force, I sense.

Examples/Python/tests/test_examples.py (1)

407-408: Test coverage, maintained and enhanced it is!

New particle selection functionality, properly tested it is. The path of thorough testing, you follow.

Also applies to: 440-448

Examples/Scripts/Python/full_chain_odd.py Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd.py Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd_LRT.py Show resolved Hide resolved
Copy link
Member

@benjaminhuth benjaminhuth left a comment

Choose a reason for hiding this comment

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

LGTM

@kodiakhq kodiakhq bot merged commit 89ad5d0 into acts-project:main Jan 21, 2025
42 checks passed
@andiwand andiwand deleted the ex-split-particle-selection branch January 21, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changes Performance Component - Examples Affects the Examples module Infrastructure Changes to build tools, continous integration, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants