Skip to content

Update TrkrNtuplizer: refine ntuple filling and fix variable handling#4252

Open
Mughal789 wants to merge 2 commits intosPHENIX-Collaboration:masterfrom
Mughal789:trkrntuplizer_update
Open

Update TrkrNtuplizer: refine ntuple filling and fix variable handling#4252
Mughal789 wants to merge 2 commits intosPHENIX-Collaboration:masterfrom
Mughal789:trkrntuplizer_update

Conversation

@Mughal789
Copy link
Copy Markdown
Contributor

@Mughal789 Mughal789 commented Apr 20, 2026

comment: <> Fixed NaN placeholders for vertex variables

Types of changes

  • [x ] 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

TODOs (if applicable)

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

PR Summary: TrkrNtuplizer — refine vertex ntuple filling and fix variable handling

Motivation / context

  • Vertex ntuple output previously produced a single per-event entry filled with NaN placeholders for vertex observables, making vertex ntuples unusable for downstream analysis. This PR restores correct retrieval of reconstructed vertices and writes one ntuple entry per vertex so analyses receive actual vertex parameters.

Key changes

  • Replace placeholder single-entry vertex fill with per-vertex filling from SvtxVertexMapActs.
  • Retrieve SvtxVertexMap from node "SvtxVertexMapActs"; emit a warning and write zero vertex entries if the node is missing.
  • For each non-null SvtxVertex: reset vertex buffer to quiet_NaN(), populate vertexID, vx/vy/vz, ntracks (size_tracks), chisq and ndof, then fill the NTuple once per vertex.
  • Keep event/vertex/info buffers combined into the vertex ntuple row; allocate/deallocate vertex_data per vertex.
  • Add verbose debugging output (Verbosity()>1) showing populated vertex parameters.
  • Minor control/timing adjustments around the vertex processing block.

Potential risk areas

  • Ntuple format/semantics: downstream analysis expecting one vertex row per event (possibly NaN when absent) must be updated to handle zero or multiple vertex entries per event.
  • Event counting and normalization: events with no reconstructed vertices now produce zero rows (previously one NaN row), which can change normalization or event-based bookkeeping.
  • Data volume and performance: writing one entry per vertex increases ntuple size and CPU cost; impact depends on typical vertex multiplicities.
  • Thread-safety: no explicit thread-safety changes were introduced, but per-event per-vertex heap allocation/deallocation in a multi-threaded environment should be reviewed.
  • Backward compatibility: existing analysis scripts and ntuple consumers may need schema/expectation updates.

Possible future improvements

  • Add configurable vertex selection (e.g., minimum track count, quality cuts) before ntuple filling to reduce volume and improve analysis relevance.
  • Reuse or pre-allocate vertex_data buffer to avoid per-vertex heap allocations and reduce overhead.
  • Add validation checks (reasonable vertex position ranges, chi2/ndof sanity checks) and unit tests covering the absent-node and multi-vertex cases.
  • Document the ntuple schema change in collaboration analysis notes and update downstream scripts.

Caveat

  • This summary was generated with AI assistance. AI can make mistakes; please verify the code changes and their impacts against the actual diffs and run tests where appropriate.

Copilot AI review requested due to automatic review settings April 20, 2026 18:10
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 498e9bb3-87bb-402d-b39c-a0ba6a182a09

📥 Commits

Reviewing files that changed from the base of the PR and between d1507d2 and 6ffe19a.

📒 Files selected for processing (1)
  • offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc

📝 Walkthrough

Walkthrough

Vertex NTuple filling in TrkrNtuplizer was changed to fetch SvtxVertexMapActs from the node tree, warn and skip when missing, iterate per-vertex (initializing fields to NaN, populating id/position/track-count/chi2/ndof), and call _ntp_vertex->Fill() once per vertex with timing and verbose logging around the block.

Changes

Cohort / File(s) Summary
Vertex NTuple Filling Refactor
offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
Replaced single-fill path with defensive findNode::getClass<SvtxVertexMap>("SvtxVertexMapActs") retrieval. If missing, emit warning and skip. If present, iterate vertices, reset fx_vertex to quiet_NaN(), populate per-vertex fields (id,x,y,z,ntracks,chisq,ndof), assemble vertex_data from fx_event+fx_vertex+fx_info, and call _ntp_vertex->Fill() per vertex. Retained timer/verbosity handling and per-vertex debug prints.
sequenceDiagram
    participant Trkr as TrkrNtuplizer
    participant Top as topNode
    participant Map as SvtxVertexMapActs
    participant Ntp as _ntp_vertex

    Trkr->>Top: findNode::getClass<SvtxVertexMap>("SvtxVertexMapActs")
    alt vertex map missing
        Top-->>Trkr: nullptr
        Trkr->>Trkr: emit warning, skip vertex fills
    else vertex map present
        Top-->>Trkr: SvtxVertexMap*
        Trkr->>Trkr: start timer (if verbose)
        Trkr->>Map: iterate vertices
        loop per vertex
            Trkr->>Trkr: init fx_vertex to quiet_NaN()
            Trkr->>Trkr: populate id, vx/vy/vz, ntracks, chi2, ndof
            Trkr->>Ntp: assemble vertex_data (fx_event+fx_vertex+fx_info)
            Trkr->>Ntp: _ntp_vertex->Fill(vertex_data)
        end
        Trkr->>Trkr: stop timer (if verbose) and log vertex time
    end
