Skip to content

Trying again!#4300

Open
Ishangoel11 wants to merge 1 commit into
sPHENIX-Collaboration:masterfrom
Ishangoel11:branch
Open

Trying again!#4300
Ishangoel11 wants to merge 1 commit into
sPHENIX-Collaboration:masterfrom
Ishangoel11:branch

Conversation

@Ishangoel11

@Ishangoel11 Ishangoel11 commented Jun 12, 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)

Motivation

This PR extends the TPC Debugger diagnostic output to capture additional cluster-formation details and event-level metadata. The goal is to enable deeper investigation of cluster properties and track-residual correlations by persisting new cluster reconstruction parameters and event identifiers to ROOT output trees.

Key Changes

Event-Level Tracking:

  • Added evt_id (event identifier) from EventHeader to TrackResiduals, with fallback to -1 when unavailable
  • New evt_id branch added to multiple output TTrees: eventtree, failedfits, vertextree, hittree, clustertree, and residualtree
  • Per-event refresh of m_runnumber and m_segment from recoConsts

Cluster Storage Expansion:

  • Replaced legacy m_clusAdc/m_clusMaxAdc vectors with detailed centroid and boundary tracking: m_clusCenAdc, m_clusPadCen, m_clusTBinCen, m_clusPadMax, m_clusTBinMax
  • Added cluster-size categorization (m_clussize) alongside existing phi/z size vectors
  • Introduced comprehensive edge tracking: separate counters for left/right sector edges (m_clussledge, m_clussredge), top/bottom time-bin edges (m_clustledge, m_clustredge), and dead/hot channel edges (dledge, dredge, hledge, hredge)
  • Added mixing/adjacency flags: m_clusslmix, m_clussrmix, m_clustlmix, m_clustrmix to identify clusters with signal in neighboring bins

Cluster Reconstruction Refactoring:

  • Introduced ClusterCounters struct in TpcClusterizer to systematize per-cluster metric tracking (overlap, sector/time edges, dead/hot edges, mixing flags)
  • New check_cluster_touching helper to detect adjacent bin adjacencies and set mixing flags dynamically
  • Updated calc_cluster_parameter to populate centroid ADC (via adc_map), size/bin/phase information, and edge-category flags during cluster construction
  • Switched cluster output format to TrkrClusterv6 (from v5), which provides new getter/setter methods for the expanded properties
  • Modified ProcessSectorData to carry ClusterCounters through stepdown retry logic and preserve original ADC snapshots for touching checks

NTuple Schema Updates:

  • Extended TrkrNtuplizer cluster schema with new fields: centroid ADC, pad/tbin cent/max, edge/mix metrics, overlap, bin ranges, phase information
  • Changed cluster size source from getSize() to getRSize()
  • Added explicit null-check for vertex entries before writing

Potential Risk Areas

IO Format Changes:

  • ROOT output file structure now includes evt_id branch and significantly expanded cluster variable vectors; existing analysis code expecting older schema will require updates
  • Migration from TrkrClusterv5 to TrkrClusterv6 is a breaking change; older reconstruction code reading v5-format files may fail

Reconstruction Behavior:

  • Cluster edge/touch accounting logic has been substantially refactored; clusters in data processed with this code will have different edge/mix flag assignments compared to prior reconstructions
  • The new check_cluster_touching and revised calc_cluster_parameter logic may subtly alter which hits are included/excluded in final clusters or marked as boundary hits

Performance:

  • Additional vector allocations and detail-tracking logic in cluster formation may have modest CPU/memory overhead, though likely negligible for typical event rates

Suggestions for Future Improvements

  • Consider backward-compatibility layer or migration utilities for existing analysis code reading v5-format cluster data
  • Add unit or integration tests validating the new cluster properties against known test cases
  • Document the physical meaning and use-cases for the new mixing/edge flags and centroid ADC in reconstruction documentation
  • Consider adding histogramming or validation plots to TpcClusterQA to cross-check new cluster parameters against expected distributions

Note: This summary is AI-generated and may contain inaccuracies. Please review the actual diff carefully to confirm all changes and their implications.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR expands TPC cluster metadata and refactors edge-detection accounting. It captures per-event IDs from EventHeader, extends cluster schema with centroid ADC and pad/tbin center/max values alongside edge/mix/phase categorization, updates the NTuple output columns accordingly, and replaces scalar touch/edge tracking in clustering with a structured ClusterCounters approach that distinguishes overlap, sector/time edges, dead/hot edges, and mixing flags.

Changes

Event ID & Cluster Attribute Schema

