Skip to content

Conversation

@mvicenzi
Copy link
Member

@mvicenzi mvicenzi commented Dec 18, 2025

This PR closes #18

It includes the following changes:

  • The primaries output tree is removed; simplified primary particles info is now saved in the event tree for each vertex, while full information can be found in the new particles tree.

  • Full particle truth is moved into a general particles tree. By default, this tree stores the following particles:
    -- all primaries;
    -- all particles leaving hits in any SD;
    -- all ancestors of any particle leaving hits in any SD;.
    This tree is the last to be filled as particles (and their ancestors) are registered to be saved while looping the hits for the other output trees. It should provide all that's needed to recover the particle hierarchy of interest.

  • The particles tree can be forced to save all particles in the event (regardless of whether they left hits or not) by setting the /out/saveAllParticles to true. Note that in this case the output file can grow quickly and become quite big.

  • The particles tree can also be expanded to store the full particle trajectories by setting the /out/saveTrajectory parameter to true (needed by FPFDisplay).

  • A custom FPFTrajectory class now replaces the standard G4Trajectory. These trajectories are used to fill the new particles tree. This new class optionally disables storing individual trajectory points. As a result, if /out/saveTrajectory is false, G4 only stores light-weight tracks, which is better for memory usage.

  • StackingAction now fills two associations: one maps track_id into its parent_id and the second maps track_id to its ancestor_id (ie, the track id of the primary particle from which it came from). These two associations are used by the AnalysisManager for its particle-saving logic.

  • The computation of the ACTS-style barcode/particle_id is now perfomed by an helper function: to speed things out, values are cached in a map so they can be retrieve by all functions without re-computing. The above associations are used in this function to determine the number of generations of a particle from its ancestor.

  • The ACTS particles tree is removed in favor of the generic one which now contains the same (and more!) information.

Let me know what you think/ if you have suggestions!

EDIT: update description after latest changes.

@mvicenzi mvicenzi linked an issue Dec 18, 2025 that may be closed by this pull request
@mvicenzi mvicenzi self-assigned this Dec 18, 2025
@mvicenzi mvicenzi added the enhancement New feature or request label Dec 18, 2025
@mvicenzi mvicenzi changed the title Unifiy output tree for particles/trajectories Unify output tree for particles/trajectories Dec 18, 2025
@mvicenzi
Copy link
Member Author

One possibility that comes to mind is the saving only particles that leave hits + all their ancestors; so basically:

  • all primaries;
  • all particles leaving hits in any SD;
  • all ancestors of any particle leaving hits in any SD;

Basically, we would first store all track IDs of interest as we loop over the hits in AnalysisManager.
Then, while looping through the trajectories, just select those of interest or their ancestors.
This last task can probably be accomplished more efficiently by preparing in advance some kind of "daughter-parent" association.

@benw22022
Copy link
Contributor

Thanks @mvicenzi, this sounds like a nice idea! I'll review this as soon as I get some time

@mvicenzi
Copy link
Member Author

Thanks @mvicenzi, this sounds like a nice idea! I'll review this as soon as I get some time

Thanks! Don't worry -- take your time for the review, I will also need to push new updates.
I thought it over, and I think I'm going to implement the changes I mentioned in my comment.

@mvicenzi
Copy link
Member Author

I have pushed the latest changes -- I think this is a good compromise, and the file sizes are now more reasonable.
FLArE-specific output needs to be optimized better, but that will be handled in #19 ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge primaries and trajectories into a single "particles" tree

3 participants