Skip to content

HFTrackEfficiency updates#4232

Merged
osbornjd merged 2 commits into
sPHENIX-Collaboration:masterfrom
cdean-github:master
Mar 24, 2026
Merged

HFTrackEfficiency updates#4232
osbornjd merged 2 commits into
sPHENIX-Collaboration:masterfrom
cdean-github:master

Conversation

@cdean-github

@cdean-github cdean-github commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

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)

HFTrackEfficiency Updates

Motivation / Context

HFTrackEfficiency is a reconstruction analysis module for the sPHENIX experiment that studies heavy-flavor decay chain reconstruction efficiency. The module tracks true (generator-level) and reconstructed (detector-level) particle kinematics and stores them in ROOT TTrees for offline analysis. This PR adds new measurement capabilities and corrects an indexing bug affecting the alignment of truth-reco particle mappings.

Key Changes

  • Added azimuthal angle (φ) storage: Introduced m_true_track_phi[m_maxTracks] and m_reco_track_phi[m_maxTracks] arrays to store azimuthal angles for each daughter track, along with corresponding TTree branches for both mother particles and individual tracks.

  • Extended mother kinematic measurements: Added m_reco_mother_pT (computed from motherRecoLV.perp() when all daughters are found) and m_true_mother_phi data members for expanded mother particle characterization.

  • Fixed daughter array indexing: Replaced the prior i - 1 offset with a dedicated sequential index counter (initialized to -1), ensuring proper alignment between per-daughter kinematic arrays (m_true_track_pT, m_reco_track_pT, etc.) and the trackableParticles filtering logic. This indexing change appears to correct a latent bug where truth/reco assignments could become misaligned if the loop index did not match array positions.

  • Updated reconstructed track property bookkeeping: Extended write/read operations for kinematic limits, seed counts, and chi-squared values to use the corrected index counter.

Potential Risk Areas

  • Output File Format Change (IO): New TTree branches (reco_mother_pT, true_mother_phi, per-track _phi branches) change the structure of output ROOT files. Analyses built on previous output files will require updates to handle the new branches or be regenerated with this version.

  • Index Alignment Bug Fix: The shift from i - 1 to explicit indexing could affect backward compatibility and may change reconstructed efficiency distributions if the prior indexing was inadvertently hiding misalignments. Comparisons with previous efficiency measurements should be validated.

  • Analysis Reproducibility: Results from analyses using prior HFTrackEfficiency output will differ slightly due to corrected indexing; historical results should not be directly compared without understanding this change.

Possible Future Improvements

  • Extend mother-level kinematic measurements to include mass and momentum reconstructed from daughter kinematics for cross-validation.
  • Add configurable options to write only a subset of branches to reduce output file sizes for high-multiplicity decays.
  • Consider adding invariant mass resolution studies using the expanded four-vector information now available.

Note: AI-assisted analysis was used to understand code changes. Code review best practices suggest manually verifying the index counter fix and testing with typical HFTrackEfficiency use cases to confirm the efficiency measurements are correct.

@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes enhance the HFTrackEfficiency module by adding azimuthal angle (phi) storage for mothers and daughter tracks, replacing a relative index offset (i - 1) with a dedicated sequential counter to correctly align array assignments with trackable particle filtering, and computing reconstructed mother pT from the four-vector when all daughters are found.

Changes

Cohort / File(s) Summary
Header Member Variables
offline/packages/HFTrackEfficiency/HFTrackEfficiency.h
Added m_reco_mother_pT, m_true_mother_phi, m_true_track_phi[m_maxTracks], and m_reco_track_phi[m_maxTracks] member variables, all initialized to quiet_NaN.
Implementation Logic and Data Handling
offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc
Introduced dedicated index counter for per-daughter array population in place of i - 1 offset; updated truth/reco kinematic and mapping bookkeeping to use index; added phi angle filling for mothers and tracks via new TTree branches; corrected daughter four-vector construction for invariant mass to use proper PID indexing; computed reconstructed mother pT from motherRecoLV.perp().

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d252e1d6-dfbd-4dde-8fa7-a07d00f0a80b

📥 Commits

Reviewing files that changed from the base of the PR and between 5f94b58 and 0743fbe.

📒 Files selected for processing (2)
  • offline/packages/HFTrackEfficiency/HFTrackEfficiency.cc
  • offline/packages/HFTrackEfficiency/HFTrackEfficiency.h

