Skip to content

feat: implement v6 option in tpc clusterizer#4312

Merged
pinkenburg merged 13 commits into
sPHENIX-Collaboration:masterfrom
osbornjd:branch
Jun 24, 2026
Merged

feat: implement v6 option in tpc clusterizer#4312
pinkenburg merged 13 commits into
sPHENIX-Collaboration:masterfrom
osbornjd:branch

Conversation

@osbornjd

@osbornjd osbornjd commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This should implement @Ishangoel11 v6 cluster object and get all of the types consistent between the base class and derived class IO object.

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)

Motivation and Context

This PR introduces an optional v6 clustering mode in the TPC clusterizer to provide richer per-cluster characterization (edge/mixing/overlap) and to tighten type consistency between the TrkrCluster base interface and the v5/v6 derived cluster implementations. It also updates tracking diagnostics and cluster NTuples to serialize the new observables. Note: AI can make mistakes—please use best judgment and verify key API/IO impacts locally, with extra attention to the IO object refactoring/standardization mentioned by the author (independent verification that IO changes are correct and not unintentionally corrupted).

Key Changes

  • TPC clustering (v6 support + richer bookkeeping)

    • Added a ClusterCounters-based workflow to track cluster overlap, overall edge counts, detailed per-side edge categories, and phi/time “mix” touching indicators.
    • Implemented neighbor scanning (check_cluster_touching) across adjacent phi/time cells to populate mix indicators.
    • Updated cluster building (get_cluster, calc_cluster_parameter) to propagate ClusterCounters into the produced cluster object.
    • Added a DetailedClusterAnalysis()/m_debug debug path to select TrkrClusterv6 (otherwise TrkrClusterv5).
    • Extended ProcessSectorData to preserve original ADC data for neighbor checks and to reset/pipeline ClusterCounters appropriately.
  • Cluster object API/type contract alignment

    • TrkrCluster.h: const-correct setter parameters plus multiple public type contract changes (notably getPadMax/getTBinMax float→int, mix getters int→char, phi/tbin bin lo/hi float→unsigned short) and associated sentinel changes.
    • TrkrClusterv6.h: standardized signatures with override and aligned member types/defaults to the updated contracts.
    • Minor override/signature consistency updates in v4/v5 cluster classes (const/override correctness, no intended logic changes).
  • Tracking diagnostics + ROOT output extensions

    • TrackResiduals: read EventHeader, store m_evt_id, and write a new evt_id branch into multiple ROOT trees.
    • Added/expanded cluster state resets and extended cluster/edge/mix observable filling into existing output trees.
  • Cluster NTuple schema updates

    • TrkrNtuplizer: extended _ntp_cluster/n_cluster schema and filling to include new per-cluster ADC/bin/max/phase and edge/mixing-related fields.
    • Changed nclusize to use cluster->getRSize() instead of cluster->getSize().

Potential Risk Areas

  • IO / analysis compatibility
    • ROOT tree branch additions/renames (TrackResiduals) and TNtuple column/schema layout changes (TrkrNtuplizer) may require downstream analysis updates.
  • API/type contract changes
    • Public method return types and sentinels in TrkrCluster (and v6 alignment) can break downstream code or subtly change behavior if callers assumed float/NaN or other sentinel semantics.
  • Reconstruction behavior differences
    • When v6 mode is selected via the debug/detailed-analysis path, new neighbor/mix/edge logic may change cluster-derived observables versus v5.
  • Performance / resource use
    • Additional neighbor scans and more per-cluster serialized fields can increase compute and IO load in v6/detailed mode.
  • Thread-safety / state management
    • Ensure per-cluster/per-sector ClusterCounters resets and any new debug flag plumbing do not leak state across parallel execution contexts.

Possible Future Improvements

  • Add regression tests that compare representative v5 vs v6 outputs (especially boundary and bin/phase edge cases for mix/overlap/edge categories).
  • Provide a short migration note for downstream users about updated TrkrCluster contracts and updated ROOT/TNtuple schemas.
  • Profile v6 performance impact on large productions and consider configurability for neighbor/mix criteria (without code changes).