Layer / File(s) Summary
Event ID Infrastructure
offline/packages/TrackingDiagnostics/TrackResiduals.h, offline/packages/TrackingDiagnostics/TrackResiduals.cc
Adds m_evt_id member initialized to -1, reads event identifier from EventHeader with fallback, and creates evt_id branches across all six output TTrees (eventtree, failedfits, vertextree, hittree, clustertree, residualtree) with debug logging.
Cluster Field Schema Definition
offline/packages/TrackingDiagnostics/TrackResiduals.h
Replaces m_clusAdc and m_clusMaxAdc with five new vectors (m_clusCenAdc, m_clusPadCen, m_clusTBinCen, m_clusPadMax, m_clusTBinMax), adds scalar m_cluscenadc and edge/mix/phase member fields, and introduces vectors for cluster size, edge categories (sector/time/dead/hot), mixing flags, and bin/phase ranges.
Cluster State Clearing & Filling
offline/packages/TrackingDiagnostics/TrackResiduals.cc
clearClusterStateVectors() extends to zero all new cluster vectors; fillClusterTree() populates centroid ADC, pad/tbin center/max, phi/tbin bin ranges, pad/tbin phases, and edge/mix/overlap values from cluster objects; fillClusterBranchesKF() and fillClusterBranchesSeeds() accumulate the same fields into residual-tree vectors.
ROOT Cluster & Residual Tree Branches
offline/packages/TrackingDiagnostics/TrackResiduals.cc
createBranches() wires new vectors into ROOT branches: clustertree receives cluster-size, edge, mix, pad/tbin center/max, phi/tbin bin ranges, and phase fields; residualtree receives corresponding per-hit/per-cluster residual vectors for centroid ADC and all edge/mix/bin/phase attributes.

NTuple Schema & Cluster Filling

Layer / File(s) Summary
NTuple Enum & Variable List
offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
Extends n_cluster enum with new field identifiers for centroid ADC, pad/tbin cent/max, edge metrics (SL/SR/T/R and dead/hot), mixing parameters, overlap, phi/tbin bin ranges, and phase values; updates str_cluster TNtuple variable list to match the expanded column schema.
FillCluster & Vertex Processing Updates
offline/packages/TrackingDiagnostics/TrkrNtuplizer.cc
FillCluster() extracts centroid ADC and pad/tbin center/max using new cluster getters, changes size from getSize() to getRSize(), replaces prior edge/overlap outputs with expanded cluster method calls for all edge/mix/bin/phase fields; vertex filling loop adds null-check guard before accessing vertex data.

TPC Cluster Edge/Touching Accounting Refactor

Layer / File(s) Summary
ClusterCounters Infrastructure
offline/packages/tpc/TpcClusterizer.cc
Introduces ClusterCounters struct with overlap, nedge, and bit flags for sector/time/dead/hot edges and SL/SR/TL/TR mixing, includes clear() method for reset between clustering retries.
Refactored Range Finding with ClusterCounters
offline/packages/tpc/TpcClusterizer.cc
find_t_range() and find_phi_range() accept ClusterCounters and boolean edge-tracking outputs instead of scalar touch/edge integers; increment overlap, sector/time edge, and dead/hot edge counters during masked/edge-truncated scan regions.
Cluster Touching & Neighbor Detection
offline/packages/tpc/TpcClusterizer.cc
Adds check_cluster_touching() helper that builds coordinate lookup of current cluster hits and scans 8-connected neighbors to set mix flags (slmix/srmix/tlmix/trmix) when adjacent bins contain signal, avoiding double-counting.
Cluster Parameter & v6 Construction
offline/packages/tpc/TpcClusterizer.cc
Updates get_cluster() to use counts.overlap for hit eligibility; refactors calc_cluster_parameter() to accept ClusterCounters, track size and max-ADC bin positions, compute centroid ADC via adc_map keyed by integer bin coordinates, set edge-category flags for dead/hot channels, and construct TrkrClusterv6 with all extended per-edge/per-mix fields and bin/phase/centroid properties.
ProcessSectorData Integration
offline/packages/tpc/TpcClusterizer.cc
Updates ProcessSectorData to snapshot original ADC matrix (adcval_orig) before masking, carry ClusterCounters through fixed-window stepdown retries with counter reset, call check_cluster_touching() with pre-modified ADC, and pass ClusterCounters to calc_cluster_parameter().

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.

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

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)

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

ncluredge is left uninitialized for most layers

fx_cluster is stack-allocated in callers and not pre-zeroed per entry; in FillCluster, ncluredge is only set inside the specific-layer if (Line 2343-2348). For other layers, that field can carry indeterminate data into the NTuple row.

Initialize ncluredge before the conditional, then override to 1 for the listed layers.

Suggested fix
   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;
   }

Also applies to: 2349-2361


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f5cd96b7-4cc1-482b-a675-e64ce4d33174

📥 Commits

Reviewing files that changed from the base of the PR and between aab166c and bece3f0.

