Skip to content

Filling the newly added variables and saving them. As well as printing them.#4296

Closed
Ishangoel11 wants to merge 3 commits into
sPHENIX-Collaboration:masterfrom
Ishangoel11:branch
Closed

Filling the newly added variables and saving them. As well as printing them.#4296
Ishangoel11 wants to merge 3 commits into
sPHENIX-Collaboration:masterfrom
Ishangoel11:branch

Conversation

@Ishangoel11

@Ishangoel11 Ishangoel11 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

them.

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

This pull request enhances tracking diagnostics and TPC cluster characterization by adding explicit event identification, expanding per-cluster diagnostic metrics, and introducing cluster mixing/overlap detection during TPC clustering.

Motivation / context

Better event correlation and richer cluster diagnostics are needed to analyze reconstruction behavior, identify clustering artifacts (overlap/mixing, edge effects, ADC/centroid behavior), and improve downstream validation and physics-quality studies.

Key changes

  • Event identification

    • Add event sequence ID (evt_id, default -1 if EventHeader absent) to multiple ROOT outputs: eventtree, failedfits, vertextree, hittree, clustertree, residualtree.
    • Switch run/segment sourcing from Fun4AllServer to recoConsts (RUNNUMBER, RUNSEGMENT).
  • Cluster-finding and counters (TPC)

    • Introduce ClusterCounters to accumulate overlap, edge counts, dead/hot-edge counts, and mixing flags (slmix/srmix/tlmix/trmix).
    • Refactor find_t_range and find_phi_range to populate ClusterCounters.
    • Add check_cluster_touching() to detect neighboring-cluster mixing (±1 phi/time bins).
    • Use ClusterCounters throughout cluster construction and parameter calculation; compute centroid ADC from (iphi,it) -> adc map and derive rsize from hit set.
  • Output schema and diagnostics

    • Expand NTuple/tree schemas (TrkrNtuplizer, TrackResiduals) with many new per-cluster fields: centroid ADC, center/max pad and time-bin indices, pad/tbin centroids and maxima, pad/tbin phase ranges, detailed edge splits (S/T/D/H left/right), overlap/mixing indicators, and cluster size (rsize).
    • Create/clear/fill new vectors and branches in clustertree and residualtree for these diagnostics (new branches added; existing branches retained where applicable).

Potential risk areas

  • IO format changes: ROOT TTrees and NTuple layouts are extended; analysis code expecting previous branch/column layouts may break or misinterpret columns. Consumers must handle new branches and verify column ordering where NTuple-style layouts changed.
  • Reconstruction behavior: The new ClusterCounters and check_cluster_touching() logic can change hit-to-cluster grouping and computed cluster properties versus the prior implementation; this may affect downstream reconstruction results and physics quantities.
  • Data structure compatibility: Use of extended cluster metadata (TrkrClusterv6-like setters/getters reflected in code) and switch from getSize() to getRSize() can be incompatible with older consumers expecting previous cluster APIs.
  • Performance: Additional neighbor scans (check_cluster_touching) and per-cluster counters add CPU work; high-occupancy events may see a measurable performance impact.
  • Configuration dependency: Relying on recoConsts RUNNUMBER/RUNSEGMENT requires correct recoConsts configuration; behavior differs from using Fun4AllServer defaults.
  • Thread-safety: Increased mutable state and new per-seed counters require review for concurrent execution contexts (no explicit thread-safety guarantees added).

Possible future improvements

  • Add a migration/compatibility note and update analysis macros documenting new tree/NTuple schemas and the cluster size API change.
  • Provide unit/integration validation comparing cluster-level quantities and physics observables before/after the changes.
  • Benchmark and optimize check_cluster_touching() for high-occupancy scenarios; consider early exits or spatial indexing to reduce cost.
  • Add configurable switches to enable/disable mixing detection or fine-grained diagnostics to control performance and output size.
  • Extend documentation describing the physical meaning of new diagnostics and recommended analysis usage.

Note: This summary was AI-assisted. Please validate against the code changes directly—AI can make mistakes or omit subtle details.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: ece81b33-7185-456f-b98f-34df2ae7e5d9

📥 Commits

Reviewing files that changed from the base of the PR and between 28ad3fb and 3e44733.

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

📝 Walkthrough

Walkthrough

Adds evt_id sourcing and recoConsts-run/segment, expands cluster diagnostics across TrackResiduals and TrkrNtuplizer, and refactors TPC cluster finding to use ClusterCounters to record overlap/edge/mix and populate TrkrClusterv6 metadata.

Changes

TPC Cluster Diagnostics Expansion