@coderabbitai

coderabbitai Bot commented Jun 22, 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: f005985d-242c-45d0-8fd1-0a7ae84fcc51

📥 Commits

Reviewing files that changed from the base of the PR and between edbd44e and 5e357d8.

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

📝 Walkthrough

Walkthrough

TrkrCluster/TrkrClusterv4/v5/v6 field types are narrowed (float → int/char/unsigned short) for pad/tbin max and bin indices, with const parameters and override specifiers standardized. TpcClusterizer gains a ClusterCounters struct, DetailedClusterAnalysis() debug mode, refactored range-finding functions, and check_cluster_touching helper; calc_cluster_parameter now emits TrkrClusterv6 with all new fields populated. TrackResiduals retrieves EventHeader for event ID, extends cluster vectors, fills them from updated TrkrCluster getters, and adds branches to all output trees. TrkrNtuplizer extends its NTuple schema and FillCluster to record all new observables.

Changes

TPC Cluster Detail Pipeline

Layer / File(s) Summary
Cluster interface type changes and conformance across v4/v5/v6
offline/packages/trackbase/TrkrCluster.h, offline/packages/trackbase/TrkrClusterv4.h, offline/packages/trackbase/TrkrClusterv4.cc, offline/packages/trackbase/TrkrClusterv5.h, offline/packages/trackbase/TrkrClusterv5.cc, offline/packages/trackbase/TrkrClusterv6.h
TrkrCluster.h changes getPadMax/getTBinMax from float to int, and getPhiBinLo/Hi/getTBinLo/Hi from float to unsigned short. All setter parameters updated to const and narrower types. TrkrClusterv4 and TrkrClusterv5 add missing override specifiers and const parameters. TrkrClusterv6 harmonizes all method signatures with the new API, updates private members (m_padmax/m_tbinmax to int, edge/mix to char, bin fields to unsigned short), and normalizes const qualification.
TpcClusterizer: ClusterCounters struct and clustering pipeline
offline/packages/tpc/TpcClusterizer.h, offline/packages/tpc/TpcClusterizer.cc
Introduces ClusterCounters (overlap, nedge, per-side dead/hot edges, phi/time mix). Adds DetailedClusterAnalysis()/m_debug to enable TrkrClusterv6 output. Refactors find_t_range/find_phi_range to accumulate into ClusterCounters. Adds check_cluster_touching for mix-flag detection. calc_cluster_parameter now computes cen_adc, rsize, selects TrkrClusterv6 when debug is set, and populates all new fields. ProcessSectorData preserves adcval_orig, instantiates counts per cluster, calls check_cluster_touching, and threads the full pipeline.
TrackResiduals and TrkrNtuplizer: branches, columns, and cluster data output
offline/packages/TrackingDiagnostics/TrackResiduals.h, offline/packages/TrackingDiagnostics/TrackResiduals.cc, offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
TrackResiduals adds m_evt_id, extends scalar/vector declarations for center ADC, pad/tbin centers/maxes, edge breakdown, mix terms, and bin/phase ranges. Retrieves EventHeader in process_event, extends clearClusterStateVectors, fills all new observables in cluster-filling methods, and registers branches on all six output trees. TrkrNtuplizer extends n_cluster enum and str_cluster TNtuple column list, populates all new fields in FillCluster from updated TrkrCluster getters, and switches nclusize to getRSize().

Possibly related PRs

  • sPHENIX-Collaboration/coresoftware#4291: Introduced the extended TrkrCluster/TrkrClusterv6 API (center ADC, edge/mix setters, bin/phase fields) that this PR's clusterizer and diagnostic code directly depends on.

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.

@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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 236e322b-ac8a-4011-b00a-cfc0a3e43a9c

📥 Commits

Reviewing files that changed from the base of the PR and between bf0556b and 2f80ad0.

