Skip to content

auto-hunt: TRACKING - 19 fixes (S1 1, S2 6, S3 12) - #1259

Merged
staylorjlab merged 19 commits into
masterfrom
auto-hunt/tracking
Dec 3, 2026
Merged

staylorjlab merged 19 commits into
masterfrom
auto-hunt/tracking

Conversation

@DraTeots

@DraTeots DraTeots commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

These fixes come from the Hall D bug hunt, an autonomous campaign that read the GlueX software, built a test for every suspect line, and kept only findings confirmed by a measurement: a test run of the program on data or simulation, or a direct call of the code against a known answer. Each commit below fixes one finding and is named by its finding id and grade (S1 most serious, S4 least). Every commit has a comment in this pull request with the finding's card: what is wrong, the code, the measured effect, who is affected and the fix. Full cards with plots are on the campaign pages (JLab login): https://pages.jlab.org/halld/auto-hunt/index.html, by library: https://pages.jlab.org/halld/auto-hunt/libraries.html

Split at the reviewer's request (2026-12-01). This pull request first held all 49 tracking findings. It now holds the 19 production-tracking fixes (S1 to S3). The straight-line (field-off) fixes are in #1263 (8 commits) and the remaining minor fixes in #1264 (22 commits, all S4). The commits are the same changes as before, cherry-picked onto the current master without conflicts; the branch was force-pushed. The three pull requests merge together in any order, and their combination equals the former 49-commit branch file for file. The comments below for the 30 findings that moved belong to #1263 and #1264 now, where each is posted again; the commit hashes in all 49 earlier comments here are those of the old branch.

Overall gains

19 confirmed bugs fixed in this pull request (S1 1, S2 6, S3 12), one commit each, in the order of the commits (most serious first).

finding grade what was wrong the fix
R3-43i S1 A simulation option replaces each track's quality number (normally its fit probability) by one from the simulated particle the track came from. To find that particle, the code takes the particle's id number, counted over all simulated particles, and uses it as a position in a shorter list that holds only the final-state particles. Where the position falls inside the list it picks the wrong particle and, by reading, gives a wrong number without warning; where it falls past the end, the job reads garbage and crashes within the first events. Look the particle up by its id.
R3-1 S2 For electron and positron fits, the loss formula holds the square of the mean excitation energy, so its logarithm must be subtracted twice; the code subtracts it once. The collision loss comes out at 0.34 to 0.57 of the right value from 0.1 to 5 GeV/c in hydrogen, plastic and argon. Subtract the logarithm twice (one line).
R3-41 S2 The tracking swim reads its step settings (the TRK parameters, such as the largest step) from the job only when it is built with a handle to the job. The wire-based track factory builds its swim without that handle, though it holds it in the same routine, so this swim keeps the built-in values. The built-in values equal the parameter defaults, so a default job is unchanged. Build the wire-based swim with the job's handle.
R3-59 S2 Stepping along z, the forward track fit crosses the CDC endplate in one step of the endplate's thickness, 0.6 cm, and sets a flag. The flag is never cleared, so every later step up to the last FDC plane is 0.6 cm too (shorter only where it lands on a hit plane). Finer than the normal 2 cm, these steps no longer stop at material boundaries. Clear the flag after the endplate step.
R3-6 S2 Most tracks end their fit in a forward description, and their error matrix is then converted to the point closest to the beam line. There the code takes the derivatives of that point's z with the wrong sign. The error on z stays right; its correlations with momentum, angles and distance to the beam are reversed. Change the four signs.
R3-63 S2 Each track is fitted under several masses, each with a quality number (FOM, 0 to 1); later code picks the highest-FOM mass. The simulation option TRKFIT:PID_FORCE_TRUTH should replace every FOM by a truth score, above 0 only for the true mass. It does so only for the masses fitted first (the pion, and the proton for slow tracks); masses added later keep their fit FOM. Release 5.9.0 is the same; "today" includes the fix of the option's crash. see the commit
R3-9 S2 The forward track fit carries the track and its errors from step to step with derivatives of the equation of motion. In the derivative of the x slope by y, the term with the y-gradient of the beam-axis field takes the x slope where the equation has the y slope. Fitted tracks and hit weights come out slightly off. One letter: tx to ty.
R3-10 S3 After a forward track fit, the code extends the track to the FDC planes the fit did not reach and stores the path length and flight time per plane, passed there in swapped order. Both are in cm at that point, so the path length is too long and the time too short by 1/beta: for a 0.8 GeV/c proton, +54% and -35%. The FDC hit search of the time-based fit reads that path length; nothing reads the time. Swap the two arguments back, one line.
R3-12 S3 A track fitted with the central (CDC) parameters is finally stepped from the start of its fitted trajectory to the point closest to the beam line. On that step the code negates the energy loss, the only one of 21 calls of the energy-loss function that does, so the vertex momentum is off by twice the energy lost on the step. Release 5.9.0 has the same line. Drop the minus.
R3-14 S3 For forward tracks the Kalman fitter takes each CDC hit's track-to-wire distance at their closest approach. When that lies beyond the downstream end of the straw, the code moves the track back to the end and leaves the wire where it was. On a stereo wire (6 degrees to the beam) the distance is then off by up to a tenth of the overshoot, at most about 3 mm. Release 5.9.0 has the same lines. Take the wire where the track is.
R3-19 S3 An FDC track candidate records its first and last FDC package (of four). When segments from further packages are joined to it later, the code refits the track but does not update this range. The next step joins CDC hits only to candidates starting in the first package, so a track that gained its first-package segment late gets none. Release 5.9.0, used for the 2025-01 pass, computes the range from the segments each time and is not affected. Update the package range wherever segments are joined.
R3-2 S3 For the first fit of every track, the hit selection gives each wire hit an error from the track's curvature, corrected for the field at the hit, and drops hits too far off. Each hit's correction is applied on top of the previous hit's, so a hit carries the corrections of all hits before it. Release 5.9.0 has the same lines. Scale from the values at the track's start.
R3-32 S3 Two faults in the optional second Kalman track fitter. Its hits arrive with the event's time offset already subtracted, and it subtracts it again. And when it steps toward a CDC wire in pieces, every piece starts from the first point, so the track travels too far. Subtract the offset once; start each step piece where the last one ended.
R3-37 S3 To find where a track crosses a radius, a BCAL shower's, the code steps back from the stored track point outside it toward the one inside. The position moves by the fraction of the step that reaches the radius, the flight time by the rest: the time belongs to the point mirrored about the step's middle. 5.9.0 has the same line. The same fraction for both.
R3-4b S3 A track below 60 degrees is fitted with the forward and the central track model; the more probable fit is kept. The forward result is stored only for tracks with FDC hits. When the forward fit of a CDC-only track wins, the fitter returns chi-square -1 and no degrees of freedom, and the next stage takes the wire-based fit instead or drops that mass hypothesis. Release 5.9.0 has the same lines. Store the forward fit for every track.
R3-43d S3 A tracking routine finds the distance from a track to a hit point with a small-angle expansion of the helix, valid when the turning angle to the closest point is below 0.2 rad. When the equation for that angle has one root, the routine returns the distance below 0.2 and "no answer" above. When it has three roots, the test is the wrong way round: no answer where the expansion holds, a distance where it does not. Turn the test round.
R3-48 S3 The density-effect correction of the track fit's energy loss takes one form for materials whose mean excitation energy I is below 100 eV and another above. ln I is held with I in GeV (100 eV is -16.118), but the test is against -1.6118, so every solid takes the low form: aluminium, copper and the like lose up to 3% more energy in the fit than with the fix. Write -16.118 in the three places (measured at the main one).
R3-49 S3 The track fit takes a track's time from the earliest CDC or FDC drift time along its path, searching down from 1 000 000 ns. When no step of the path carries such a hit, that start value becomes the track time and the start time of later fits and matches: 2.5% of time-based fits with today's code, 1.3% in the 2025-01 pass. Keep the fit's start time when no drift time was found.
R3-51 S3 When a track candidate joins FDC and CDC hits, its helix is refitted, and each CDC stereo wire gives a point where the wire crosses the track circle. The code finds the distance d along the wire to that crossing, then divides it by cos(stereo) a second time. The point stays on the wire but lands beyond the crossing, off the circle, with its z offset from the wire centre stretched by 1/cos(stereo), 0.55% at 6 degrees. Release 5.9.0 has the same line. Drop the second division.

Related findings and commits that belong together

  • auto-hunt: TRACKING minor issues - 22 fixes (S4 22) #1264 edits some of the same files as this pull request (DTrackFitterKalmanSIMD.cc, DReferenceTrajectory.cc, DTrackFitter.cc, DHelicalFit.cc, DTrackCandidate_factory_FDCCathodes.cc) in different places; they merge without conflict in either order.
  • R3-63 is tested together with R3-43i, the fix of the same option's crash; both are in this pull request.

How it was tested

Each finding's card says how it was confirmed (a run of the program before and after the fix on the same events, or a direct call of the function). The commits were rebased on the current default branch; every changed source file compiles (syntax check against the release headers). A full build and a physics benchmark of this combination of commits has not been run on the new base.


Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-43i S1 (commit ad67206)

A simulation option that rates tracks by their true particle crashes the job

What is wrong. A simulation option replaces each track's quality number (normally its fit probability) by one
from the simulated particle the track came from. To find that particle, the code takes the particle's id
number, counted over all simulated particles, and uses it as a position in a shorter list that holds only the
final-state particles. Where the position falls inside the list it picks the wrong particle and, by reading, gives a
wrong number without warning; where it falls past the end, the job reads garbage and crashes within the first events.

The code (on GitHub):

int thrownIndex = GetThrownIndex(mcthrowns, track, f);   // the particle's id number, counted over all particles
if(thrownIndex<=0 || f<=0.5) return 0.;
double delta_pt_over_pt = (fourMom.Pt()-gen_fourMom[thrownIndex-1].Pt())/...;   // used as a position
...
if (fabs(track->mass()-mcthrowns[thrownIndex-1]->mass())<0.01 && ...)          // in the final-state list

Fixed: find the position of the particle with that id first.

