Skip to content

Updates to HFTrackEfficiency and KFParticle#4259

Merged
osbornjd merged 7 commits into
sPHENIX-Collaboration:masterfrom
rosstom2232:TPOTQA
May 29, 2026
Merged

Updates to HFTrackEfficiency and KFParticle#4259
osbornjd merged 7 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

Enhance heavy-flavor reconstruction and offline analysis by (1) adding DCA significance measurements to KFParticle nTuples to better quantify track-vertex and track-pair consistency, and (2) improving HFTrackEfficiency truth outputs and truth-matching for cascade-style decays that include an intermediate resonance so those decays can be analyzed correctly when only Geant4 (G4) truth is available.

Key Changes

  • HFTrackEfficiency
    • Adds true rapidity outputs: m_true_mother_rapidity and m_true_track_rapidity[] are written to the nTuple (with NaN defaults and HepMC underflow guards).
    • Fixes truth-matching for decays with a bachelor + intermediate 2-body resonance (e.g., cascade → Λ(→ p+π) + π) when using G4 truth: code may substitute the intermediate resonance as the mother under specific parent/PID/barcode checks to enable correct matching.
    • Separates truth-matching logic based on m_nDaughters (dedicated 2- and 3-daughter paths).
  • KFParticle
    • Adds per-track DCA significance relative to the primary vertex: DCA_sig and DCA_sig_xy (via GetDeviationFromVertex / GetDeviationFromVertexXY).
    • Adds track-pair DCA significance: DCA_sig and DCA_sig_xy for each i<j pair (via GetDeviationFromParticle / GetDeviationFromParticleXY).
    • New branches and arrays added to nTuple headers and initialization; no public API signature changes.

Potential Risk Areas

  • I/O changes: New TTree branches (true rapidities, DCA_sig, DCA_sig_xy) alter nTuple contents; downstream jobs or merging/reading tools should be verified to tolerate additional branches.
  • Truth-matching limitations: The G4 fix targets the specific "bachelor + 2-body intermediate resonance" topology and does not generalize to arbitrary or deeper decay trees. Users must validate other topologies before trusting results.
  • Control-flow complexity: Additional branching by m_nDaughters and special-case substitution of mother candidates introduces more conditional paths and potential edge cases (barcode/PID handling).
  • Performance: Computing deviation/significance for all tracks and all pairs may increase CPU cost for high-multiplicity events; benchmark impact on reconstruction/analysis workflows.
  • Thread-safety/behavior: No explicit thread-safety changes in public interfaces, but increased per-event memory and branch handling should be sanity-checked in multi-threaded runs.

Possible Future Improvements

  • Generalize intermediate-resonance/truth-matching to arbitrary decay topologies or provide a configurable decay-matching utility.
  • Offer options to compute/store significance selectively (config flags or multiplicity-dependent heuristics) to reduce CPU cost.
  • Provide rapidity outputs for intermediate resonance candidates and additional truth kinematics to support more complete kinematic reconstruction.
  • Add validation tests and performance benchmarks for high-occupancy events and for varied truth sources (HepMC vs G4).

Note: This summary was produced with AI assistance. AI can make mistakes—please review changes in code and tests carefully before relying on them in production.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2a85ee12-583b-4c0b-8d34-2b064880e0cf

📥 Commits

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

📒 Files selected for processing (1)
  • offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc

📝 Walkthrough

Walkthrough

Adds guarded HepMC mother rapidity computation and per-daughter rapidity storage to HFTrackEfficiency, restructures truth-matching into m_nDaughters==2 and ==3 paths, adds related TTree branches and resets; separately, KFParticle_nTuple now records DCA significance (PV and pair) per track/pair.

Changes

HFTrackEfficiency: Rapidity and truth-matching

Layer / File(s) Summary
Mother rapidity calculation, TTree branch and reset
offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc
Computes guarded HepMC mother rapidity from (e,pz), adds true_mother_rapidity TTree branch, and resets it to NaN each event.
Truth-matching per-daughter rapidity and branching by m_nDaughters
offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc, offline/packages/HFTrackEfficiency/HFTrackEfficiency.h
Refactors truth-matching to handle m_nDaughters == 2 and == 3, determines daughter identify() and m_is_primary, fills mother/daughter true kinematics (including m_true_mother_rapidity, m_true_track_rapidity) and PID, adds per-daughter TTree branches and NaN resets, and uses controlled loop exit on successful match.

KFParticle_nTuple: DCA significance

Layer / File(s) Summary
DCA significance branches and fills
offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.h, offline/packages/KFParticle_sPHENIX/KFParticle_nTuple.cc
Adds member arrays for per-track PV DCA significance (m_calculated_daughter_PV_dca_sig, m_calculated_daughter_PV_dca_xy_sig) and for daughter-pair DCA significance (m_daughter_dca_sig, m_daughter_dca_sig_xy), and populates them using GetDeviationFromVertex{,XY} and GetDeviationFromParticle{,XY} aligned with existing 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

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

@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit 996eb322f88119c7074d68a145ba5c14d0eff77d:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@osbornjd osbornjd merged commit 8791bc8 into sPHENIX-Collaboration:master May 29, 2026
22 checks passed
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.

2 participants