Skip to content

Updates to HFTrackEfficiency and KFParticle#4259

Open
rosstom2232 wants to merge 6 commits into
sPHENIX-Collaboration:masterfrom
rosstom2232:TPOTQA
Open

Updates to HFTrackEfficiency and KFParticle#4259
rosstom2232 wants to merge 6 commits into
sPHENIX-Collaboration:masterfrom
rosstom2232:TPOTQA

Conversation

@rosstom2232
Copy link
Copy Markdown
Contributor

@rosstom2232 rosstom2232 commented May 1, 2026

comment: For KFParticle this PR just adds DCA significance relative to the PV and other tracks in the decay as measurements to what gets stored in the output nTuple. For HFTrackEfficiency, this PR adds output variables for the truth mother rapidity and truth daughter track rapidities so those values can be used in offline analysis. Additionally, this PR fixes an issue in HFTrackEfficiency where decays with intermediate resonances would not be processed correctly if the G4 truth information needed to be accessed instead of the HepMC record. 2 prong decays should be unaffected by this update, but HFTrackEfficiency should now be able to handle decays with a bachelor track and an intermediate resonance decaying to 2 tracks (such as the cascade->Lambda(->proton+pion)pion). Be careful for decays outside of that format, however, as it does not generalize to any decay topology.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work for users)
  • Requiring change in macros repository (Please provide links to the macros pull request in the last section)
  • I am a member of GitHub organization of sPHENIX Collaboration, EIC, or ECCE (contact Chris Pinkenburg to join)

What kind of change does this PR introduce? (Bug fix, feature, ...)

TODOs (if applicable)

Links to other PRs in macros and calibration repositories (if applicable)

Summary

Motivation / Context

These updates enhance the reconstruction and analysis capabilities for heavy-flavor physics at the sPHENIX collaboration. The changes add precision measurements of track-vertex distances and enable proper truth matching for cascade decay topologies that involve intermediate resonances.

Key Changes

HFTrackEfficiency Package:

  • Truth rapidity outputs: Adds m_true_mother_rapidity and m_true_track_rapidity[] to nTuple branches, enabling detailed kinematic studies of decay topologies
  • Intermediate resonance handling: Implements fix for 3-prong decays containing intermediate resonances (e.g., cascade → Λ(→ p + π) + π). When processing G4 truth data, the code now correctly substitutes the intermediate resonance as the mother particle by checking its parent PID and barcode, enabling proper truth matching for these decay modes
  • HepMC rapidity calculation: Adds manual rapidity computation for HepMC mother particles using (e, pz) formula with underflow protection

KFParticle Package:

  • DCA significance measurements: Introduces per-track DCA significance relative to the primary vertex (DCA_sig, DCA_sig_xy) computed via GetDeviationFromVertex() and GetDeviationFromVertexXY()
  • Track-pair DCA significance: Adds track-to-track DCA significance (DCA_sig, DCA_sig_xy) for all track pairs computed via GetDeviationFromParticle() and GetDeviationFromParticleXY()
  • These complement existing DCA measurements with statistical significance information

Potential Risk Areas

  1. I/O Format Changes: New TTree branches (DCA_sig, DCA_sig_xy, true_mother_rapidity, true_track_rapidity) are added to output nTuples. Downstream analyses must account for these additions or filter them appropriately.

  2. Intermediate Resonance Fix Limitations: The implementation is specifically designed for "bachelor + 2-body intermediate" topology. The PR documentation explicitly cautions against generalizing to arbitrary decay topologies; users must verify compatibility with their specific decay modes.

  3. Truth Matching Complexity: The expanded logic with branching on m_nDaughters == 2 vs. m_nDaughters == 3 introduces more conditional paths. Edge cases with unusual barcode or PID values should be tested.

  4. Computation Overhead: DCA significance calculations (deviation measurements) are performed for all track-vertex and track-pair combinations; performance impact should be evaluated for high-occupancy events.

  5. Backward Compatibility: Existing analyses using two-prong decays remain unaffected, but those processing cascade decays via G4 truth will see corrected mother assignments.

Possible Future Improvements

  • Generalize intermediate resonance handling to arbitrary decay topologies, or provide a configurable parser for decay structures
  • Optimize DCA significance computation for high-multiplicity events
  • Add systematic studies of DCA significance thresholds for track quality selection
  • Extend rapidity outputs to intermediate resonance candidates for complete kinematic reconstruction

Note: AI summary may contain errors; code review best judgment recommended for production use.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

The PR extends kinematics tracking in heavy-flavor reconstruction by adding rapidity computation for mother and daughter particles in HFTrackEfficiency, expanding truth-matching logic to handle different daughter multiplicities, and recording DCA significance quantities in KFParticle nTuples.

Changes