int thrownPos=-1;
for(unsigned int i=0; i<mcthrowns.size(); i++)
  if(mcthrowns[i]->myid==thrownIndex) thrownPos=i;
if(thrownPos<0) return 0.;
// ... then gen_fourMom[thrownPos], mcthrowns[thrownPos]

What it does (1000 simulated events with the option):

events written now with the fix
development code 0 of 1000 (crash) 1000 of 1000
release 5.9.0 0 of 1000 (crash) 1000 of 1000

Plot: BH-370: simulation jobs with the option, today and with the fix

BH-370. Today dashed, nothing written; orange with the fix. Both crash reports name this function.

Who is affected. Simulation studies that switch the option on.

Who is not. Data, and every reconstruction without the option.

The fix. Look the particle up by its id.

Grade S1 (most severe of four, "the job crashes"): both tested jobs crash. The option is off by default, set by
no configuration of the collaboration's code, and its use is not known.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-43i-truth-fom-thrown-indexed-by-myid/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-43i-truth-fom-thrown-indexed-by-myid

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-53 S1 (commit 103385b)

The field-off drift-chamber alignment gets no tracks: the straight-line fitter fills hit residuals in an old order

What is wrong. For each hit on a track the fitter stores its residual and error in a small record (a "pull").
In the development code the record changed: the error became a variance and one field was removed. The
straight-line fitter, used when the solenoid is off, still fills it in the old order, so later fields shift by one:
for central-chamber (CDC) hits a drift time lands in the cathode-residual field, for forward-chamber (FDC) hits a
signed residual in the cathode-variance field. The alignment plugin drops any track with a cathode residual above
10 cm or a negative variance: every track.

The code (on GitHub):

// the record now:  pull_t(resi, var, s, tdrift, d, cdc_hit, fdc_hit, docaphi, z, tcorr, resic, varc, ...)
pull_t thisPull(resi,sqrt(V),                     // an error where the variance belongs
                best_trajectory[m].t*SPEED_OF_LIGHT,
                cdc_updates[id].tdrift,
                d,cdchits[id], NULL,
                diff.Phi(), //docaphi
                best_trajectory[m].z,cosThetaRel,  // a removed field: shifts the rest by one
                cdc_updates[id].tdrift);           // so the drift time lands in the cathode residual

Fixed, as the main (Kalman) fitter already fills it:

pull_t thisPull(resi,V, ..., best_trajectory[m].z, cdc_updates[id].tdrift);

What it does (real data, field-off run, 10000 events):

alignment file now (same file, two attempts) with the fix
tracks written 0 2003
size 0 bytes 4781684 bytes

Plot: BH-371: tracks written to the field-off alignment file, today and with the fix

BH-371 (version 2). Today's bars have zero length; orange with the fix. Limits: the alignment fit itself was not run.

Who is affected. Field-off alignment of the CDC and FDC with the development code; anyone reading the pulls of
field-off tracks.

Who is not. Field-on running and physics; release 5.9.0 (it has the old record).

The fix. Fill the record in its new order, with variances.

Grade S1 (most severe of four, "an output missing in every event"): the alignment output is empty; no crash, no
physics output changes. Development code only; a calibration setup outside the production plugin list.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-53-straightline-pulls-old-pull-t-arguments/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-53-straightline-pulls-old-pull-t-arguments

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-1 S2 (commit dcf3986)

The track fit gives electrons and positrons about half the collision energy loss they should have

What is wrong. For electron and positron fits, the loss formula holds the square of the mean excitation energy,
so its logarithm must be subtracted twice; the code subtracts it once. The collision loss comes out
at 0.34 to 0.57 of the right value from 0.1 to 5 GeV/c in hydrogen, plastic and argon.

The code (shortened, on GitHub):

// pions, kaons, protons
dEdx=K_rho_Z_over_A/beta2*(-log(two_Me_betagamma_sq*Tmax)
      +2.*(LnI + beta2)+delta);                        // ln I twice
...
// collision loss (Leo eq. 2.66)
double dEdx_coll
   =-K_rho_Z_over_A/beta2*(log(0.5*tau_sq*tau_plus_2*m_e_sq)-LnI+f-delta);   // <-- ln I once

Fixed:

   =-K_rho_Z_over_A/beta2*(log(0.5*tau_sq*tau_plus_2*m_e_sq)-2.*LnI+f-delta);

What it does (unselected: 1000 events of a 2025-01 run; selected: seven standard reactions in 1M events
of that run):

now with the fix
collision loss of an electron at 1 GeV/c in hydrogen / argon, as a fraction of the right value 0.416 / 0.553 1
unselected events whose electron or positron track fits move beyond 0.1% in momentum 727 of 998
fits as pion, kaon or proton that change 0 of 7954
e+ e- mass in gamma p -> p e+ e-, median change +1.2 MeV (+0.17%)

Plot: BH-67: the fit gives electrons 0.416 to 0.553 of the textbook collision loss at 1 GeV/c

BH-67. Collision loss of the fit over the textbook value for an electron, from the code's formula (no events);
dashed line at 1: with the fix. Plastic lies on hydrogen.

Who is affected. Lepton analyses: too little lost energy is added back, so momenta
come out low (0.12% at the median in p e+ e- events), and e+ e- masses with them. Photons slightly, through track
matching: 69 of 22746 selected events change their photon list, as an eta -> pi0 gamma gamma analysis may meet.

Who is not. Pion, kaon and proton fits; no standard reaction yield moves beyond three standard deviations.

The fix. Subtract the logarithm twice (one line).

Grade S2 (second of four levels of how widely an output moves): electron and positron fits change beyond 0.1% in
momentum in 73% of unselected events, mostly the electron fits of pion and proton tracks. Its weight is on lepton
analyses.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-1-electron-dedx-ln-i-once/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-1-electron-dedx-ln-i-once

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-33 S2 (commit f9bc3cd)

Solenoid off: each forward track's first piece also comes back as its own track

What is wrong. Without field, forward tracks are built by linking straight pieces (segments) of the
forward drift chambers. The start piece is never marked as used and comes back as a one-piece track: one
particle counted twice. The direction computed after a join is dropped.

The code (on GitHub):

