Skip to content

auto-hunt: kinematic fit with a missing recoil (issue 733) - 2 fixes (S2 1, S4 1) - #1268

Open
DraTeots wants to merge 2 commits into
masterfrom
auto-hunt/kinfit-gh733
Open

DraTeots wants to merge 2 commits into
masterfrom
auto-hunt/kinfit-gh733

Conversation

@DraTeots

@DraTeots DraTeots commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Addresses part of #733.

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. Full cards with plots are on the campaign pages (JLab login): https://pages.jlab.org/halld/auto-hunt/index.html

What is left of #733

The issue's own channel, g p -> pi0 (p missing), is not fixed here. There a single mass-constrained pi0 carries all the measured errors of the p4 constraint, because the beam photon has no errors in the fit. The 4 p4 rows and the pi0 mass row then depend on the photons only through the pi0 4-vector, so S = D V D^T is singular (rank 4 for 5 rows). The fitter's guard removes the pi0 mass constraint to avoid that, silently. A 2C fit for that channel needs a change at the fitter level. The options are in a comment on #733 and are a choice for the maintainers. This pull request fixes the case where the guard is too broad: two or more constrained decaying particles.

Overall gains

2 confirmed bugs fixed in this pull request (S2 1, S4 1), one commit each, most serious first.

finding grade what was wrong the fix
GH-733 S2 In g p -> pi0 pi0 (p missing) no particle of the p4 constraint carries its own errors, so the fitter treats the system as over-constrained and deletes the first pi0's mass constraint. With two constrained pi0s the matrix is not singular, so the deletion is not needed. NDF is 2 instead of 3, and one fitted photon pair comes out at 163.3 / 39.6 MeV (mean / rms) instead of m(pi0). The fit also depends on the order of the two pi0s, so 50% of combos differ between two identical runs. The same holds for other fits with a missing recoil whose measured particles all sit in two or more mass-constrained decays, for example pi0 eta (p) or K_S K_S (p). Keep every mass constraint when two or more mass-constrained decaying particles carry the errors (production-step p4 constraint only).
GH-733b S4 When S looks singular, Calc_dS lowers the tolerance on dS so it passes the checks, but dS_Inverse = dS copies only the elements. The inversion then runs at the normal tolerance and fails, ROOT leaves the matrix unchanged, and the fit goes on with S in place of S^-1 and reports a result. On the data measured here it was not met (0 in 1.6 M events). The e+e- pair fit meets it 6-16 times per 1000 raw events, with no output change above noise. In a test that keeps the single-pi0 mass constraint, all 671 such fits came out with chi2 below 1e-5 and CL = 1. Invert with TDecompLU::InvertLU on a copy and keep its status. Reset both tolerances. Return false on failure, so the fit ends with d_KinFitFailedInversion.