Cohort / File(s) Summary
HFTrackEfficiency: Rapidity and truth-matching
offline/packages/HFTrackEfficiency/HFTrackEfficiency.h, offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc
Adds scalar m_true_mother_rapidity and array m_true_track_rapidity data members; implements manual rapidity calculation for HepMC mothers using (e, pz) with underflow guards; populates rapidity values from truth-matched lorentz vectors and TTree branches. Expands truth-matching logic to branch on m_nDaughters: adds dedicated paths for m_nDaughters == 2 (including daughterG4->identify(), m_is_primary determination, and truth kinematics/vertex filling) and m_nDaughters == 3 (including conditional mother substitution with parent particle and loop exit via break).
KFParticle_nTuple: DCA significance
offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.h, offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.cc
Adds four floating-point member arrays for DCA significance: m_calculated_daughter_PV_dca_sig, m_calculated_daughter_PV_dca_xy_sig (per-track PV significance), and m_daughter_dca_sig, m_daughter_dca_xy_sig (fixed-size daughter pair storage). Populates significance quantities via GetDeviationFromVertex, GetDeviationFromVertexXY (PV constraints) and GetDeviationFromParticle, GetDeviationFromParticleXY (track-pair DCAs), aligned with existing DCA pair indexing.

Possibly related PRs


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 41593349-771c-408d-9a5f-dd3fa30ee887

📥 Commits

Reviewing files that changed from the base of the PR and between 9582033 and dd98db2.

📒 Files selected for processing (4)
  • offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc
  • offline/packages/HFTrackEfficiency/HFTrackEfficiency.h
  • offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.cc
  • offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.h

Comment on lines +218 to +225
if (mother->momentum().e() > abs(mother->momentum().pz()))
{
m_true_mother_rapidity = 0.5 * log((mother->momentum().e() + mother->momentum().pz())/(mother->momentum().e() - mother->momentum().pz()));
}
else
{
m_true_mother_rapidity = -999.;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Inconsistent sentinel value for invalid rapidity.

When the rapidity cannot be computed, -999. is used, but elsewhere in the class (e.g., resetBranches() at line 605), quiet_NaN() is used to indicate invalid/unset values. Downstream analysis code checking std::isnan() will miss these cases.

Consider using NaN for consistency:

Proposed fix
   if (mother->momentum().e() > abs(mother->momentum().pz()))
   {
     m_true_mother_rapidity = 0.5 * log((mother->momentum().e() + mother->momentum().pz())/(mother->momentum().e() - mother->momentum().pz()));
   }
-  else
-  {
-    m_true_mother_rapidity = -999.;
-  }
+  // else: m_true_mother_rapidity remains at its initialized NaN value

Alternatively, if -999. is intentional for compatibility with existing analysis code, please document this choice clearly.

Comment on lines +311 to +314
if (Verbosity() >= VERBOSITY_MORE || true) // fix later
{
daughterG4->identify();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Debug code left in: || true bypasses verbosity check.

The condition Verbosity() >= VERBOSITY_MORE || true always evaluates to true, causing daughterG4->identify() to print for every matched daughter regardless of verbosity setting. The comment "fix later" confirms this is unintentional.

Proposed fix
-           if (Verbosity() >= VERBOSITY_MORE || true) // fix later
+           if (Verbosity() >= VERBOSITY_MORE)
            {
              daughterG4->identify();
            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (Verbosity() >= VERBOSITY_MORE || true) // fix later
{
daughterG4->identify();
}
if (Verbosity() >= VERBOSITY_MORE)
{
daughterG4->identify();
}

Comment on lines +212 to +213
float m_daughter_dca_sig[99]{0};
float m_daughter_dca_sig_xy[99]{0};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Pairwise DCA-significance buffers are undersized and can overflow.

At Line 212 and Line 213, capacity is 99, but pairwise loops in offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.cc can write up to m_num_tracks_nTuple*(m_num_tracks_nTuple-1)/2 entries. With max_tracks=20, that is 190 entries, so these arrays can be written out-of-bounds (memory corruption/crash risk).

💡 Proposed fix
--- a/offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.h
+++ b/offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.h
@@
-  float m_daughter_dca[99]{0};
-  float m_daughter_dca_xy[99]{0};
-  float m_daughter_dca_sig[99]{0};
-  float m_daughter_dca_sig_xy[99]{0};
+  static constexpr int max_track_pairs{max_tracks * (max_tracks - 1) / 2};
+  float m_daughter_dca[max_track_pairs]{0};
+  float m_daughter_dca_xy[max_track_pairs]{0};
+  float m_daughter_dca_sig[max_track_pairs]{0};
+  float m_daughter_dca_sig_xy[max_track_pairs]{0};

As per coding guidelines, **/*.{cc,cpp,cxx,c}: “Prioritize correctness, memory safety, error handling, and thread-safety.”

@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit dd98db258886298d85a63a02faedbb2e0eeafe31:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

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.

1 participant