📒 Files selected for processing (7)
  • offline/packages/TrackingDiagnostics/TrackResiduals.cc
  • offline/packages/TrackingDiagnostics/TrackResiduals.h
  • offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
  • offline/packages/tpc/TpcClusterizer.cc
  • offline/packages/tpc/TpcClusterizer.h
  • offline/packages/trackbase/TrkrCluster.h
  • offline/packages/trackbase/TrkrClusterv6.h


char tsize = tbinhi - tbinlo + 1;
char phisize = phibinhi - phibinlo + 1;
char rsize = size;

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

Potential truncation: cluster size stored in char.

size is an int counting hits in the cluster (incremented at line 673), but rsize is char (line 886). If a cluster has more than 127 hits (or 255 for unsigned char), the value will wrap around silently.

Large clusters from overlapping tracks or noise could exceed this limit. Consider either clamping to CHAR_MAX or using a wider type.

Suggested fix
-    char rsize = size;
+    char rsize = (size > std::numeric_limits<char>::max()) 
+                 ? std::numeric_limits<char>::max() 
+                 : static_cast<char>(size);

Or add a sanity check if this should never happen:

+    if (size > std::numeric_limits<char>::max()) {
+      std::cout << PHWHERE << "Warning: cluster size " << size << " exceeds char range" << std::endl;
+    }
     char rsize = static_cast<char>(size);
📝 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
char rsize = size;
char rsize = (size > std::numeric_limits<char>::max())
? std::numeric_limits<char>::max()
: static_cast<char>(size);

Comment thread offline/packages/tpc/TpcClusterizer.cc
Comment thread offline/packages/trackbase/TrkrCluster.h Outdated
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 2f80ad06ca0c895de1b979afb7383509f0a45c86:
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 dc21c7e51b1b7f0996ee8e7771e653fe6ebf18f5:
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 3854e03585d80e1ead504ce61dab0f602ce0414d:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@osbornjd osbornjd requested a review from pinkenburg June 23, 2026 12:59
@osbornjd

Copy link
Copy Markdown
Contributor Author

@pinkenburg can you give an extra set of eyes on the IO objects and make sure I haven't inadvertently mangled something, I tried cleaning them up and making them consistent

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4ce901d2-f83a-4f4b-a4b5-2295a91e6f51

📥 Commits

Reviewing files that changed from the base of the PR and between 2f80ad0 and edbd44e.

📒 Files selected for processing (9)
  • offline/packages/TrackingDiagnostics/TrackResiduals.cc
  • offline/packages/TrackingDiagnostics/TrackResiduals.h
  • offline/packages/tpc/TpcClusterizer.cc
  • offline/packages/trackbase/TrkrCluster.h
  • offline/packages/trackbase/TrkrClusterv4.cc
  • offline/packages/trackbase/TrkrClusterv4.h
  • offline/packages/trackbase/TrkrClusterv5.cc
  • offline/packages/trackbase/TrkrClusterv5.h
  • offline/packages/trackbase/TrkrClusterv6.h
✅ Files skipped from review due to trivial changes (3)
  • offline/packages/trackbase/TrkrClusterv4.cc
  • offline/packages/trackbase/TrkrClusterv5.cc
  • offline/packages/trackbase/TrkrClusterv4.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • offline/packages/TrackingDiagnostics/TrackResiduals.h
  • offline/packages/TrackingDiagnostics/TrackResiduals.cc
  • offline/packages/tpc/TpcClusterizer.cc

Comment thread offline/packages/trackbase/TrkrClusterv6.h Outdated
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit edbd44ed868c831eab405b8b50eb035b12584262:
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 497ed8d0f58826246b9e3dacc60fa7ad21685af9:
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 5e357d834043708cef8cb208b237e2d563b49b0a:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io


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.

The segment is really meaningless. It doesn't go back to the rawdata (so it won't help locating the event) but is just a feature of the filename depending on how many events we store in a file which is subject to change.

@pinkenburg pinkenburg merged commit cebff85 into sPHENIX-Collaboration:master Jun 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