Layer / File(s) Summary
EventID includes and header changes
offline/packages/TrackingDiagnostics/TrackResiduals.cc, offline/packages/TrackingDiagnostics/TrackResiduals.h
Add EventHeader/recoConsts includes and m_evt_id member; source evt_id and run/segment from EventHeader/recoConsts.
TrackResiduals state: members and clearing
offline/packages/TrackingDiagnostics/TrackResiduals.h, offline/packages/TrackingDiagnostics/TrackResiduals.cc
Expand private cluster diagnostic members (centroid/pad/tbin/max, edge/mix, phase) and extend clearClusterStateVectors() to reset new vectors including m_clussize.
ROOT tree branches: evt_id and new cluster branches
offline/packages/TrackingDiagnostics/TrackResiduals.cc
Add evt_id branch to all trees and extend clustertree/residualtree with cluster size, center/max ADC, pad/T-bin centers/max, phi/tbin lo/hi, pad/tbin phases, overlap/edge splits, and mix flags.
TrackResiduals: cluster filling and per-path vectors
offline/packages/TrackingDiagnostics/TrackResiduals.cc
Populate expanded per-cluster vectors in fillClusterTree, fillClusterBranchesKF, and fillClusterBranchesSeeds (edge/mix, ADC center/max, pad/tbin metrics, bin/phase, size).
TrkrNtuplizer: cluster NTuple schema update
offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
Extend n_cluster enum and str_cluster TNtuple definition to include new center/max ADC, pad/T-bin, edge, mix, overlap, phi/tbin range, and phase columns.
TrkrNtuplizer: FillCluster assignments
offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
Fill new NTuple columns using TrkrCluster getters (getCenAdc, getPadCen, getTBinCen, getPadMax, getTBinMax); switch to getRSize() and populate edge/mix/overlap and phase fields.
TPC: ClusterCounters struct and helper refactor
offline/packages/tpc/TpcClusterizer.cc
Introduce ClusterCounters; refactor find_t_range/find_phi_range to update counters and use boolean edge flags; add check_cluster_touching to detect mixing.
TPC: get_cluster, calc_cluster_parameter, ProcessSectorData wiring
offline/packages/tpc/TpcClusterizer.cc
Gate hit collection on counts.overlap, change calc_cluster_parameter to accept ClusterCounters, build adc map for centroid ADC, compute rsize, update dead/hot edge handling, populate TrkrClusterv6 overlap/edge/mix fields, and wire counters through ProcessSectorData including ADC snapshot and FixedWindow re-clustering resets.

Possibly Related PRs

  • sPHENIX-Collaboration/coresoftware#4291: The main PR’s new residual/cluster diagnostics and NTuple branches (e.g., clussize via getRSize() plus edge/mixing/bin/phase observables) directly depend on the retrieved PR’s added TrkrCluster/TrkrClusterv6 getters that expose those fields.
  • sPHENIX-Collaboration/coresoftware#4135: Both PRs modify offline/packages/TrackingDiagnostics/TrackResiduals.cc to extend ROOT clustertree branch creation; overlaps in branch/schema changes.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc (1)

2339-2348: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Initialize ncluredge before the boundary-layer check to avoid stale NTuple values.

At Line 2343, ncluredge is only written for a subset of layers. Since callers pass non-zero-initialized stack buffers into FillCluster, non-matching layers can carry stale values into the redge column.

Suggested fix
   fXcluster[n_cluster::nclusize] = cluster->getRSize();
   fXcluster[n_cluster::ncluphisize] = cluster->getPhiSize();
   fXcluster[n_cluster::ncluzsize] = cluster->getZSize();
   fXcluster[n_cluster::nclupedge] = cluster->getEdge();
+  fXcluster[n_cluster::ncluredge] = 0;
   if (layer_local == 7 || layer_local == 22 ||
       layer_local == 23 || layer_local == 28 ||
       layer_local == 39 || layer_local == 54)
   {
     fXcluster[n_cluster::ncluredge] = 1;
   }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 78b00e0a-6b92-4663-aacf-5cff722a7333

📥 Commits

Reviewing files that changed from the base of the PR and between 166a9a5 and 7fa7f9f.

📒 Files selected for processing (4)
  • offline/packages/TrackingDiagnostics/TrackResiduals.cc
  • offline/packages/TrackingDiagnostics/TrackResiduals.h
  • offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
  • offline/packages/tpc/TpcClusterizer.cc

Comment on lines +342 to +344
auto *rcs = recoConsts::instance();
m_runnumber = rcs->get_IntFlag("RUNNUMBER");
m_segment = rcs->get_IntFlag("RUNSEGMENT");

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== recoConsts API =="
fd -i 'recoConsts*' . | xargs -r rg -n -C2 'class recoConsts|get_IntFlag|FlagExist'

echo
echo "== RUNNUMBER/RUNSEGMENT producers and consumers =="
rg -n -C2 'RUNNUMBER|RUNSEGMENT|get_IntFlag\("RUNNUMBER"|get_IntFlag\("RUNSEGMENT"|FlagExist\("RUNNUMBER"|FlagExist\("RUNSEGMENT"' .

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 15207


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Search for RUNSEGMENT in codebase =="
rg -n "RUNSEGMENT" .

echo
echo "== Inspect TrackResiduals::process_event() region =="
sed -n '300,380p' offline/packages/TrackingDiagnostics/TrackResiduals.cc