Related findings and commits that belong together

  • GH-733b is the same change as R7-26 (found earlier by the bug hunt in the e+e- fit, with no output change above noise there). It is committed once, under GH-733b. Kinematic fit over constrained in fitted pi0 channels? #733 adds the reason the inversion fails after the determinant check has passed: dS.SetTol(...) lowers the tolerance on dS, but dS_Inverse = dS copies only the elements. dS_Inverse keeps the default tolerance, so Invert() fails for exactly the matrices the lowering was meant to let through.
  • The two commits are independent. Kinematic fit over constrained in fitted pi0 channels? #733 does not make S singular (two constrained pi0s), so it does not rely on GH-733b. GH-733b guards every fit, including any future change that keeps a constraint the guard now removes.
  • The open pull request auto-hunt/kinfitter (auto-hunt: KINFITTER - 8 fixes (S4 8) #1249) touches other lines of DKinFitter.cc. The two pull requests do not overlap.

How it was tested

  • Run 132404 of 2025-01 (REST), first 400 000 events of each of 4 files (1.6 M events), calibtime 2025-12-24-00-00-01, the same CCDB for every arm. ReactionFilter fits of g p -> pi0 (p missing) with the pi0 mass constrained (B2, F1) and free (M7), g p -> pi0 pi0 (p missing) (B2, F1), and g p -> pi0 p (F1). Master was run twice to measure noise.
  • Kinematic fit over constrained in fitted pi0 channels? #733: pi0 pi0 (p): NDF 2 -> 3. The first fitted photon pair goes from 163.3 / 39.6 MeV (mean / rms) to 134.977 / 0.059 MeV, and the two pairs are within 0.1 MeV of m(pi0) in 99.92% and 99.86% of combos. chi2 rises in 99.5% of matched combos. Combos with CL > 0.01: 5901 -> 4077 (-31%; -5% between two identical master runs). Combos written: 64 050 -> 63 091 (fits that fail or do not converge with the extra constraint; 0.16% between identical runs). Two master runs differ in 50% of matched combos, because the pi0 that loses its constraint depends on the pi0 order. Two patched runs differ in 0.04%. The single-pi0 and detected-proton reactions are unchanged beyond noise. Expectations were written before the runs.
  • GH-733b: master plus the patch on the same 1.6 M events: 0 failed inversions, and every output equals master within the noise of two identical master runs. Test arm (50 000 events, a test-only change keeping the single-pi0 mass constraint): without the fix, 1342 inversions left S unchanged and all 671 single-pi0 combos were written with chi2 below 1e-5 and CL = 1. With the fix, 670 failed inversions were reported and none of those combos was written. The pi0-mass-free fit, pi0 pi0 (p) and pi0 p are unchanged. A direct call of Calc_dS's steps on the logged matrix shows that the copy keeps tolerance 2.2e-16 while dS has 1.1e-17, that Invert() returns the matrix unchanged, and that the patched route reports the failure.

Not tested: no simulation check of the CL distribution for true pi0 pi0 p events (the data sample has no pi0 or missing-mass selection and is mostly background). Decay-step p4 constraints with two constrained decaying products keep the old behaviour. This branch (both commits, on master c6ad386) builds: its ANALYSIS and KINFITTER libraries were compiled into the campaign's master tree with g++ 13 (BUILD EXIT 0, 2026-12-02); it was not run as a whole. An earlier test build carried GH-733b's change together with a broader form of GH-733's rule (it also kept the single-pi0 constraint, for the test arm above). In it, pi0 pi0 (p) with both mass constraints had 0 failed inversions and the same fit in 1857 of 1858 combos. The physics benchmark was not run.


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

🤖 Generated with Claude Code

DraTeots and others added 2 commits December 2, 2026 00:48
… pi0 (p) although the fit is not singular there

Create_Constraints and Get_ConstraintInfo (DKinFitUtils_GlueX.cc): when no particle of the p4 constraint has its own
errors but two or more mass-constrained decaying particles are in it, and the p4 constraint is the production step,
the system is not treated as over-constrained and no mass constraint is deleted. With one such particle nothing
changes (the deletion avoids a singular matrix there). Measured on 1.6 M events of run 132404: NDF 2 -> 3, the first
fitted photon pair 163.3 / 39.6 MeV -> 134.977 / 0.059 MeV, the fit no longer depends on the pi0 order.
Relates to #733; the issue's own channel (one pi0, missing proton) is not fixed.
Card: https://pages.jlab.org/halld/auto-hunt/cards/gh-733-pi0pi0-missing-proton-mass-constraint-dropped/

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the inversion of S fails

DKinFitter::Calc_dS lowers the tolerance on dS, but dS_Inverse = dS copies only the elements, so the inversion runs
at the default tolerance, fails, and leaves S in place of S^-1; the fit goes on and reports a result. Now a copy is
inverted with TDecompLU::InvertLU, its status is kept, both tolerances are reset, and a failed inversion ends the fit
with d_KinFitFailedInversion. Same change as R7-26 of the campaign table.
Card: https://pages.jlab.org/halld/auto-hunt/cards/gh-733b-kinfit-failed-inversion-used-as-inverse/

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DraTeots

DraTeots commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Two-pi0 kinematic fits with a missing proton drop one pi0 mass constraint

What is wrong. In the fit of g p -> pi0 pi0 (p missing) the fitter deletes the first pi0's mass constraint,
although the fit would work with it. One fitted photon pair is then off the pi0 mass. This card fixes the two-pi0
case. The issue's own channel (one pi0, missing proton) is NOT fixed: there the deletion avoids a singular matrix.

The code (on GitHub):

if(!locNonZeroErrorFlag)   // "over-constrained": no particle with its own errors
  locMassConstraints.erase(locStepMassConstraintMap[locEarliestStepIndex]);  // <-- also for two pi0s

Fix, added before it (two constrained decays leave the matrix invertible):

if(!locNonZeroErrorFlag && (locP4StepIndex == 0) && (locP4ConstrainedParticleSteps.size() >= 2))
    locNonZeroErrorFlag = true;

What it does (pi0 pi0 (p) combos, 1.6 M events):

now fixed
degrees of freedom 2 3
first fitted pair mass, mean / rms 163.3 / 39.6 MeV 134.977 / 0.059 MeV
combos with CL > 0.01 5901 4077 (-31%; -5% between two identical runs)
fit differs between two identical runs 50% 0.04% (file 000 only)

First fitted photon-pair mass of pi0 pi0 (p) combos: 163.3 MeV mean today, 134.977 MeV with the fix

Affected. Fits with a missing recoil where every measured particle sits in a mass-constrained decay, with two or
more such decays: pi0 pi0 (p), pi0 eta (p), K_S K_S (p). A CL cut keeps fewer combos.
Not affected. Fits with a detected proton or a charged track outside the constrained decays.

The fix. Keep every mass constraint when two or more constrained decays carry the errors.
Grade S2: the fit changes in every event of the reaction; 0.67% of all events.

Full card (JLab login): https://pages.jlab.org/halld/auto-hunt/cards/gh-733-pi0pi0-missing-proton-mass-constraint-dropped/


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

@DraTeots

DraTeots commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

A fit that cannot invert its matrix goes on and reports a result

What is wrong. When the matrix S of the kinematic fit looks singular, the fitter lowers a tolerance on S so it
passes its checks, then inverts a copy that keeps the normal tolerance. That inversion fails, ROOT leaves the copy
unchanged, and the fit uses S itself as its inverse and reports a result. The lowering never yields a real inverse.

The code (shortened, on GitHub):

dS.SetTol(minDiagElement/2);          // lower the tolerance on S so S passes the checks
...
dS_Inverse = dS;                      // copies the elements, not the tolerance
dS_Inverse.Invert();                  // fails at the normal tolerance, S left in place, status ignored
...
return true;                          // the fit goes on with S as its "inverse"

Fixed: invert the copy, keep the status, and return false when it failed, so the fit reports a failed inversion.

What it does (test arm, 50 000 events: a code change keeps a pi0 mass constraint that master removes):

single-pi0 combos written without the fix with the fix
mass constraint kept, all with CL = 1 671 0
mass-free fit (control) 673 673

On real data it is rare: 0 failures in 1.6 M events (three reactions, six fit set-ups).

A failed inversion is used as the inverse: 671 fits report CL = 1, none with the fix

Who is affected.

  • A fit that meets a singular matrix reports a result instead of failing. The e+e- pair fit meets it 6-16 times per 1000 raw events, with no output change above noise.
  • Any future change that keeps a constraint the fitter now removes.

Who is not. The fits measured here on real data.

The fix. Report the failed inversion; the fit fails. Inverting at the lowered tolerance instead is left to the authors.

Grade S4: no output changes above noise on real data. It does not say a published result moved.

Full card (JLab login): https://pages.jlab.org/halld/auto-hunt/cards/gh-733b-kinfit-failed-inversion-used-as-inverse/


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

@gluex

gluex commented Dec 2, 2026

Copy link
Copy Markdown

Test status for this pull request: SUCCESS

Summary: summary.txt
Logs: results/log

Build log: make_auto-hunt_kinfit-gh733.log
Build report: report_auto-hunt_kinfit-gh733.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants