Skip to content

Poly seed taubin - #4503

Merged
osbornjd merged 2 commits into
sPHENIX-Collaboration:masterfrom
mcyoren:poly-seed-taubin
Oct 28, 2026
Merged

osbornjd merged 2 commits into
sPHENIX-Collaboration:masterfrom
mcyoren:poly-seed-taubin

Conversation

@mcyoren

@mcyoren mcyoren commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Taubin circle fit, seed circle center, common crossing period, residual frame, optional PHGarfield maps

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, feature, ...)

Several improvments to polyseeding workflow:

  1. Taubin circle fit (Tpc_FittingTools.cc). The poly track fit used a simple algebraic circle fit. On short arcs it gives a too small radius, so the seed phi gets a bias and pT is underestimated. Now we use TrackFitUtils::circle_fit_by_taubin, the same fit as the CAseeding.
  2. Seed circle center (TpcPolyTrackSeedConverter.cc). The circle center X0/Y0 of the converted TrackSeed was mirrored across the track (wrong sign). Now we take the center from the poly fit. Could affect only some specific QA.
  3. Crossing period (4 headers). The poly modules used 106.56 ns per crossing, while Acts uses sphenix_constants::time_between_crossings = 106.652 ns. The converter adds the crossing back with one value and the fitter removes it with the other, so cluster z was off by about 7 um per crossing (2-3 mm for large crossings). Now all poly modules use the sphenix constant.
  4. Polyseed Specific Residuals (Tpc_PolyClusterResiduals.cc). The tracks are fitted in the world frame, but the residuals used cluster positions in the TPC envelope frame. This gave a ~2 mm offset (two bands in r-phi). Now both are in the world frame. PS: it is not full track residuals module change, but polytracks only module.
  5. Optional PHGarfield maps (PHGarfield.cc). If the space-charge or frame-charge scale is set to 0 on both sides (non-distorted MC flag), these maps are never used. A missing CDB payload is now not an error for them, so non-distorted MC also runs with tags that do not have the maps (e.g. MDC2).

Test: run 79513, 200 jobs x 1000 events, new build vs new + this branch, same macro, check resudialtree.

  • Matched tracks: pT ratio branch/release goes from 0.99 at low pT to 1.01-1.02 above 1.5 GeV. This is expected: the old fit gave too low pT, so tracks move to higher pT. Will partially solve mom-scale issue. The other part is eloss and it still will be there.
  • TPC-only tracks: the effect is much bigger, because pT comes only from the TPC fit. The ratio goes from 0.97 at low pT to about 1.1 at 1 GeV and like 2 at 3 GeV. Was not an issue in TPC only tests as those use refit before KF. But it was a porblem for TPC only analysis on final produced tracks.

TODOs (if applicable)

None

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

None

Motivation

The PR addresses polyseeding fit and coordinate issues that can bias reconstructed seed parameters and residuals. It also aligns crossing-time handling with the shared sPHENIX constant and allows unused Garfield map payloads to be absent when their scales are zero.

Key changes

  • Replace the local algebraic circle fit in Tpc_FittingTools::fit with TrackFitUtils::circle_fit_by_taubin.
  • Set converted TrackSeed X0/Y0 from the poly track’s helix center.
  • Compare cluster centroids and tracks in the world frame in Tpc_PolyClusterResiduals.cc when geometry is available.
  • Use sphenix_constants::time_between_crossings in the polyseeding modules instead of 106.56 ns.
  • Permit missing space-charge or frame-charge map payloads when both corresponding scales are explicitly zero.
  • The author reports improved pT ratios in a run 79513 comparison. Those results are author-reported and are not independently verified here.

Potential risk areas

  • The fit and seed-center changes affect reconstruction behavior, including inferred radii and track parameters.
  • The world-frame conversion changes residual and arc-direction calculations. Its fallback retains envelope-frame coordinates when geometry is unavailable.
  • The crossing-period update changes timing-derived positions; the commit notes an approximately 7 μm z shift per crossing.
  • The optional-map logic changes input-loading behavior when the relevant scales are zero.
  • No test results or current review findings were supplied. IO format, thread-safety, and performance effects are not established by the available evidence.

Possible future improvements

  • Add regression tests for short-arc fits, seed centers, residual frame conversion, and missing maps with zero scales.
  • Validate the reconstruction changes with the reported comparison and document the sample selection and uncertainty.
  • Track the remaining momentum-scale effects, including energy loss, separately from the circle-fit change.

AI-generated summaries can contain mistakes. Use best judgment and verify implementation details and reported performance against source and analysis results.

…tional field maps

- Tpc_FittingTools: use the Taubin circle fit; the algebraic fit underestimated R on short arcs, possibly giving a charge-dependent phi0 bias of the seeds.
- TpcPolyTrackSeedConverter: X0/Y0 were mirrored across the track; use the circle centre from the poly fit.
- Tpc_PolyClusterResiduals: compare clusters and tracks in the world frame (was a ~2 mm TPC envelope/world offset).
- PHGarfield: missing field-map payloads are not fatal when the correction is switched off (non-distorted MC, e.g. MDC2 tag).
The poly modules hard-coded 106.56 ns while Acts uses 106.652 ns, shifting converted TPC clusters by ~7 um in z per crossing.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The changes update Garfield map-loading conditions, transform TPC cluster centroids for diagnostics when geometry is available, and adjust TPC tracking defaults and calculations.

Changes: Garfield Map Loading

Layer / File(s) Summary
Conditional map lookup failures
offline/packages/PHGarfield/PHGarfield.cc
Missing space-charge maps are tolerated when both sides’ space-charge scales are explicitly overridden to zero. Missing frame maps are tolerated when both frame-charge scales are explicitly overridden to zero. Other unresolved inputs still cause loading to fail.

Cluster Residual Coordinates

Layer / File(s) Summary
World-frame centroid use
offline/packages/TrackingDiagnostics/Tpc_PolyClusterResiduals.cc
When ActsGeometry is available, cluster centroids are transformed from the TPC envelope frame to the world frame. Residual calculations, arc-direction selection, and recorded cluster coordinates use the transformed values. If geometry is unavailable, the code warns on the first event and uses untransformed coordinates.

TPC Tracking Updates

Layer / File(s) Summary
Shared crossing-period defaults
offline/packages/tpctrackreco/TpcCrossingFinder.h, offline/packages/tpctrackreco/TpcPolyClusterTrkrClusterConverter.h, offline/packages/tpctrackreco/TpcPolyTrackSeedConverter.h, offline/packages/tpctrackreco/Tpc_PolyClusterizer.h
These classes initialize m_crossingPeriodNs from sphenix_constants::time_between_crossings instead of the literal 106.56.
Taubin transverse circle fit
offline/packages/tpctrackreco/Tpc_FittingTools.cc
Tpc_FittingTools::fit replaces its local Kasa fit with TrackFitUtils::circle_fit_by_taubin. It rejects non-finite radius or center values; subsequent checks and track-parameter calculations remain in place.
Helix center in published seeds
offline/packages/tpctrackreco/TpcPolyTrackSeedConverter.cc
publishSeed uses the poly track’s helix-center coordinates instead of deriving the center from seed coordinates, curvature sign, radius, and azimuth.

Priority: High

Merge Risk: Moderate · up to 17f2f

The Taubin fit change depends on libtrack, but libtpctrackreco does not link it directly. A macro that does not load libtrack first could fail to load the polytrack library, so add -ltrack before merging. The residual diagnostics can still produce mismatched-frame residuals when no geometry node is present, which affects only the diagnostics output.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Nitpick comments: 1
offline/packages/TrackingDiagnostics/Tpc_PolyClusterResiduals.cc: 1

510-510: Trivial · Functional Correctness · Quick win

Do not write residuals from mixed-frame inputs.

process_event accepts saved clusters and tracks without ActsGeometry. The fallback then uses envelope-frame clusters. Tpc_PolyTrackReco requires ActsGeometry and stores tracks fitted from world-frame coordinates. A saved world-frame track container can therefore produce incorrect residuals in this no-geometry path.

The warning indicates an intended envelope-frame mode, but the code does not enforce that the tracks are also in the envelope frame. Require geometry for world-frame tracks, or define and enforce an envelope-frame track input contract. The previous implementation already used raw envelope-frame centroids, so this is a remaining diagnostics limitation rather than a new production-data defect. Major severity is not justified for this diagnostics-only impact.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0c50905 and 17f2f7c.

Files selected for processing: 8
  • offline/packages/PHGarfield/PHGarfield.cc
  • offline/packages/TrackingDiagnostics/Tpc_PolyClusterResiduals.cc
  • offline/packages/tpctrackreco/TpcCrossingFinder.h
  • offline/packages/tpctrackreco/TpcPolyClusterTrkrClusterConverter.h
  • offline/packages/tpctrackreco/TpcPolyTrackSeedConverter.cc
  • offline/packages/tpctrackreco/TpcPolyTrackSeedConverter.h
  • offline/packages/tpctrackreco/Tpc_FittingTools.cc
  • offline/packages/tpctrackreco/Tpc_PolyClusterizer.h

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


double sol[3] = {0.0, 0.0, 0.0};
if (!solve_3x3(A, b, sol))
const auto [R, xc, yc] = TrackFitUtils::circle_fit_by_taubin(xy);

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.

Major · Stability & Availability · Heavy lift

Supported by static analysis

Script executed:

set -eu
printf '%s\n' '--- diff for relevant files ---'
git diff --no-ext-diff --unified=30 0c509054d780051c067a5b1e513bc014bba098d7 17f2f7c4d175db5c9b3ee692b844c5ac76394cfd -- \
  offline/packages/tpctrackreco/Tpc_FittingTools.cc \
  offline/packages/tpctrackreco/Makefile.am \
  offline/packages/trackbase/Makefile.am
printf '%s\n' '--- Taubin declarations and implementation ---'
rg -n -F --glob '*.{h,cc,cpp,cxx,c}' \
  -e 'circle_fit_by_taubin' \
  offline/packages/trackbase offline/packages/tpctrackreco
printf '%s\n' '--- tpctrackreco Makefile context ---'
nl -ba offline/packages/tpctrackreco/Makefile.am | sed -n '1,180p'
printf '%s\n' '--- trackbase Makefile context ---'
nl -ba offline/packages/trackbase/Makefile.am | sed -n '1,180p'

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 16487


Script executed:

set -eu
printf '%s\n' '--- trackbase library definitions ---'
nl -ba offline/packages/trackbase/Makefile.am | sed -n '240,390p'
printf '%s\n' '--- all relevant track library declarations ---'
rg -n -F --glob 'Makefile.am' \
  -e 'libtrack_la_SOURCES' \
  -e 'libtrack_la_LIBADD' \
  -e 'libtrack_io_la_LIBADD' \
  -e 'libtpctrackreco_la_LIBADD' \
  -e 'trackbase' \
  offline/packages/trackbase offline/packages/tpctrackreco
printf '%s\n' '--- TrackFitUtils implementation and declaration ---'
nl -ba offline/packages/trackbase/TrackFitUtils.h | sed -n '1,55p'
nl -ba offline/packages/trackbase/TrackFitUtils.cc | sed -n '130,175p'

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 8208


Declare the direct libtrack dependency.

TrackFitUtils::circle_fit_by_taubin(xy) is implemented in libtrack. Add -ltrack so libtpctrackreco does not depend on another module loading libtrack first.

Suggested fix
   -ltrack_io \
+  -ltrack \
   -ltrackbase_historic_io \

Source: Path instructions

@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 17f2f7c4d175db5c9b3ee692b844c5ac76394cfd:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@osbornjd

Copy link
Copy Markdown
Contributor

I restarted jenkins on this, so that we can compare the current reference default build with new material map to this PR+default build+new material map

@mcyoren
mcyoren marked this pull request as ready for review October 27, 2026 17:38
@sphenix-jenkins-ci

Copy link
Copy Markdown

Build & test report

Report for commit 17f2f7c4d175db5c9b3ee692b844c5ac76394cfd:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@coderabbitai coderabbitai Bot mentioned this pull request Oct 28, 2026
2 of 5 tasks
@osbornjd
osbornjd merged commit fd8b28c into sPHENIX-Collaboration:master Oct 28, 2026
41 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Oct 28, 2026
1 of 3 tasks
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