echo
echo "== Inspect recoConsts / PHFlag get_IntFlag behavior =="
sed -n '1,200p' offline/framework/phool/recoConsts.h
# PHFlag.h might hold the actual flag-getter implementation/contract
sed -n '1,220p' offline/framework/phool/PHFlag.h 2>/dev/null || true

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 5350


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Search for RUNSEGMENT producers (set_IntFlag) =="
rg -n 'set_IntFlag\("RUNSEGMENT"|FlagExist\("RUNSEGMENT"|get_IntFlag\("RUNSEGMENT"|RUNSEGMENT' .

echo
echo "== Search for PHFlag::get_IntFlag implementation =="
fd -i '*PHFlag*' offline/framework/phool | head -n 50
rg -n "get_IntFlag\\(const std::string &name\\)" offline/framework/phool -S || true
rg -n "get_IntFlag\\(const std::string &name, const int defaultval\\)" offline/framework/phool -S || true

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 596


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Locate PHFlag source files =="
fd -i "PHFlag" offline/framework/phool | head -n 50

echo
echo "== Find PHFlag::get_IntFlag implementations =="
rg -n "PHFlag::get_IntFlag" offline/framework/phool

echo
echo "== Search for RUNSEGMENT usage patterns (all forms) =="
rg -n 'set_IntFlag\("RUNSEGMENT"|FlagExist\("RUNSEGMENT"|get_IntFlag\("RUNSEGMENT"' .
rg -n 'get_IntFlag\("RUNSEGMENT"\s*,\s*' . || true

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 585


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '70,160p' offline/framework/phool/PHFlag.cc

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 2465


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== TrackResiduals.cc uses of m_segment =="
rg -n "m_segment" offline/packages/TrackingDiagnostics/TrackResiduals.cc

echo
echo "== TrackResiduals.cc uses of m_runnumber =="
rg -n "m_runnumber" offline/packages/TrackingDiagnostics/TrackResiduals.cc

echo
echo "== Inspect surrounding code near first m_segment usage (if any) =="
rg -n -C 2 "m_segment" offline/packages/TrackingDiagnostics/TrackResiduals.cc | head -n 80

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 3316


Ensure RUNSEGMENT is set before TrackResiduals::process_event() fills the TTree branches

  auto *rcs = recoConsts::instance();
  m_runnumber = rcs->get_IntFlag("RUNNUMBER");
  m_segment = rcs->get_IntFlag("RUNSEGMENT");

TrackResiduals::process_event() calls PHFlag::get_IntFlag("RUNSEGMENT") unconditionally; when the flag is missing, PHFlag::get_IntFlag prints an error + stack trace and returns 0, and that 0 is then written into the "segment" branches for every event. Since "RUNSEGMENT" is not set/checked anywhere else in the codebase (only read here), add a FlagExist("RUNSEGMENT") guard (or use the default overload) or ensure the flag is produced upstream.

Comment thread offline/packages/TrackingDiagnostics/TrackResiduals.cc Outdated

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
offline/packages/tpc/TpcClusterizer.cc (2)

214-234: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

FixedWindow mode is effectively disabled here.

Lines 214-341 no longer apply my_data.FixedWindow during range growth, so the first get_cluster(...) call at Line 1279 always runs the step-down algorithm. The fallback block at Lines 1281-1319 then just reruns step-down on the same seed, which changes clustering behavior for any job that enables fixed-window mode.

As per coding guidelines, **/*.{cc,cpp,cxx,c} reviews should prioritize correctness, memory safety, error handling, and thread-safety.

Also applies to: 321-341, 1281-1319

Source: Coding guidelines


647-648: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

TrainingHits::nedge is saved before the dead/hot edge accounting is finalized.

training_hits->nedge is copied from counts.nedge at Lines 647-648, but Lines 754-802 can still increment counts.nedge for masked dead/hot neighbors before the final TrkrClusterv6 metadata is written. That makes the saved training record disagree with the persisted cluster metadata whenever these masks fire.

Suggested fix
-      training_hits->ntouch = counts.overlap;
-      training_hits->nedge = counts.nedge;
       training_hits->v_adc.fill(0);
@@
     if (my_data.maskHot)
     {
       auto it = my_data.hotMap->find(tpcHitSetKey);
@@
       }
     }
+
+    if (gen_hits && training_hits)
+    {
+      training_hits->ntouch = counts.overlap;
+      training_hits->nedge = counts.nedge;
+    }

As per coding guidelines, **/*.{cc,cpp,cxx,c} reviews should prioritize correctness, memory safety, error handling, and thread-safety.

Also applies to: 754-802

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9f5cfe53-3830-4d72-a3bf-ba0b7a02a59e

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa7f9f and 28ad3fb.

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

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 7fa7f9f1d73c83764129124ffce9a4f369ef7aae:
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 28ad3fb72dea49e025a610db1ee28609745c3778:
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 3e4473304b5b87d9493672577ff41fb3c8a31a25:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@Ishangoel11 Ishangoel11 deleted the branch branch June 12, 2026 14:21
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