if (myhits.size()>0){         // pieces of later packages were linked: build the track
   myhits.insert(myhits.begin(),fdc_segments[i][j].hits.begin(),fdc_segments[i][j].hits.end());
   fdc_tracks.push_back(fdc_segment_t(myhits));
}                             // <-- the start piece is never marked as used
...
fdc_tracks[i].FindStateVector();   // <-- after a join: the new direction is computed and dropped
...
// Make track candidates out of single segments not connected to other tracks
if (fdc_segments[j][k].matched==false){
  fdc_tracks.push_back(fdc_segments[j][k]);   // so the start piece comes back as a track

Fixed:

   fdc_segments[i][j].matched=true;
   fdc_tracks[i].S=fdc_tracks[i].FindStateVector();

What it does (field-off run 133609, 2.4M events; selected events, mostly not the
exclusive reaction; σ: gained minus lost over the square root of their sum):

reaction today → fixed change
π⁰ → γγ 255 → 266 +4.3%, 3.05σ
η → γγ 327 → 341 +4.3%, 3.7σ
ω → π⁰γ 878 → 912 +3.9%, 4.7σ

η → π⁰γγ: not run on this sample.

About half of the gains are explained by the duplicates: the selection drops events with more than three extra
tracks, and 33 of the 69 gains sit at that limit with the fixes; the rest is not explained, and the two fixes were
measured together. Good fits do not change (16, 2 and 24 both ways): no yield gain is shown.

Plot: BH-443: 789 of the 833 candidates the fix removes are the start segment of a kept track, counted a second time

BH-443. A different sample from the table's: field on, 1000 events (998 read), finder forced on, start-piece fix alone.

Who is affected. Event selection without field, the only case using this finder. The 2025-01 pass has the
same lines; whether it made field-off files is not known.

The fix. Mark the start piece used; keep the direction after a join.

Grade S2 (second of four levels of how widely an output moves): three photon reactions change by about 4%
without field. It says nothing about field-on running or alignment.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-33-straightline-stale-state-duplicate-segment/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-33-straightline-stale-state-duplicate-segment

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-41 S2 (commit a746929)

The step-size settings of the track swim do not reach the wire-based fit

What is wrong. The tracking swim reads its step settings (the TRK parameters, such as the largest step) from
the job only when it is built with a handle to the job. The wire-based track factory builds its swim without that
handle, though it holds it in the same routine, so this swim keeps the built-in values. The
built-in values equal the parameter defaults, so a default job is unchanged.

The code. The real lines, shortened (on GitHub):

auto app = GetApplication();                 // the job's handle, in the same routine
...
// set up reference trajectory
rt = new DReferenceTrajectory(bfield);       // <-- built without it

// in the swim's constructor:
if (app != nullptr) {
    app->SetDefaultParameter("TRK:MAX_STEP_SIZE", MAX_STEP_SIZE, ...);
    ...                                      // never reached for this swim
}

Fixed:

rt = new DReferenceTrajectory(bfield, app);

What it does (998 events of a 2025-01 run read in both runs; events that change with the fix):

default settings step size set to 1 cm
wire-based tracks 0 600
time-based tracks 0 595
charged tracks 0 143

Plot: BH-901: with the step size set, the fix changes wire-based tracks in 600 of 998 events; at the defaults nothing

BH-901. Events changed by the fix per object type, default settings and largest step 1 cm (default 3 cm), current
code and the 2025-01 pass release. Limits: one run, one value.

Who is affected. Jobs that set a TRK step parameter: the time-based energy-loss swim follows it, the wire-based
fit stays on the built-in values, so one track is swum on two settings.

Who is not. Default jobs and production: 0 of 998 events change.

The fix. Build the wire-based swim with the job's handle.

Grade S2 (second of four; S1 is the most severe), on jobs that set a TRK step parameter: with the one value
measured, time-based tracks change in 595 of 998 events. At the defaults nothing changes, also on 1 000 000 raw events
with 12 other tracking fixes: no benchmark reaction moved.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-41-wirebased-rt-ignores-trk-parameters/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-41-wirebased-rt-ignores-trk-parameters

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-56 S2 (commit 3158f7f)

Field-off track fits weight forward CDC hits with an uninitialised number

What is wrong. With the solenoid off, tracks are fitted as straight lines in two passes: wire-based (wire
positions) and time-based (drift times), which starts from it. For forward tracks the weight of each CDC hit comes
from a variable set only in the time-based pass; the wire-based pass uses whatever the build leaves in memory and
keeps or drops hits and tracks by it.

The code (on GitHub):

double V_CDC;                                   // declared, never given a value
...
if (fit_type==kTimeBased){
  ...
  CDCDriftParameters(dphi,delta,tdrift,dmeas,V_CDC);    // set only in the time-based pass
}
...
double InvV=1./(V_CDC+H_CDC*C*H_T_CDC);         // wire-based pass: reads the garbage value

Fixed, with the wire-based value the same fitter already uses for central tracks:

double V_CDC=1.15*(0.78*0.78/12.);              // (0.78 cm)^2/12, the code's scale factor 1.15

What it does (field-off data, 10 000 events; two runs of today's code are identical):

straight tracks today with the fix
wire-based 24227 25911 (+7.0%)
time-based (final) 18247 19886 (+9.0%)

Plot: BH-390: field-off track counts today and with the fix

BH-390. Limits: one field-off run, no truth (no field-off simulation), one build.

Benchmark reactions (a change; no direction is claimed):

2.4M raw events of the field-off run 133609 (solenoid off), master; same events, σ from events gained and lost:

reaction today → fixed change
π⁰ → γγ 255 → 214 -16.1%, -5.9σ
η → γγ 327 → 267 -18.3%, -7.0σ
ω → π⁰γ 878 → 718 -18.2%, -11.2σ

No event selected in this sample: ω → π⁺π⁻π⁰, ρ → π⁺π⁻, φ → K⁺K⁻ and e⁺e⁻.

Who is affected. Anyone reconstructing field-off runs (mostly alignment): these are then the default tracks.

Who is not. Field-on data and simulation, including eta -> pi0 gamma gamma: the straight-line fit does not make
those tracks.

The fix. Give the variable its wire-based value (one line).

Grade S2 (second most severe of four): track counts change by more than 1% in this build (another build may
differ). Neither the fit quality (76.4% of added tracks fit with probability of at least 1%, against 65.2% of all)
nor the 16-18% loss says which side is right.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-56-straightline-forward-cdc-variance-uninitialised/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-56-straightline-forward-cdc-variance-uninitialised

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@gluex

gluex commented Dec 1, 2026

Copy link
Copy Markdown

Build status for this pull request: FAILURE

Build log: make_auto-hunt_tracking.log
Build report: report_auto-hunt_tracking.txt

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-59 S2 (commit 7f64e7f)

Forward tracks: after the CDC endplate, every step of the track fit has the endplate's thickness

What is wrong. Stepping along z, the forward track fit crosses the CDC endplate in one step of the endplate's thickness, 0.6 cm, and sets a flag. The flag is never cleared, so every later step
up to the last FDC plane is 0.6 cm too (shorter only where it lands on a hit plane). Finer than the normal 2 cm, these steps no longer stop at material boundaries.

The code
(on GitHub):

   ...   // ds chosen above from energy loss, material boundaries, at most 2 cm
   double dz=stepped_to_endplate ? endplate_dz : ds*dz_ds;   // once set, always 0.6 cm
   double newz=z+dz;
   if (newz>endplate_z && z<endplate_z){
      newz=endplate_z+EPS3;
      stepped_to_endplate=true;     // set here, never set back to false
   }

Fixed:

   double dz=ds*dz_ds;
   if (stepped_to_endplate){   // one step through the endplate, then normal steps again
      dz=endplate_dz;
      stepped_to_endplate=false;
   }

What it does (BH-T74; 1000 events of run 132404, 998 event numbers in both outputs):

now with the fix
events with a changed time-based track fit 650 of 998
fits below 20 deg (all particle hypotheses) whose printed momentum (1 MeV steps) changes, of 5161 3750; 915 by more than 1%
changed forward fits (one per track) with a lower chi2/ndf 639 of 1065 (60%)
median chi2/ndf of the 10369 paired fits (shift -0.010, 95%: -0.032 to +0.013) 1.937 1.927

Plot: BH-287: changed fits per angle range, lower and higher chi2/ndf

BH-287. Fits per angle range, one per track: unchanged, lower or higher chi2/ndf with the fix. Real data; no truth.

Who is affected. Every analysis with forward tracks (FDC hits, below about 20 degrees), and less so 20-60 degrees
(414 of 3754 fits change; 76 of 118 changed pion fits get a higher chi2/ndf); release 5.9.0 and master, data and
simulation. Changes above 1% go both ways; smaller ones lean lower (median -0.08%, one fit per track). Through track matching, showers change; the beam bunch moves in 14 of 998 events.

Who is not. Tracks above 60 degrees (4 of 1454 fits move).

The fix. Clear the flag after the endplate step.

Grade S2 (second most severe of four): track fits move beyond one printed digit in 65% of events. No physics effect was measured;
closeness to the truth is untested.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-59-forward-steps-ignore-limits-after-cdc-endplate/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-59-forward-steps-ignore-limits-after-cdc-endplate

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-6 S2 (commit 2e4929c)

Most tracks carry their z correlations with the wrong sign

What is wrong. Most tracks end their fit in a forward description, and their error matrix is then converted to the point closest to the beam line. There the code takes the derivatives of that point's z with the wrong
sign. The error on z stays right; its correlations with momentum, angles and distance to the beam are reversed.

The code (on GitHub):

J(state_z,state_x)=tx_/tsquare;                          // <-- sign wrong
J(state_z,state_y)=ty_/tsquare;                          // <-- sign wrong
...
J(state_z,state_tx)=-(x_*diff+2.*tx_*ty_*y_)*frac;       // <-- sign wrong
J(state_z,state_ty)=-(2.*tx_*ty_*x_-y_*diff)*frac;       // <-- sign wrong

Fixed, as in the file's other conversion:

J(state_z,state_x)=-tx_/tsquare;  ...  J(state_z,state_tx)=(x_*diff+2.*tx_*ty_*y_)*frac;  ...

What it does (2025-01 data; the fits fit energy, momentum and vertex):

now with the fix
tracks in REST with z correlations reversed, 1000 events 2350 of 2749 0
median fit chi-square per degree of freedom, p pi+ pi-, 1 million events 11.9 10.3
the same, p pi+ pi- pi0 / p K+ K- 42.4 / 23.5 38.3 / 19.7

Plot: BH-74: kinematic fit quality per event, with the fix against today

BH-74. Per event selected with and without the fix, 1 million 2025-01 raw events: fit chi-square per degree of freedom, fix over today (orange), two runs without the fix (blue). Left of 1: lower with the fix. Limits: real data, three reactions; a lower chi-square is not by itself a check against the true vertex.

Who is affected.

  • Vertex fits, and kinematic fits that fit the vertex of two or more tracks.
  • Anyone using the track error matrix, also from REST files already written (2025-01 pass included).

Who is not. Track parameters and their single errors; reactions with one charged track. Yields of seven standard
reactions stay within 1.4 standard deviations, though 6-13% of the selected events are swapped for others.

The fix. Change the four signs.

Grade S2 (second of four levels of how widely an output moves): the vertex fit changes in most events. It says
nothing about physics weight.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-6-transformcovariance-z-row-sign/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-6-transformcovariance-z-row-sign

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-63 S2 (commit 7400bde)

A simulation option that forces the true particle identity misses most masses, so a wrong mass often wins

What is wrong. Each track is fitted under several masses, each with a quality number (FOM, 0 to 1); later code picks the highest-FOM mass. The simulation option TRKFIT:PID_FORCE_TRUTH should replace every
FOM by a truth score, above 0 only for the true mass. It does so only for the masses fitted first (the pion, and
the proton for slow tracks); masses added later keep their fit FOM. Release 5.9.0 is the same; "today" includes the fix of the option's crash.

The code (on GitHub):

if (PID_FORCE_TRUTH && mData.size()>num)      // only the mass just fitted
    mData[mData.size()-1]->FOM = GetTruthMatchingFOM(i, mData[mData.size()-1], mcthrowns);
...
InsertMissingHypotheses(event);                // the other masses: fit FOM, no truth score

Fixed: every mass gets the truth score after InsertMissingHypotheses.

What it does (1000 simulated events; 2439 tracks matched to a simulated hadron):

with the option true mass wins a wrong mass wins tie at the top
today 1097 1270 72
with the fix 1304 1 1134 (every FOM 0: no winner)

Plot: BH-465: which mass wins, without the option, today and with the fix

BH-465. Without the option a wrong mass wins in 1495 (the fit FOM alone does not identify particles). The 1134 are
mostly forward tracks: by reading, the truth score ignores forward-chamber hits unless FDC:MATCH_TRUTH_HITS=1 (off by default and here).

Side effect of the fix (at the default FDC setting). Tracks with every FOM 0 fail the vertex fit's minimum: events
with two or more passing tracks drop from 905 (option on, today) to 418 of 1000; the others fall back to fitting all tracks.

Who is affected. Simulation studies that set this option (off by default).

Grade S2 (S1 the most severe of four): in jobs that set the option, a wrong mass wins for at least one track in
768 of 1000 events.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-63-truth-fom-skips-added-hypotheses/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-63-truth-fom-skips-added-hypotheses

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-9 S2 (commit 5a68e7c)

Forward track fit: one field-gradient term uses the wrong track slope

What is wrong. The forward track fit carries the track and its errors from step to step with derivatives of the
equation of motion. In the derivative of the x slope by y, the term with the y-gradient of the beam-axis field takes
the x slope where the equation has the y slope. Fitted tracks and hit weights come out slightly off.

The code. The real lines, shortened (on GitHub):

J(state_tx,state_x)=kq_over_p_ds*(ty*myField.dBzdx+txty*myField.dBxdx-one_plus_tx2*myField.dBydx);
...
J(state_tx,state_y)= kq_over_p_ds*(tx*myField.dBzdy+txty*myField.dBxdy-one_plus_tx2*myField.dBydy);
                                // <-- tx: the y derivative needs ty, as the x derivative above has

Fixed:

J(state_tx,state_y)= kq_over_p_ds*(ty*myField.dBzdy+txty*myField.dBxdy-one_plus_tx2*myField.dBydy);

What it does (raw: 1000 events of a 2025-01 run; selected: 22187 events seven standard reactions select in
1 million events of that run, on both sides):

changed by the fix number
raw events with a track moved beyond 0.1% in momentum or 0.1 mrad, or with other hits 570 of 998
selected events with a track moved beyond 0.1% or 0.1 mrad 2299 (10%)
events leaving / entering a selection 682 / 618
selected events with a different photon list 243 (1.1%)

Plot: BH-76: largest track momentum change per selected event

BH-76. Largest track momentum change per selected event. Right of the dotted line, beyond 0.1%: 1879 events (2299 with angle changes). Limits: one run.

Who is affected. Every analysis with charged tracks, in data and simulation; photons through clustering and
track matching: an eta -> pi0 gamma gamma analysis meets it in its photons, recoil proton and event list.

Who is not. Analyses without charged tracks or photons near tracks. In most selected events tracks move only by
parts in a million; no reaction yield moves beyond three standard deviations.

The fix. One letter: tx to ty.

Grade S2 (second of four levels of how widely an output moves), at its lower edge: tracks change beyond a tenth
of the resolution in 57% of raw events, in 10% of selected ones. It says nothing about which side is better.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-9-forward-jacobian-tx-for-ty/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-9-forward-jacobian-tx-for-ty

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-10 S3 (commit f11403d)

Path length and flight time are swapped for FDC planes beyond the fitted forward track

What is wrong. After a forward track fit, the code extends the track to the FDC planes the fit did not reach and
stores the path length and flight time per plane, passed there in swapped order. Both are in cm at that point, so the
path length is too long and the time too short by 1/beta: for a 0.8 GeV/c proton, +54% and -35%. The FDC hit search
of the time-based fit reads that path length; nothing reads the time.

The code. The real lines, shortened (on GitHub):

void AddExtrapolation(DetectorSystem_t detector, double z, const DMatrix5x1 &S,
                      double t, double s, ...);          // time first, then path length
...
s+=ds;                                                   // path length
t+=ds*sqrt(one_over_beta2);                              // time, in cm
...
AddExtrapolation(SYS_FDC,z,S,s,t,s_theta_ms_sum,theta2ms_sum);   // <-- swapped

Fixed, as in every other call of the file:

AddExtrapolation(SYS_FDC,z,S,t,s,s_theta_ms_sum,theta2ms_sum);

What it does. Raw data of a 2025-01 run, and a direct call:

now fixed
path length at the last FDC plane, 0.8 GeV/c proton (true 345.01 cm) 531.95 cm 345.01 cm
time-based track hypotheses changed, 1000 events 128 of 10488
yields of seven selected reactions, 1 million events within 2 standard deviations (largest 1.73)

Plot: Path length per FDC plane

Who is affected. Forward tracks, most when the hit search runs along a slow mass hypothesis: time-based tracks
change in 77 of 998 events at master, 20 of 998 in release 5.9.0.

Who is not. Photons: neutral showers change in 12 of 998 events, through track matching.

The fix. Swap the two arguments back, one line.

Grade S3 (third of four levels of how widely an output moves, S1 the widest): tracks change in 8% of events (2% in
5.9.0); no yield moves. It does not say whether tracks get better.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-10-fdc-extrapolation-s-t-swapped/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-10-fdc-extrapolation-s-t-swapped

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-12 S3 (commit 5668850)

The final step of a central track to the beam line applies the energy loss with the wrong sign

What is wrong. A track fitted with the central (CDC) parameters is finally stepped from the start of its fitted
trajectory to the point closest to the beam line. On that step the code negates the energy loss, the only one of 21
calls of the energy-loss function that does, so the vertex momentum is off by twice the energy lost on the step.
Release 5.9.0 has the same line.

The code. The real lines, shortened (on GitHub):

// central extrapolation to the beam line, with covariance
if (CORRECT_FOR_ELOSS){
   dedx=-GetdEdx(q_over_p,K_rho_Z_over_A,rho_Z_over_A,LnI,Z);   // <-- minus: GetdEdx is already
}                                                                //     dE/ds, negative
...
// the same extrapolation without covariance, and every other call:
   dedx=GetdEdx(q_over_p,K_rho_Z_over_A,rho_Z_over_A,LnI,Z);

What it does. Simulated gamma p -> eta p, eta -> gamma gamma, proton momentum at the vertex:

1041 events
changed 944, median +5.6e-7 relative
changed by 1% or more (protons of 0.27-0.34 GeV/c) 8; the fix moves all 8 farther from the true momentum

Plot: Proton momentum change per event

Who is affected.

  • Analyses with slow protons in the central region: their vertex momentum, mostly by a millionth, in a few by 1%.
  • Overall closer or farther is not shown; that the sign is wrong rests on the code.

Who is not. Photons: 0 of 1041 photon energies change. Yields of seven selected reactions in 1 million raw events
stay within 1.8 standard deviations.

The fix. Drop the minus.

Grade S3 (third of four levels of how widely an output moves, S1 the widest): track values, to the printed digits, change in
28% of raw events; smaller changes, below the printed digits, are not counted.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-12-vertex-extrapolation-eloss-sign/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-12-vertex-extrapolation-eloss-sign

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-14 S3 (commit 0d8a379)

Track fit at the CDC end: the wire is taken at a different place along the beam than the track

What is wrong. For forward tracks the Kalman fitter takes each CDC hit's track-to-wire distance at their closest
approach. When that lies beyond the downstream end of the straw, the code moves the track back to the end and leaves
the wire where it was. On a stereo wire (6 degrees to the beam) the distance is then off by up to a tenth of the
overshoot, at most about 3 mm. Release 5.9.0 has the same lines.

The code. Shortened (on GitHub):

newz=z+dz;                         // point of closest approach
if (newz>endplate_z){              // beyond the end of the straw:
  dz=endplate_z-z;                 //   the track is moved back to the end
}                                  // <-- newz, the wire's position, is not
...
wirepos+=(newz-z0w)*dir;           // wire at newz
dx=S(state_x)+S(state_tx)*dz-xw;   // track at z+dz

Fixed, inside the same if:

  newz=endplate_z;                 // added: wire at the same place as the track

What it does. Raw data of run 132404 (2025-01), 998 events, each run now and fixed:

release 5.9.0 master
events in which a time-based fit changes 124 128
time-based track fits that change, of all 421 of 10 717 449 of 10 510
... momentum moves by over 1% 104 84
number of fits, now -> fixed 10 717 -> 10 721 10 510 -> 10 513

Plot: Momentum change of each track fit the fix changes

Who is affected. Analyses with tracks at 10 to 30 degrees, which leave the CDC through its end: a fit changes in
12% to 13% of events, 16 fits by a factor of two or more. In 1 000 000 events, the kinematic fit changes in 484 of
7996 selected omega events.

Who is not. Yields of seven selected reactions (none beyond 1.13 standard deviations). Photons, except through
track matching; in eta -> pi0 gamma gamma only a forward recoil proton can change.

The fix. Take the wire where the track is.

Grade S3 (third of four, S1 the most severe): fits change in a minority of events; no count or yield moves by 1%.
Which side is closer to the truth is not measured.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-14-finddoca-endplate-clamp-z/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-14-finddoca-endplate-clamp-z

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-19 S3 (commit bf3a770)

Forward track candidates keep a stale record of which FDC packages they span

What is wrong. An FDC track candidate records its first and last FDC package (of four). When segments from
further packages are joined to it later, the code refits the track but does not update this range. The next step
joins CDC hits only to candidates starting in the first package, so a track that gained its first-package segment
late gets none. Release 5.9.0, used for the 2025-01 pass, computes the range from the segments each time and is not affected.

The code. Shortened (on GitHub):

// a leftover segment is joined to candidate i (upstream or downstream)
mData[i]->AddAssociatedObject(segment);
...
mData[i]->dMomentum=mom;        // the refit is stored ...
return true;                    // <-- ... FirstPackage, LastPackage are not

// next step: CDC hits are joined only to candidates from the first package
if (fdccan->FirstPackage>0) continue;

Fixed: set the range from the joined segments, sorted along the beam.

mData[i]->FirstPackage=segments[0]->package;
mData[i]->LastPackage=segments[segments.size()-1]->package;

What it does. Raw data of run 132404 (2025-01) reprocessed with master, without -> with the fix:

events whose track candidates change (of 998) 47
FDC candidates that gain CDC hits (from none) 44
track candidates 4992 -> 4989 (5 merges, 2 splits)
selected omega events (of 1 000 000 events) 7996 -> 8020 (44 lost, 68 gained)

Plot: Where the changed candidates start, and the CDC hits they gain

Who is affected. Future passes with master: forward tracks up to 30 degrees get their CDC hits in 4.2% of events;
the selected yields of omega, p pi+ pi- and p K+ K- rise by 0.1% to 0.3% (2.0 to 2.5 standard deviations of the
events exchanged).

Who is not. Files of the 2025-01 pass (release 5.9.0). Photons, except through tracks;
in eta -> pi0 gamma gamma only a forward recoil proton can change.

The fix. Update the package range wherever segments are joined.

Grade S3 (third of four, S1 the most severe): candidates change in a minority of events with master; no count or
yield moves by 1%. Which side is closer to the truth is not measured.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-19-fdc-package-range-not-updated/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-19-fdc-package-range-not-updated

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-2 S3 (commit 3d9d887)

The first track fit compounds a magnetic-field correction from one wire hit to the next

What is wrong. For the first fit of every track, the hit selection gives each wire hit an error from the track's
curvature, corrected for the field at the hit, and drops hits too far off. Each hit's correction is applied on top
of the previous hit's, so a hit carries the corrections of all hits before it. Release 5.9.0 has the same lines.

The code. CDC loop, shortened; the FDC loop is the same (on GitHub):

for( ... every hit, outermost first ... ){
  ...
  // Compensate for the fact that the field at the "origin" of the
  // track does not correspond to the average Bz used to compute pt
  double Bratio=last_step->B.z()/Bz0;
  double invBratio=1./Bratio;
  pt_over_a*=invBratio;   // <-- multiplies the value the previous hit left
  p_over_a*=invBratio;
  a_over_p*=Bratio;

Fixed: scale the values at the track's start, kept before the loop.

  pt_over_a=pt_over_a_0*invBratio;
  p_over_a=p_over_a_0*invBratio;
  a_over_p=a_over_p_0*Bratio;

What it does. Run 132404 (2025-01), same events:

now fixed
error of the 27 inner hits, one test track 0.5% to 4.9% larger one correction per hit
wire-based tracks, 998 events 4601 4594; change in 292 events
selected gamma p -> p K+ K-, 1 000 000 events (largest of seven reactions) 6118 6097 (-1.43 standard deviations)

Plot: Error given to each hit of the test track, now against fixed

Who is affected. Every analysis with charged tracks: in 28% of events a track takes different hits, or a track
appears or disappears.
Photons only through matching to tracks.

Who is hardly affected. Photon energies: none change in 1041 simulated eta -> gamma gamma events.

The fix. Scale from the values at the track's start.

Grade S3 (third of four levels of how widely an output moves): a minority of events; no count or yield by 1%.
Which side is closer to the truth is not measured.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-2-alt2-field-ratio-compounded/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-2-alt2-field-ratio-compounded

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-32 S3 (commit bc6cd50)

The alternative Kalman track fitter subtracts the hit time offset twice and oversteps toward the CDC wire

What is wrong. Two faults in the optional second Kalman track fitter. Its hits arrive with the event's time
offset already subtracted, and it subtracts it again. And when it steps toward a CDC wire in pieces, every piece
starts from the first point, so the track travels too far.

The code (on GitHub):

// hits are loaded with the offset removed: hit->t = fdchit->time - mT0
fdc_updates[my_id].tdrift = my_fdchits[my_id]->t - forward_traj[k].t*TIME_UNIT_CONVERSION - mT0;   // <-- removed again

double my_z=z;
for (int m=0;m<num_steps;m++){
   newz=my_z+my_dz;
   StepJacobian(z,newz,S0,dedx,J);   // <-- from z, the first point: should be my_z
   ...
   Step(z,newz,dedx,S0);             // <-- same
   my_z=newz;
}

With the fix the offset is subtracted once, and each piece starts where the last one ended. The double offset exists
only in the current release (version set 7.10.0); earlier releases load hits with the raw times.

What it does (998 raw events of a 2025-01 run, this fitter selected):

today with the fix
events with changed tracks, both halves 488
median chi-square per degree of freedom, both halves 2.573 2.402
track times not a number 4 0
tracks closer to the default fitter (time half, events) 66 146

Plot: BH-894: alternative fitter, 41.0% of track fits below chi-square per degree of freedom 2 today, 43.8% with the time fix

BH-894. Track fits of this fitter, today and with the time fix. The default fitter on the same events is the
reference that says the fix is right. Limits: one run.

Who is affected.

  • Anyone who selects this fitter with the option DEFTAG:DTrackFitter=KalmanSIMD_ALT1.

Who is not. The default reconstruction, its files and the physics benchmarks, which run the default fitter and
cannot reach this fix. The 2025-01 pass (release 5.9.0) has the step fault only.

The fix. Subtract the offset once; start each step piece where the last one ended.

Grade S3 (second lowest of four), on the jobs that set the option: objects change in 498 of 998 events, just
under half. Whether any production sets it is not known.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-32-alt1-finddoca-step-and-double-t0/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-32-alt1-finddoca-step-and-double-t0

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-37 S3 (commit 6a3adbc)

The track extrapolation to a radius returns the flight time of the wrong point

What is wrong. To find where a track crosses a radius, a BCAL shower's, the code steps back from the
stored track point outside it toward the one inside. The position moves by the fraction of the step that reaches
the radius, the flight time by the rest: the time belongs to the point mirrored about the step's middle. 5.9.0 has
the same line.

The code. Shortened (on GitHub):

pos=extrap.position;  t=extrap.t;  s=extrap.s;   // start at the outer point
...
DVector3 delta = prevpos - pos;
pos+=alpha*delta;                                 // position: back by alpha of the step
// Flight time and path length (approximate)
double ds=(1.-alpha)*delta.Mag();                 // <-- time and length: back by 1 - alpha
double v=(extrap.s-prev.s)/(extrap.t-prev.t);
s-=ds;
t-=ds/v;

Fixed:

double ds=alpha*delta.Mag();

What it does. Off by up to one step:

now, off by
field on: steps inside the BCAL of 0.5 to 2 cm up to 0.07 ns for fast tracks; changed track times, median 0.003 ns
field off: straight-line fit, points at 65 and 89 cm, shower at 70 cm about 0.47 ns
run 132404 (2025-01), 998 events: time-based fits change in 148 events; beyond the last digits in 31

Plot: Flight time returned at each radius on a test step, now and fixed

Who is affected.

  • Tracks whose start time comes from a BCAL shower, the last choice after start counter, TOF, FCAL and ECAL.
  • The BCAL timing calibration, per shower and per hit; past constants not checked.

Who is not. Uses of the crossing position alone; photon energies (1041 simulated eta -> gamma gamma events).
Seven selected reactions move within 1.21 standard deviations.

The fix. The same fraction for both.

Grade S3 (third of four levels, S1 the widest): a minority of events; no count or yield moves 1%. The
straight-line test shows the fix is right.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-37-extrapolate-to-radius-alpha/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-37-extrapolate-to-radius-alpha

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-4b S3 (commit 7346f0e)

Track fits: the forward fit of a track with CDC hits only wins the comparison but was never stored

What is wrong. A track below 60 degrees is fitted with the forward and the central track model; the
more probable fit is kept. The forward result is stored only for tracks with FDC hits. When the forward fit of a
CDC-only track wins, the fitter returns chi-square -1 and no degrees of freedom, and the next stage takes the
wire-based fit instead or drops that mass hypothesis. Release 5.9.0 has the same lines.

The code. Shortened (on GitHub):

forward_prob=TMath::Prob(chisq_,ndf_);
if (my_fdchits.size()>0){
   ...                                // forward against FDC fit
   chisq_forward=chisq_;              // <-- the store sits inside the FDC block:
   ndof_forward=ndf_; ...             //     never reached without FDC hits
}
...
if (central_prob<forward_prob){       // the forward fit wins
   chisq_=chisq_forward;              //     -1 and 0 for CDC-only tracks
   ndf_= ndof_forward; ...

Fixed: the FDC block closes before the store.

if (my_fdchits.size()>0){ ... }       // FDC block ends here
chisq_forward=chisq_; ...             // stored for every forward fit

What it does. Raw data of run 132404 (2025-01), 998 events, now -> fixed:

release 5.9.0 master
events whose time-based fits change 34 24
time-based fits 10 717 -> 10 768 10 510 -> 10 534
fits that fell back to the wire-based one, now refitted 13 12
charged tracks 2857 -> 2864 2797 -> 2797

Plot: Simulated tracks whose fit the fix replaces, against the thrown particle

In simulation (picture), of 6 replaced fits (4 tracks) near a thrown particle, 5 move closer to it in direction, 4 in
momentum, none farther in direction.

Who is affected. Analyses with charged tracks below 60 degrees with CDC hits only: a fit changes in 2.4% to 3.4% of
events; the fits added are often poor.

Who is not. Photons, except through track matching (simulated eta -> gamma gamma: 0 of 1041 events change); in
eta -> pi0 gamma gamma only the recoil proton can change. Yields of seven selected reactions show no net change beyond
1.0 standard deviation.

The fix. Store the forward fit for every track.

Grade S3 (third of four levels): track fits change in a minority of events; no object count or yield
moves by 1%.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-4b-forward-cdc-fit-never-saved/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-4b-forward-cdc-fit-never-saved

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-43d S3 (commit b094616)

Distance from a track to a hit point: one branch checks its small-angle limit the wrong way round

What is wrong. A tracking routine finds the distance from a track to a hit point with a small-angle expansion of
the helix, valid when the turning angle to the closest point is below 0.2 rad. When the equation for that angle has
one root, the routine returns the distance below 0.2 and "no answer" above. When it has three roots, the test is the
wrong way round: no answer where the expansion holds, a distance where it does not.

The code. The real lines, shortened (on GitHub):

if (d2>=0){                                   // one real root
  ...
  if (fabs(phi)<0.2){ // check small angle approximation
    ... dist2 = ...;                          // distance used
  }
  else{
    return numeric_limits<double>::quiet_NaN();
  }
}
else{                                         // three real roots
  ...
  if (fabs(phi)<0.2){ // Check small angle approximation
    return numeric_limits<double>::quiet_NaN();   // <-- the wrong way round
  }
}

Fixed: if (fabs(phi)>=0.2){ return numeric_limits<double>::quiet_NaN(); }

What it does (1000 raw events of a 2025-01 run, alternative hit selector):

now with the fix
1048 three-root calls, all beyond 0.2 rad a distance no answer
events with changed wire-based tracks - 26 of 998
wire-based and time-based tracks 4715 and 10568 4725 and 10580

Plot: BH-905: the three-root check is the wrong way round; with the fix 1048 distances become no answer and tracks change in 26 of 998 events

BH-905. Constructed cases, the calls on 1000 raw events, and track counts with the alternative hit selector.
Limits: one run.

Who is affected. Jobs run with the alternative hit selector, a switch the code offers on the command line; the
selector drops a hit whose distance is no answer.

Who is not. Standard reconstruction, REST files and analyses: the default hit selector uses another distance
routine.

The fix. Turn the test round.

Grade S3 (third of four; S1 is the most severe), on jobs that select the alternative hit selector: wire-based
tracks change in 26 of 998 events (32 at release 5.9.0). Fit quality is unchanged, so the data do not tell which side
is better.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-43d-disttort-three-root-angle-check-inverted/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-43d-disttort-three-root-angle-check-inverted

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-48 S3 (commit f4e661c)

The energy-loss density correction compares ln I with a threshold off by a factor of 10

What is wrong. The density-effect correction of the track fit's energy loss takes one form for materials whose
mean excitation energy I is below 100 eV and another above. ln I is held with I in GeV (100 eV is -16.118), but the
test is against -1.6118, so every solid takes the low form: aluminium, copper and the like lose up to 3% more energy
in the fit than with the fix.

The code (the same test sits in two more places;
on GitHub):

  double Cbar=2.*(LnI-log(28.816e-9*sqrt(rho_Z_over_A)))+1.;   // (added:) ln I in GeV, plasma energy 28.816 eV
  if (rho_Z_over_A>0.01){ // not a gas
    if (LnI<-1.6118){ // I<100          // (added:) true for every solid; ln(100 eV) is -16.118
      if (Cbar<=3.681) X0=0.2;
      else X0=0.326*Cbar-1.;
      X1=2.;
    }
    ...

Fixed:

    if (LnI<-16.118){ // I<100 eV (ln of I in GeV)

What it does (BH-T80; the code's formulas and the run 132404 maps; data: run 132404, 1000 events, 998 event
numbers in both outputs; main site only):

now with the fix
density correction, pion of 1 GeV/c in aluminium (tabulated 1.01) 0.58 1.19
energy lost by a straight 1 GeV/c pion in the tracking volume, 8-90 degrees 6.96-38.32 MeV 0.03-0.66 MeV less (at most 0.07% of p; resolution about 2.6%)
data events whose track fit moves by more than one printed digit 359 of 998
fits whose printed momentum changes, of 10452 paired 545 (5%), half of them by 1-2 MeV

Plot: BH-301: density correction in aluminium, and the change of energy loss

BH-301. Computed from the code's formulas, not measured. Top: the correction in aluminium, today, fixed, tabulated.
Bottom: change of the local dE/dx with the fix (lower is less energy loss); the whole-track change is far smaller.

Who is affected. Every analysis with charged tracks, release 5.9.0 and master, data and simulation. Changed pion
fits lean lower (109 of 180).

Who is not. Photon-only analyses, but for track matching (neutral showers change in 15 of 998 events).

The fix. Write -16.118 in the three places (measured at the main one).

Grade S3 (third of four): track fits move beyond one printed digit in 36% of events; track counts by 0.11%. No
physics effect was measured, and no truth check was run.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-48-density-effect-ln-i-threshold-factor-10/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-48-density-effect-ln-i-threshold-factor-10

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-49 S3 (commit e26cea8)

Some track fits store a time of about one million nanoseconds

What is wrong. The track fit takes a track's time from the earliest CDC or FDC drift time along its path,
searching down from 1 000 000 ns. When no step of the path carries such a hit, that start value becomes the track
time and the start time of later fits and matches: 2.5% of time-based fits with today's code, 1.3% in the 2025-01
pass.

The code. The real lines, shortened (on GitHub):

mT0MinimumDriftTime=1e6;                   // start value of the search
...
mT0MinimumDriftTime+=mT0;                  // <-- used even when the search found no hit
fit_params.setTime(mT0MinimumDriftTime);
fit_params.setT0(mT0MinimumDriftTime,4.,mT0Detector);

With the fix:

if (mT0MinimumDriftTime<1e6){ ... the three lines above ... }
else{                                      // no drift time found: keep the start time the fit used
  fit_params.setTime(mT0);
  fit_params.setT0(mT0,input_params.t0_err(),input_params.t0_detector());
}

What it does. Track fits near 1 000 000 ns in the reduced (REST) output of 1000 events: 256 of 10 342 today,
none with the fix. Benchmark reactions:

1M raw events of run 132404, master; same events, σ from events gained and lost:

reaction today → fixed change
ω → π⁺π⁻π⁰ 7996 → 8068 +0.9%, 5.5σ
ρ → π⁺π⁻ 12696 → 12744 +0.4%, 3.3σ
φ → K⁺K⁻ 6118 → 6173 +0.9%, 4.8σ

Not moving: π⁰ → γγ, η → γγ, e⁺e⁻ and ω → π⁰γ (below 3σ: at most +1.1%, 1.2σ).

Plot: BH-543: 1061 simulated track times at the placeholder today, none with the fix

BH-543. 4000 simulated events, one sample; momentum and angle are in the details.

Who is affected.

  • Users of a charged track's time or start counter match from reduced files: these tracks lose the match.
  • Reactions with charged pions or kaons: 0.4 to 0.9% more events with the fix. Not measured: whether these are
    signal, and whether a yield corrected with simulation, which loses the same tracks, moves.

Who is not. Track momentum and angle.

The fix. Keep the fit's start time when no drift time was found.

Grade S3 (third of four levels, S1 the widest): objects change in 159 of 998 events. A benchmark move of 1% or
more would make it S2; these moves, at most +0.90%, sit under that line by less than one statistical error.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-49-kalman-t0-sentinel-reaches-tracks/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-49-kalman-t0-sentinel-reaches-tracks

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-51 S3 (commit 256b429)

CDC stereo points of the track-candidate refit are placed beyond the track's crossing

What is wrong. When a track candidate joins FDC and CDC hits, its helix is refitted, and each CDC stereo wire
gives a point where the wire crosses the track circle. The code finds the distance d along the wire to that crossing,
then divides it by cos(stereo) a second time. The point stays on the wire but lands beyond the crossing, off the circle, with its z offset
from the wire centre stretched by 1/cos(stereo), 0.55% at 6 degrees. Release 5.9.0 has the same line.

The code. The real lines, shortened (on GitHub):

DVector3 dir = wire->udir;            // unit vector along the wire
...                                   // solve |origin + dz*dir - centre| = radius, in x and y
double dz1 = (b-B)/temp1;
double dz2 = (b+B)/temp1;
...                                   // dz: the root nearer the wire centre, already a distance along the wire
double s=dz/cos(wire->stereo);        // <-- divided again: s is too long by 1/cos(stereo)
DVector3 pos = origin + s*dir;

Fixed:

double s=dz;

What it does. 1000 events of run 132404 (2025-01):

today fixed
stereo points over 0.01 cm from the crossing (test program, every stereo hit; the refit accepts 3904) 22851 of 23780 (median 0.146 cm) 0 of 23828
track candidates changed 312 of 4992, in 252 of 998 events
time-based tracks 10510 10502

Benchmark reactions:

No benchmark reaction moves beyond the run-to-run noise (1M raw events).

Plot: BH-554: a CDC stereo point is stored past the wire-circle crossing, 0.22 cm at 40 cm

BH-554. Where the point is stored today and with the fix, drawn with an enlarged angle; measured distances on the figure.

Who is affected.

  • Anyone using track candidates that join CDC and FDC hits: their slope tan(dip) moves by 1.2e-4 of its value and
    their z by 0.09 mm (medians).
  • Analyses of final tracks: a few tracks are gained or lost in the fit (time-based tracks 10510 to 10502).

Who is hardly affected. Physics yields: no benchmark reaction moves. In 4000 simulated events the fixed tracks lean
closer to truth, below 3 standard deviations (at most 2.0).

The fix. Drop the second division.

Grade S3 (third of four levels, S1 the most severe): candidates change in a quarter of the events; no count or
yield moves by 1%.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-51-helicalfit-stereo-distance-divided-twice/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-51-helicalfit-stereo-distance-divided-twice

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-52 S3 (commit 48d9897)

Field-off track fits lose the detector of the start time

What is wrong. With the solenoid off, tracks are fitted as straight lines. The time-based fit is told which
detector gave the start time and adds its time resolution to each CDC hit error. A newer
version of the fit function takes an extra argument before the detector; this one call was not updated. The detector
code lands in the new slot, which the straight-line fit never reads; the detector slot gets "none", so the fit adds
no start-time error and takes the start time as exact. Release 5.9.0
of the 2025-01 pass is not affected; master and release 5.16.0 are.

The code. The real lines (on GitHub):

// the fit function, master: a start-time error was added before the detector
FitTrack(pos, mom, q, mass, double t0, double t0_sigma, DetectorSystem_t t0_det=SYS_NULL);

// the field-off call, written for the old argument list
fitter->FitTrack(pos,dir,1.,0.,t0,t0_detector)     // <-- the detector goes into t0_sigma

Fixed:

fitter->FitTrack(pos,dir,1.,0.,t0,Quiet_NaN,t0_detector)   // NaN: the unused default; the error comes from the detector

What it does. Field-off run 133609 (2025-01), first 10000 events; two runs of today's code are identical:

field-off time-based tracks today with the fix
tracks 18247 18315
events that change 4194 of 10000
tracks whose fit chi2 falls / rises 6076 / 459

A lower chi2 is expected once hit errors grow; it does not say which fit is right.

No benchmark reaction moves beyond the run-to-run noise (2.4M raw events, field off).

Plot: BH-558: with the fix the fit chi2 falls in 6076 field-off tracks and rises in 459

BH-558. Change of the fit chi2 per field-off track, fix minus today.

Who is affected. Anyone reconstructing field-off runs with master or 5.16.0, mostly for alignment: these are
then the default tracks. Which passes did is not known.

Who is not. Field-on data and simulation, and every job of release 5.9.0.

The fix. Pass the detector in its own argument (one line).

Grade S3 (third of four levels, S1 the most severe), graded on field-off jobs: tracks change in a minority of
events (42%; 37% leaving out fits whose chi2 alone changes). No benchmark reaction moves.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-52-straightline-t0-detector-into-t0-sigma/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-52-straightline-t0-detector-into-t0-sigma

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-11 S4 (commit 8204e73)

CDC hit pulls get their track error from a matrix the smoother has already overwritten

What is wrong. After a central track is fitted, the smoother walks back along it and, at each CDC hit, computes
the pull: residual over the error of hit minus track. To get the track error at the wire it moves the track's error
matrix there in place, so the moved matrix travels on to the next hit as if it belonged to the trajectory. The track
state is moved in a copy; the error matrix is not.

The code (on GitHub):

DMatrix5x1 myS=Ss;                   // the state goes to the wire in a copy
...
double Vhit=cdc_updates[id].variance;
Cs=Jc*Cs*Jc.Transpose();             // <-- the smoother's own error matrix is overwritten
double Vtrack=H*Cs*H_T;

With the fix:

DMatrix5x5 myCs=Jc*Cs*Jc.Transpose();   // a copy, as for the state
double Vtrack=H*myCs*H_T;

What it does (1000 raw events of run 132404, 2025-01):

today with the fix
CDC hits whose track error comes from the overwritten matrix 18322 of 19598 0
CDC hits whose pull error is undefined (negative variance) 296 97
monitoring pulls: half width of the central 68% (error about 0.008) 0.9895 0.9883
events with a changed track, shower or particle 0 of 998 0 of 998

Plot: BH-881: 18322 of 19598 CDC hits get their track error from an overwritten matrix; 0 with the fix

BH-881. Smoothed CDC hits of 1000 raw events, today and with the fix. Dashed: the count expected from the
smoother's own matrix.

Who is affected.

  • Anyone using CDC pulls: the tracking-pull monitoring and the CDC alignment plugins, in the 2025-01 pass (release
    5.9.0) and the current release. By reading the code, these skip a whole track when one pull error is undefined.

Who is not. Tracks, showers, particles, reduced (REST) files and analysis trees: the smoother feeds only the
pulls. No benchmark reaction moves beyond the run-to-run noise (1M raw events).

The fix. Move a copy of the error matrix to the wire.

Grade S4 (lowest of four): 0 of 998 events change a reconstructed object; only monitoring and alignment inputs
move.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-11-smoothcentral-overwrites-smoothed-covariance/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-11-smoothcentral-overwrites-smoothed-covariance

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-13 S4 (commit 4527943)

A rare fallback of the track finder gives forward track candidates a polar angle of 32 to 43 degrees

What is wrong. The track finder refits candidates that join CDC and FDC hits. When the straight-line part of
that refit fails, a starting slope taken from the forward candidate stays in use. The formula takes the arctangent
of the angle where its cotangent belongs, so any forward angle from 0 to 30 degrees becomes 32.5 to 42.6 degrees.

The code (on GitHub):

// Initialize fit.tanl in case new line fit does not work
fit.tanl=M_PI_2-atan(fdccan->dMomentum.Theta());   // <-- pi/2 minus the arctangent of an angle
fit.FitLineRiemann();                               // leaves this slope as it is when it fails

With the fix, the cotangent, the form the same code uses elsewhere for this slope:

fit.tanl=tan(M_PI_2-fdccan->dMomentum.Theta());

What it does (track candidates that take the fallback):

today with the fix
2025-01 data, 99 998 events: polar angle of the 6 changed candidates 32.6 to 42.6 deg 0.5 to 30.0 deg
constructed candidates at 5, 10, 20 deg 34.0, 35.6, 39.0 deg 5, 10, 20 deg
same data: events whose final charged tracks change 2 of 99 998

Plot: BH-887: all 6 changed candidates sit at 32.6 to 42.6 deg today; with the fix 0.5 to 30.0 deg

BH-887. The 6 track candidates the fix changes in the first 100 000 events of a 2025-01 raw file, today and with
the fix (event numbers are the run's own and go past 100 000). Grey band: the only angles today's fallback can give.

Who is affected.

  • Anyone who studies track finding: the candidate's angle and momentum seed the first track fit.

Who is not. Physics results: no benchmark reaction moves beyond the run-to-run noise (1M raw events, 2025-01
data). The 2025-01 pass (release 5.9.0) used an older finder without this fallback.

The fix. Use the cotangent of the forward candidate's angle.

Grade S4 (lowest of four): candidates change in 6 of 99 998 events, final tracks in 2; which side is closer to
the true track is not resolved.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-13-dorefit-tanl-fallback-wrong-formula/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-13-dorefit-tanl-fallback-wrong-formula

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-15 S4 (commit daf74d7)

Dense CDC regions are mostly not remembered, so outer layers start tracks there anyway

What is wrong. The CDC has seven rings of wire layers, called super layers. Where one super layer's hits are
too dense, the track finder drops the seeds there and remembers that stretch of angle, so the outer super layers
start no track in it. It never stores the last stretch of a super layer, stores the others one number low, and can
begin the first at a seed that was not dropped.

The code (on GitHub):

int locBeginIndex = -1, locPreviousIndex = 0, ...;   // <-- previous seed starts at seed 0
for(; locRejectIterator != locSeedsToReject.end(); ++locRejectIterator)
{
    ...
    // seed not next to the previous one: the stretch ends here
    dRejectedPhiRegions[locSuperLayer - 1].push_back(...);   // <-- stored one layer too low
    ...
}                                                            // <-- last stretch never stored

// the readers, later:
for(size_t loc_j = 1; loc_j < locOuterSuperLayer; ++loc_j)  ... dRejectedPhiRegions[loc_j] ...
... dRejectedPhiRegions[locSearchSuperLayer] ...

With the fix every stretch, the last included, is stored under its own number, from its first dropped seed.

What it does (1000 raw events of a 2025-01 run):

dense super layers (17, in 11 events) today with the fix
stretch stored under its own number 0 17
nothing stored (its only stretch is the last) 14 0
stretch stored one number low 3 0
events with changed candidates; final tracks 2; 1 of 998

Plot: BH-893: dense CDC super layers whose stretch is stored under their own number, 0 of 17 today, 17 of 17 with the fix

BH-893 version 2. Every dense super layer in 1000 raw events and what is stored for it. The three faults were not
run apart. Limits: one run at 2025-01 rate.

Who is affected.

  • Track finding in events with dense CDC hits: in the 2025-01 pass (release 5.9.0) and in the current release
    (version set 7.10.0).

Who is not. Physics analyses at 2025-01 rate: no benchmark reaction moves beyond the run-to-run noise (1M raw
events). Higher rate was not checked.

The fix. Store every stretch, the last one included, under its own super layer and with its true edges.

Grade S4 (lowest of four): track candidates change in 2 of 998 events (0.2%), final tracks in 1. It says nothing
about physics weight.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-15-cdc-rejected-phi-regions-misindexed/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-15-cdc-rejected-phi-regions-misindexed

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-17 S4 (commit 27427c7)

A rare fallback of the CDC track finder gives every circle it fits the same charge

What is wrong. The CDC track finder fits a circle to each track seed. When that fit fails, a second circle fit
takes over, and the code then picks the sense of rotation, and with it the charge, by comparing the hits with a helix
of each sense. That comparison needs the track's dip slope, which is not fitted yet and is still zero. The result is
"not a number", and the code falls to the same sense for any hits.

The code (on GitHub):

if(locFit->FitCircleRiemann(TARGET_Z, locBeamRMS) != NOERROR)
{
    if(locFit->FitCircle() != NOERROR)
    {
        ...                                   // straight-line fit, or give up
    }
    else
        locFit->FindSenseOfRotation();        // <-- needs the dip slope, still 0 here
}
else
    locFit->GuessChargeFromCircleFit(); // for Riemann fit

With the fix, the fallback takes the charge from the circle, as the first fit does:

        locFit->GuessChargeFromCircleFit();

What it does:

today with the fix
constructed tracks and their mirror images: same sense for both 3 of 3 0 of 3
2025-01 data, 998 events: candidates that change 1, charge -1 to +1
that candidate starts moving toward the beam line away from it
same data: tracks that change 0

Plot: BH-889: the one candidate the fix changes in 998 events, today moving inward, with the fix outward

BH-889. The changed candidate (5 CDC hits) seen along the beam, start point and direction today and with the fix.
The finder assumes its hits come from the outgoing part of the track.

Who is affected.

  • Anyone who studies CDC track finding: the branch is rare, and its candidates are short.

Who is not. Final tracks and physics: the changed candidate makes no track, and no benchmark reaction moves
beyond the run-to-run noise (1M raw events, 2025-01 data).

The fix. Take the charge from the circle in the fallback too.

Grade S4 (lowest of four): one candidate changes in 1 of 998 events, nothing downstream. Present in release 5.9.0
of the 2025-01 pass.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-17-cdc-fallback-circle-charge-fixed/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-17-cdc-fallback-circle-charge-fixed

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-21 S4 (commit 2480c40)

One forward track piece can be joined to two central track candidates at once

What is wrong. The track finder joins forward (FDC) track pieces to central (CDC) track candidates. Once a pair
matches, both are marked as used, but the search goes on through the remaining central candidates with the same
forward piece. A second central candidate that passes the cuts gets a copy of the same forward hits, so one forward
track ends up in two candidates.

The code (on GitHub):

for (unsigned int i=0;i<fdctrackcandidates.size();i++){      // forward pieces
  if (fdc_matches[i]) continue;
  ...
  for (unsigned int j=0;j<cdctrackcandidates.size();j++){    // central candidates
    if (cdc_matches[j]) continue;          // <-- only the central side is checked
    ...
    if (num_matches>=3){
      ...                                  // joined candidate gets the forward hits
      Insert(can);
      fdc_matches[i]=1;
      cdc_matches[j]=1;
                                           // <-- no break: the same piece is tried on the next j
    }
  }
}

With the fix the inner loop stops after the first match:

      break; // this FDC candidate is used up

What it does (998 raw events of a 2025-01 run):

today with the fix
forward pieces in two candidates 2 0
events with changed tracks 2

Plot: BH-878: a forward piece joined to a second central candidate; chi-square per degree of freedom 39.5 and 1.34 today, 0.84 and 1.03 with the fix

BH-878. The two candidates that take a forward piece a second time, today and with the fix. Today's and fixed
values are fits of different hit sets; the simulation truth does not decide. Limits: two events, one run.

Who is affected.

  • Anyone studying track finding where forward and central track pieces meet, in the current release (version set
    7.10.0).

Who is not. Physics analyses: no benchmark reaction moves beyond the run-to-run noise (1M raw events). The number
of final charged tracks does not change. The 2025-01 pass (release 5.9.0) joins pieces with older code.

The fix. Stop the search once a forward piece is joined.

Grade S4 (lowest of four): tracks change in 2 of 998 events (0.2%). It says nothing about physics weight.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-21-fdc-candidate-merged-into-several-cdc/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-21-fdc-candidate-merged-into-several-cdc

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R3-22 S4 (commit ab162f7)

Forward track candidates that pick up stray CDC hits keep the fit quality and charge of the FDC fit alone

What is wrong. The track finder gives CDC hits that no candidate uses ("stray" hits) to a forward (FDC)
candidate. With three or more it refits the circle and takes the new circle and momentum, but copies fit quality
(chi-square, degrees of freedom) and charge from the old FDC-only fit. The quality ignores every CDC hit, and the
charge need not match the curvature.

The code (on GitHub):

if (num_axial>2){ // Refit if we added several cdc axial hits
  DoRefit(fit,fdccan,fdchits,cdchits,mom,pos);   // new circle, momentum and sense of rotation
...
can->chisq=fdccan->chisq;       // <-- taken from the FDC-only fit, after the refit
can->Ndof=fdccan->Ndof;
can->dCharge=fdccan->dCharge;

With the fix, after a refit (as the code already does for the other matching step a few lines above):

can->chisq=fit.chisq;
can->Ndof=fit.ndof;
can->dCharge=FactorForSenseOfRotation*fit.h;

What it does (track candidates the fix changes):

today with the fix
simulation, 4000 events: candidates whose degrees of freedom count all their CDC hits 0 of 749 591 of 749
2025-01 data, 998 events: the same 0 of 90 62 of 90
simulation: median chi-square of these candidates 15.58 18.55
simulation: candidates that change charge 7 of 749

Plot: BH-525: today no changed candidate counts its CDC hits; with the fix 591 of 749 count them all

BH-525. Candidates by CDC hits the fit quality leaves out. With the fix these are, by reading, stereo hits, added
after the circle fit.

Who is affected.

  • Anyone who reads or cuts on track-candidate fit quality, or studies track finding.

Who is not. Final tracks and physics. Later fits start from the candidate's charge but refit the hits: a charge
change altered a first-pass fit in 1 of 4000 simulated events and no final track. No benchmark reaction moves beyond
the run-to-run noise (1M raw events), on 2025-01 data. The 2025-01 pass (release 5.9.0) used an older finder.

The fix. After a refit, take chi-square, degrees of freedom and charge from the refit.

Grade S4 (lowest of four): the changed values stay inside the reconstruction; no file or final track carries
them.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r3-22-unused-cdc-refit-takes-fdc-values/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-22-unused-cdc-refit-takes-fdc-values

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

DraTeots and others added 8 commits December 1, 2026 18:15
… hit

`libraries/TRACKING/DTrackHitSelectorALT2.cc`, `GetCDCHits` and `GetFDCHits` (the versions that take a reference
trajectory, used by the wire-based fit): the values of pt/a, p/a and a/p at the track's start are kept in three
constants before the hit loop, and each hit sets `p_over_a=p_over_a_0*invBratio` (and the same for the other two)
instead of multiplying in place. One line added and three changed in each of the two functions. `patches/master.patch` for master,
`patches/r5.9.0.patch` for release 5.9.0 (same lines, nine lines later). This is the smallest change that gives each
hit one ratio, the local-field one the lines already compute; the error model itself is left as it is.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-2-alt2-field-ratio-compounded/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-2-alt2-field-ratio-compounded

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two patches, one cause each, both in `libraries/TRACKING/DTrackFitterKalmanSIMD_ALT1.cc`.

- `patches/master.patch` (doca): `StepJacobian(z,newz,...)` and `Step(z,newz,...)` in the piecewise doca loop become
  `StepJacobian(my_z,newz,...)` and `Step(my_z,newz,...)`. The loop already advances `my_z`, and the remainder step
  after it already starts from `my_z`. Applies unchanged to release 5.9.0 (same lines).
- `patches/master-t0-companion.patch` (time): the three `-mT0` terms of the FDC and CDC updates are removed, since the
  hit objects of the base fitter already carry the subtraction at master. For master only: at 5.9.0 the hit objects
  keep the raw times, and these lines are the only subtraction.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-32-alt1-finddoca-step-and-double-t0/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-32-alt1-finddoca-step-and-double-t0

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…) where α is needed

`libraries/TRACKING/DTrackFitter.cc`, `ExtrapolateToRadius`: `double ds=alpha*delta.Mag();` in place of
`(1.-alpha)*delta.Mag()`, so that s and t are corrected by the same fraction of the step as the position. One line.
`patches/master.patch` for master, `patches/r5.9.0.patch` for release 5.9.0 (same line, 546).
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-37-extrapolate-to-radius-alpha/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-37-extrapolate-to-radius-alpha

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s below THETA_CUT (save block inside the FDC branch)

`src/libraries/TRACKING/DTrackFitterKalmanSIMD.cc`, `KalmanLoop`: the branch `if (my_fdchits.size()>0){` now closes
before the store of the forward-CDC fit, which becomes a block of its own, so the forward fit is stored for tracks
with and without FDC hits. One brace moved, one brace and a comment added; the stored fields are unchanged. This is
the minimal change: the comparison at lines 3486 and 3512 is already written for every track. `patches/master.patch`
for master, `patches/r5.9.0.patch` for release 5.9.0 (the same lines two earlier). The result does not depend on the
order of hits or tracks.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-4b-forward-cdc-fit-never-saved/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-4b-forward-cdc-fit-never-saved

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…root branch; last_swim_step set before NaN returns

`libraries/TRACKING/DReferenceTrajectory.cc`: `fabs(phi)>=0.2` instead of `fabs(phi)<0.2` before the NaN return of
the three-root branch, matching the one-root branch and the small-angle expansion both evaluate. One line. The patch
applies to master and to release 5.9.0 unchanged.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-43d-disttort-three-root-angle-check-inverted/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-43d-disttort-three-root-angle-check-inverted

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry non-gas material takes the low-I branch

One literal in `DTrackFitter::CalcDensityEffect` (run), and the same literal in `DReferenceTrajectory::dPdx` and
`DParticleID::GetScintMPdEandSigma` (not run; the scintillator lies below 100 eV either way).

Effect: materials above 100 eV take the X1 = 3 branch; pion dE/dx in aluminium at 1 GeV/c 2.7% lower, delta 0.58 ->
1.19 (tabulated 1.01). Run 132404, 1000 events: time-based fits change in 733 of 998 events, 545 of 10452 paired fits
change printed momentum; fit quality unchanged. Not checked against truth.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-48-density-effect-ln-i-threshold-factor-10/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-48-density-effect-ln-i-threshold-factor-10

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e sentinel reaches DTrackTimeBased on the refit path

`libraries/TRACKING/DTrackFitterKalmanSIMD.cc`: the track time and t0 take the earliest drift time only when the
search found one (`mT0MinimumDriftTime < 1e6`); otherwise they keep the start time the fit used, with its error and
detector. `patches/master.patch` for master, `patches/r5.9.0.patch` for release 5.9.0, where the code differs
(5.9.0 does not add `mT0` back).
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-49-kalman-t0-sentinel-reaches-tracks/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-49-kalman-t0-sentinel-reaches-tracks

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e by cos(stereo) a second time, so every CDC stereo point of a FDC+CDC candidate refit sits off the wire-circle intersection and its z is stretched by 1/cos(stereo)

`libraries/TRACKING/DHelicalFit.cc`: `s = dz` instead of `dz/cos(wire->stereo)`; `dir` is the unit wire vector, so
the root of the quadratic is the distance along the wire. One line. `patches/master.patch` for master,
`patches/r5.9.0.patch` for release 5.9.0 (the debug print next to the line differs there).
Card: https://pages.jlab.org/halld/auto-hunt/cards/r3-51-helicalfit-stereo-distance-divided-twice/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TRACKING/r3-51-helicalfit-stereo-distance-divided-twice

Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DraTeots DraTeots changed the title auto-hunt: TRACKING - 49 fixes (S1 2, S2 8, S3 13, S4 26) auto-hunt: TRACKING - 19 fixes (S1 1, S2 6, S3 12) Dec 1, 2026
@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you. The pull request is now split three ways:

Each commit is cherry-picked unchanged; the patch ids are identical to the old 49 commits. No pick conflicted, so nothing was ported by hand. The three branches merge in any order without conflict, and their merge equals the old branch file for file. Every changed source file passes a syntax-only compile against the release headers at each branch tip. The card comments posted here earlier carry the old commit hashes. The 30 findings that moved have their comments posted again in #1263 and #1264.


Created by Autonomous HallD "auto-hunt" campaign (executed by Claude)

@gluex

gluex commented Dec 1, 2026

Copy link
Copy Markdown

Test status for this pull request: SUCCESS

Summary: summary.txt
Logs: results/log

Build log: make_auto-hunt_tracking.log
Build report: report_auto-hunt_tracking.txt

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

R3-43i: Yes, it's good to make the meaning of FOM in this context consistent.

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

R3-41. Yes, it makes the command-parameters for the DReferenceTrajectory actually useful.

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

R3-48: yes, this gives a better approximation and appears to be consistent with what is done elsewhere, e.g. in geant4

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

R3-32: Yes. This alternate fitter is deprecated and will eventually be removed.

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

R3-10: Yes -- this fixes a typo.

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

R3-9: Yes, this fixes a typo.

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

R3-6: yes, looks like a good fix.

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

R3-12. Yes. Now dEdx is handled consistently.

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

R3-37: yes, looks good.
R3-43d: yes, fixes logic flaw

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

R3-19: Yes, this restores the intended behavior as implemented in the earlier release.

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

R3-51 fix okay

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

R3-4b. Looks okay. The fits that trigger this condition are not very good, but it looks like there is some recovery/improvement.

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

R3-49. Yes, this gets rid of some ridiculous timing values. I plan to revisit how the minimum drift time is found later.

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

Just as a quick test: running p2pi_hists on one run (120400) from 2023 for MC and real data:
Computing rho yields/1 k events
master this_PR ratio
MC 291.0 296.5 1.019 (only 100 k events were simulated)
Data 5.04 5.21 1.034 (one full run)

In both cases the yields go up. It will need further study to determine if the difference between the gain improvements is significant.

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

R3-2. Yes, seems okay.

@staylorjlab
staylorjlab merged commit 207f22e into master Dec 3, 2026
2 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.

3 participants