📒 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 +88 to +115
struct ClusterCounters
{
int overlap = 0;

int nedge = 0; // Total No. of Edges

int sledge = 0; // Touching Left Sector Edge
int sredge = 0; // Touching Right Sector Edge

int tledge = 0; // Touching Left Time Edge
int tredge = 0; // Touching Right Time Edge

int dledge = 0; // Touching Left Dead Edge
int dredge = 0; // Touching Right Dead Edge

int hledge = 0; // Touching Left Hot Edge
int hredge = 0; // Touching Right Hot Edge

int slmix = 0; // Touching Cluster at Left in Phibin
int srmix = 0; // Touching Cluster at Right in Phibin

int tlmix = 0; // Touching Cluster at Left in Timebin
int trmix = 0; // Touching Cluster at Right in Timebin

void clear()
{
*this = ClusterCounters{};
}

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 | 🏗️ Heavy lift

Preserve overlap direction instead of collapsing it into counts.overlap.

This refactor records only an aggregate overlap count, but remove_hit() still needs boundary-specific information to decide which bins stay USHRT_MAX. In get_cluster(), any overlap now marks all phi-edge hits and never marks time-edge hits. That breaks the overlap handoff deterministically: a cluster that only overlaps in time gets fully zeroed before the next seed is grown, while a phi-only overlap leaves extra USHRT_MAX stripes on rows that never touched the neighbor.

Also applies to: 210-315, 317-425, 574-580

Comment on lines 883 to 886
char tsize = tbinhi - tbinlo + 1;
char phisize = phibinhi - phibinlo + 1;
char rsize = size;
// std::cout << "phisize: " << (int) phisize << " phibinhi " << phibinhi << " phibinlo " << phibinlo << std::endl;

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 | 🏗️ Heavy lift

RSize can wrap for large clusters.

size is the total number of contributing bins, but it is narrowed to char before being stored. Any cluster above 127 cells will write a wrapped value into the new RSize field, and the stack context shows downstream code now consumes getRSize() for output. Please widen this storage path, or at minimum clamp explicitly before persisting it.

Also applies to: 926-928

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 | ⚡ Quick win

Do not overwrite configured run/segment metadata on every event.

These lines unconditionally replace m_runnumber and m_segment from recoConsts, which makes the existing configuration API (runnumber(), segment(), setSegment()) ineffective and can silently change the values written to every tree. Please only fall back to recoConsts when no explicit value was configured, or guard on flag existence before overwriting.

Comment on lines +707 to +719
m_cluscenadc = cluster->getCenAdc();
m_padcen = cluster->getPadCen();
m_tbincen = cluster->getTBinCen();
m_padmax = cluster->getPadMax();
m_tbinmax = cluster->getTBinMax();
m_scluslx = cluster->getLocalX();
m_scluslz = cluster->getLocalY();
m_phibinlo = cluster->getPhiBinLo();
m_phibinhi = cluster->getPhiBinHi();
m_tbinlo = cluster->getTBinLo();
m_tbinhi = cluster->getTBinHi();
m_padphase = cluster->getPadPhase();
m_tbinphase = cluster->getTBinPhase();

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

Guard the new pad/tbin/edge/mix fields to TPC clusters.

fillClusterTree, fillClusterBranchesKF, and fillClusterBranchesSeeds all run over MVTX/INTT/Micromegas clusters as well, but the newly added pad/tbin, phase/bin, and edge/mix quantities are TPC-cluster semantics. Writing them unconditionally will serialize backend/default values for non-TPC clusters into clustertree and residualtree, which makes those branches look like real measurements for detectors that do not have pad/tbin or TPC edge categories. Please gate these writes on TrkrDefs::tpcId or assign explicit N/A sentinels for the other detector types.

Also applies to: 724-737, 1158-1170, 1243-1257, 1511-1522, 1545-1559

std::string str_event = {"event:seed:run:seg:job"};
std::string str_hit = {"hitID:e:adc:layer:phielem:zelem:cellID:ecell:phibin:zbin:tbin:phi:r:x:y:z"};
std::string str_cluster = {"locx:locy:x:y:z:r:phi:eta:theta:phibin:tbin:fee:chan:sampa:ex:ey:ez:ephi:pez:pephi:e:adc:maxadc:thick:afac:bfac:dcal:layer:phielem:zelem:size:phisize:zsize:pedge:redge:ovlp:trackID:niter"};
std::string str_cluster = {"locx:locy:x:y:z:r:phi:eta:theta:phibin:tbin:fee:chan:sampa:ex:ey:ez:ephi:pez:pephi:e:adc:maxadc:cenadc:padcen:tbincen:padmax:tbinmax:thick:afac:bfac:dcal:layer:phielem:zelem:size:phisize:zsize:pedge:redge:sledge:sredge:tledge:tredge:dledge:dredge:hledge:hredge:slmix:srmix:tlmix:trmix:ovlp:phibinlo:phibinhi:tbinlo:tbinhi:padphase:tbinphase:trackID:niter"};

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 | 🏗️ Heavy lift

In-place TNtuple schema expansion can silently break downstream readers

Line 363 changes str_cluster column ordering for both ntp_cluster and ntp_clus_trk without a schema/version boundary. Any consumer decoding by position will silently misread legacy fields after maxadc.

Please add a compatibility plan in this PR (e.g., versioned tuple name/metadata, or explicit migration notes and coordinated downstream updates).

@Ishangoel11

Copy link
Copy Markdown
Contributor Author

Hi, I need help with this. I don't know why it shows so many errors/warnings from other macros?

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit bece3f0bd1612bda0d655d3066bcd8b5ab53b537:
Jenkins on fire


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.

1 participant