Comment on lines 393 to +401
if (m_dst_track->get_silicon_seed())
{
m_reco_track_silicon_seeds[i - 1] = static_cast<int>(m_dst_track->get_silicon_seed()->size_cluster_keys());
m_reco_track_silicon_seeds[index] = static_cast<int>(m_dst_track->get_silicon_seed()->size_cluster_keys());
}
else
{
m_reco_track_silicon_seeds[i - 1] = 0;
m_reco_track_silicon_seeds[index] = 0;
}
m_reco_track_tpc_seeds[i - 1] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());
m_min_reco_track_pT = std::min(m_reco_track_pT[i - 1], m_min_reco_track_pT);
m_max_reco_track_pT = std::max(m_reco_track_pT[i - 1], m_max_reco_track_pT);
m_reco_track_tpc_seeds[index] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check SvtxTrack interface for get_tpc_seed() return semantics and existing null-check patterns
rg -n -C3 'get_tpc_seed\(\)' --type=cpp

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 43826


Potential null pointer dereference: get_tpc_seed() not checked before use.

Lines 393–400 guard against a null get_silicon_seed(), but line 401 calls get_tpc_seed()->size_cluster_keys() unconditionally. If get_tpc_seed() returns nullptr, this will crash.

Proposed fix
         if (m_dst_track->get_silicon_seed())
         {
           m_reco_track_silicon_seeds[index] = static_cast<int>(m_dst_track->get_silicon_seed()->size_cluster_keys());
         }
         else
         {
           m_reco_track_silicon_seeds[index] = 0;
         }
-        m_reco_track_tpc_seeds[index] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());
+        if (m_dst_track->get_tpc_seed())
+        {
+          m_reco_track_tpc_seeds[index] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());
+        }
+        else
+        {
+          m_reco_track_tpc_seeds[index] = 0;
+        }
📝 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 (m_dst_track->get_silicon_seed())
{
m_reco_track_silicon_seeds[i - 1] = static_cast<int>(m_dst_track->get_silicon_seed()->size_cluster_keys());
m_reco_track_silicon_seeds[index] = static_cast<int>(m_dst_track->get_silicon_seed()->size_cluster_keys());
}
else
{
m_reco_track_silicon_seeds[i - 1] = 0;
m_reco_track_silicon_seeds[index] = 0;
}
m_reco_track_tpc_seeds[i - 1] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());
m_min_reco_track_pT = std::min(m_reco_track_pT[i - 1], m_min_reco_track_pT);
m_max_reco_track_pT = std::max(m_reco_track_pT[i - 1], m_max_reco_track_pT);
m_reco_track_tpc_seeds[index] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());
if (m_dst_track->get_silicon_seed())
{
m_reco_track_silicon_seeds[index] = static_cast<int>(m_dst_track->get_silicon_seed()->size_cluster_keys());
}
else
{
m_reco_track_silicon_seeds[index] = 0;
}
if (m_dst_track->get_tpc_seed())
{
m_reco_track_tpc_seeds[index] = static_cast<int>(m_dst_track->get_tpc_seed()->size_cluster_keys());
}
else
{
m_reco_track_tpc_seeds[index] = 0;
}

Comment on lines +497 to 499
m_reco_mother_pT = std::numeric_limits<float>::quiet_NaN();
m_true_mother_p = std::numeric_limits<float>::quiet_NaN();
m_true_mother_eta = std::numeric_limits<float>::quiet_NaN();

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

Missing reset of m_true_mother_phi — stale data may persist between decays.

m_reco_mother_pT is reset here (line 497), and m_true_mother_eta at line 499, but m_true_mother_phi (added in the header) is never reset. This means if one decay sets m_true_mother_phi and the next does not populate it, old values will be written to the TTree.

Proposed fix
   m_reco_mother_pT = std::numeric_limits<float>::quiet_NaN();
   m_true_mother_p = std::numeric_limits<float>::quiet_NaN();
   m_true_mother_eta = std::numeric_limits<float>::quiet_NaN();
+  m_true_mother_phi = std::numeric_limits<float>::quiet_NaN();
   m_min_true_track_pT = std::numeric_limits<float>::max();
📝 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
m_reco_mother_pT = std::numeric_limits<float>::quiet_NaN();
m_true_mother_p = std::numeric_limits<float>::quiet_NaN();
m_true_mother_eta = std::numeric_limits<float>::quiet_NaN();
m_reco_mother_pT = std::numeric_limits<float>::quiet_NaN();
m_true_mother_p = std::numeric_limits<float>::quiet_NaN();
m_true_mother_eta = std::numeric_limits<float>::quiet_NaN();
m_true_mother_phi = std::numeric_limits<float>::quiet_NaN();

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 0743fbe8eaac9118f69a777521e2e65237f42c78:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@osbornjd osbornjd merged commit a4380b3 into sPHENIX-Collaboration:master Mar 24, 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