Loading

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refines TrkrNtuplizer vertex ntuple filling to populate real vertex quantities from SvtxVertexMapActs (instead of writing placeholder NaNs) and includes additional vertex fields.

Changes:

  • Replaces placeholder-only vertex ntuple filling with per-vertex filling from SvtxVertexMapActs.
  • Initializes vertex ntuple fields to quiet_NaN() and fills vertexID, position, track count, chi2, and ndof.
  • Adds a warning when SvtxVertexMapActs is missing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1391 to +1431
@@ -1402,11 +1402,8 @@ void TrkrNtuplizer::fillOutputNtuples(PHCompositeNode* topNode)
{
i = 0;
}

// SvtxVertexMap* vertexmap = nullptr;

// vertexmap = findNode::getClass<SvtxVertexMap>(topNode, "SvtxVertexMapActs"); // Acts vertices

float vx = std::numeric_limits<float>::quiet_NaN();
float vy = std::numeric_limits<float>::quiet_NaN();
float vz = std::numeric_limits<float>::quiet_NaN();
@@ -1425,12 +1422,83 @@ void TrkrNtuplizer::fillOutputNtuples(PHCompositeNode* topNode)
std::copy(fx_info, fx_info + ((int) (n_info::infosize)), vertex_data + n_event::evsize + n_vertex::vtxsize);
_ntp_vertex->Fill(vertex_data);
delete[] vertex_data;

}
if (Verbosity() > 1)
{
_timer->stop();
std::cout << "vertex time: " << _timer->get_accumulated_time() / 1000. << " sec" << std::endl;
}*/
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The previous vertex-ntuple implementation is kept as a large commented-out block. This makes the function harder to read/maintain and risks it becoming stale. Please remove the dead commented code (it’s already replaced by the new implementation); use version control history if it needs to be referenced later.

Copilot uses AI. Check for mistakes.
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.

I would agree, we should just remove the old version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks Joe, I removed the older version and made a PR again.

Comment on lines +1434 to +1435
// Fix Nan placeholders for vertex variables
// //-----------------------
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The header comment has a couple of issues: "Nan" should be the standard "NaN", and the separator line below is double-commented (// //-----------------------). Please fix the comment text/formatting to match the surrounding section headers.

Suggested change
// Fix Nan placeholders for vertex variables
// //-----------------------
// Fix NaN placeholders for vertex variables
//-----------------------

Copilot uses AI. Check for mistakes.

if (!vertexmap)
{
std::cout << PHWHERE << " WARNING: SvtxVertexMapActs not found. Writing no vertex entries for this event." << std::endl;
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This warning is printed unconditionally when the node is missing, which can spam logs on jobs/configurations that don’t produce Acts vertices. Consider gating it behind a verbosity level (or emitting it once per run) so production output isn’t flooded.

Suggested change
std::cout << PHWHERE << " WARNING: SvtxVertexMapActs not found. Writing no vertex entries for this event." << std::endl;
static bool s_vertexmap_missing_warning_printed = false;
if (!s_vertexmap_missing_warning_printed)
{
std::cout << PHWHERE << " WARNING: SvtxVertexMapActs not found. Writing no vertex entries for this event." << std::endl;
s_vertexmap_missing_warning_printed = true;
}

Copilot uses AI. Check for mistakes.
Comment on lines +1484 to +1488
float* vertex_data = new float[((int) (n_info::infosize)) + n_event::evsize + n_vertex::vtxsize];
std::copy(fx_event, fx_event + n_event::evsize, vertex_data);
std::copy(fx_vertex, fx_vertex + n_vertex::vtxsize, vertex_data + n_event::evsize);
std::copy(fx_info, fx_info + ((int) (n_info::infosize)), vertex_data + n_event::evsize + n_vertex::vtxsize);

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

vertex_data is heap-allocated and freed for every vertex. This adds avoidable per-vertex overhead; you can allocate the buffer once outside the vertex loop and reuse it (or use a fixed-size stack buffer / std::array) since the size is known from the enum constants.

Copilot uses AI. Check for mistakes.
@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit 5cd077d06bf21763bd08706b904e099861f2a5a8:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@Mughal789 Mughal789 force-pushed the trkrntuplizer_update branch from 5cd077d to d1507d2 Compare April 20, 2026 23:23
@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit d1507d23a3a30c46251e7c5d668120b02eddaf0e:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit 6ffe19a5f9f80ab03a7e0ad8c39458a60ecf6b67:
Jenkins passed


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.

3 participants