Skip to content

Feature/aantonak caf truthfix - #674

Open
aantonakis wants to merge 8 commits into
production/sbnd-gen2from
feature/aantonak_caf_truthfix
Open

aantonakis wants to merge 8 commits into
production/sbnd-gen2from
feature/aantonak_caf_truthfix

Conversation

@aantonakis

@aantonakis aantonakis commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Please provide a detailed description of the changes this pull request introduces. If available, also link to a docdb link where the issue/change have been presented on/discussed.

This PR adds missing truth information to the CAFMaker output. Some unstable particles produced in the neutrino interaction such as eta mesons are missing in the CAF truth outputs because they are not propagated to Geant4. The goal of this PR is to identify primary particles of the interaction which are missing their parent particles and to loop back through the decay chain in the generator truth to add in the missing information. This is described in more detail in SBN docdb entry 49027.

  • Have you added a label? (bug/enhancement/physics etc.)
  • Have you assigned at least 1 reviewer?
  • Is this PR related to an open issue / project?
  • Does this PR affect CAF data format? If so, please assign a CAF maintainer as additional reviewer. @Gianluca Petrillo and @thomas Jones
  • Does this PR require merging another PR in a different repository (such as sbnanobj/sbnobj etc.)? If so, please link it in the description.
  • Are you submitting this PR on behalf of someone else who made the code changes? If so, please mention them in the description.

@aantonakis aantonakis added the enhancement New feature or request label Sep 10, 2026
@linyan-w
linyan-w requested a review from kjplows September 10, 2026 12:52
@linyan-w linyan-w moved this to Waiting on Reviewer in SBND 2025 Gen2 Production Sep 10, 2026
@aantonakis
aantonakis removed the request for review from linyan-w September 10, 2026 17:27
@aantonakis
aantonakis marked this pull request as ready for review October 6, 2026 08:39

@tjones79 tjones79 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks @aantonakis, this looks great!

There are a few comments as I was trying to figure out Genie -> G4 indices. I hope they are helpful


// Now we can check if we need to fill this missed parent in the CAF
if (matchedGenie->Mother() != min_g4_track_id-1) {
const simb::MCParticle& missedParent = inventoryTruth->GetParticle(matchedGenie->Mother());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it guaranteed that the GENIE TrackId always perfectly matches its index in the MCTruth vector? (Also asking to gain knowledge for myself!) For instance, if intermediate particles get filtered out or IDs skip numbers? Passing Mother() directly into GetParticle() in that case could access the wrong particle or cause an out-of-bounds

I guess a more robust way to do this would be to safely look up the parent by explicitly searching for the matching TrackId

if (matchedGenie) {

// Now we can check if we need to fill this missed parent in the CAF
if (matchedGenie->Mother() != min_g4_track_id-1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I had thought that GENIE's 'no mother' value is typically -1, not the G4 boundary (min_g4_track_id-1, which is usually 0, as I believe you have used correctly above).

If that is the case, matchedGenie is a GENIE particle, so if it has no mother, it will pass the != 0 check and cause an out-of-bounds lookup at index -1. So should this be changed?

caf::SRTrueParticle &srparticle, int interaction_id, int id_offset) {

std::vector<std::pair<geo::WireID, const sim::IDE *>> empty;
const std::vector<std::pair<geo::WireID, const sim::IDE *>> &particle_ides = id_to_ide_map.count(particle.TrackId()) ? id_to_ide_map.at(particle.TrackId()) : empty;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to my comment/question on the module file

Are the keys in id_to_ide_map and id_to_truehit_map Geant4 track IDs?

Since particle here is a GENIE particle, I'm slightly concerned that particle.TrackId() might accidentally collide with an unrelated Geant4 track ID, giving this unpropagated particle someone else's detector hits. Since these GENIE particles didn't go through Geant4 anyway, can we safely just remove these map lookups and leave their visE and nhit at 0?


// Special GENIE particles get a shifted positive ID so they do not overlap with G4 track IDs.
srparticle.G4ID = particle.TrackId() + id_offset;
srparticle.parent = particle.Mother() > 0 ? static_cast<unsigned>(particle.Mother() + id_offset) : 0u;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, similar to previous comments

I think GENIE uses -1 for particles with no mother, whereas Geant4 uses 0. Please disregard this and other comments if I'm incorrect!

In that case, if a GENIE particle's mother has a track ID of 0 (neutrino), > 0 will evaluate to false and return 0u instead of 0 + id_offset, right? Should this be particle.Mother() != -1 instead?


// Save the daughter particles
for (int i_d = 0; i_d < particle.NumberDaughters(); i_d++) {
srparticle.daughters.push_back(particle.Daughter(i_d));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this need to be particle.Daughter(i_d) + id_offset?

// Incoming neutrino.

if (particle.TrackId() ==
truth.GetNeutrino().Nu().TrackId())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Will this work if the module runs over a file that includes Cosmic Ray Overlays or Particle Gun events? (Cases where MCTruth record contains no neutrino)

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

Status: Waiting on Reviewer

Development

Successfully merging this pull request may close these issues.

3 participants