Skip to content

auto-hunt: TOF - 9 fixes (S1 1, S2 2, S4 6) - #1257

Merged
zihlmann merged 11 commits into
masterfrom
auto-hunt/tof
Dec 2, 2026
Merged

zihlmann merged 11 commits into
masterfrom
auto-hunt/tof

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

Overall gains

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

finding grade what was wrong the fix
R4-9c S1 At each run start the TOF hit step reads which time-walk correction the run uses and switches that one on. It never switches the others off, and each hit takes the first one that is on, in a fixed order. In a job that reads a 2018 run (correction type 3) and then a 2025 run (type 4), the 2025 hits get the 2018 correction, and the job crashes in it after a few events: the old table has 44 bars, the 2025 TOF 46. Release 5.9.0 has the same lines. Switch all three corrections off before choosing one.
R4-12 S2 The TOF has a switch, on by default, documented to drop ADC pulses the fADC250 flags as faulty. The line that drops them is commented out, so the switch does nothing. Seven other detectors use the same switch and drop them. The TOF code elsewhere handles such pulses (zero peak, overflow), so keeping them may be meant; then the switch and its text are what is wrong. For the TOF experts: restore the line, or keep the pulses and make the switch say so.
R4-28 S2 A TOF bar is read at both ends. Two end hits close in time make a two-ended paddle hit; a hit with no partner should make a one-ended one. But "no partner" is tested as "no hit at all on the other end", so a hit whose other end fired at another time is lost. Release 5.9.0 has the same code. Count only an in-time partner as a match. Open: are late extra pulses particles or afterpulses?
R4-13 S4 The TOF paddle-hit code documents an option, TOF:TOF_POINT_TAG=TRUTH, that makes it build TOF paddle hits and points from the unsmeared simulated hits. The code reads the tag when it asks for the hits, but the option is never registered, so the tag stays empty and the smeared hits are used whatever the user sets. Release 5.9.0 has the same lines. Register the option the header describes. With the fix, 22% fewer points are built, mostly points seen in one TOF plane only, and the late points (above 145 ns) halve. Why was not studied: the unsmeared path may have its own problem.
R4-16 S4 When a second TDC time on one TOF bar end matches an ADC pulse that already has a TDC time, the code makes a copy of the hit for it. The copy takes the pulse's time and energy, but the line meant to link it to the raw ADC record links the TDC record instead. Every other TOF hit with a pulse carries its ADC record. Release 5.9.0 has the same lines. Link the copy to the ADC record of the hit it copies.
R4-21c S4 A TOF bar hit with no partner in the other plane becomes an unmatched TOF point. The code makes these points by walking a set ordered by memory address, then sorts all points by time with a sort that may reorder equal times. Points with exactly equal times therefore keep an order set by where their hits sit in memory. The step reuses that memory from one event to the next, so the same event can come out in another order. Release 5.9.0 has the same lines. Make unmatched points in hit order.
R4-21d S4 The TOF and CDC hit steps keep a few user settings (the TOF time-cut overrides, cosmic mode and debug level; the CDC charge threshold) in variables shared by the whole program. The framework makes one copy of each step per thread, and each copy writes these variables when it starts, while other threads may already read them: a data race, undefined behaviour in C++. Every thread writes the same value, so no output change is expected. Release 5.9.0 has the same lines. Make the settings members of each step.
R4-24 S4 DTOFHit_factory::BeginRun returns early when TOF2/walkcorr_type is missing, before FillCalibTable see the commit
R6-29 S4 DTOFGeometry reads empty geometry vectors when the run has no ForwardTOF (run 0 of a BOR-only skim), and segfaults see the commit

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 and others added 9 commits November 30, 2026 22:07
Three lines in `DTOFHit_factory::BeginRun` (`libraries/TOF/DTOFHit_factory.cc`), before the walk-correction type is
read: `USE_AMP_4WALKCORR`, `USE_NEWAMP_4WALKCORR` and `USE_NEW_WALK_NEW` are set to 0. The switch below then sets the
one flag of the current run, as `Init` does for the first run. This is the minimal change: the flags are members, they
are set only in that switch, and nothing else reads them before it. Type 1 keeps its meaning (no flag set, integral
correction). `patches/master.patch` applies unchanged to release 5.9.0 (the file is identical there).
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-9c-tof-walk-flags-kept-across-runs/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-9c-tof-walk-flags-kept-across-runs

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed out)

`patches/master.patch` restores the commented-out `continue` under `TOF:CHECK_FADC_ERRORS` in `DTOFHit_factory.cc`,
so the switch does what its text says, as in the other detectors. It also drops overflowed in-time pulses (81 of the
83 TOF points above 0.0193 GeV). If the TOF experts keep the flagged pulses (the factory handles zero-peak and
overflow pulses further on), the change should instead set the default to false or remove the switch.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-12-tof-fadc-error-check-disabled/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-12-tof-fadc-error-check-disabled

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…her end of the same bar has any hit, even one outside the time coincidence, so neither a two-ended nor a one-ended paddle hit is made from i

`libraries/TOF/DTOFPaddleHit_factory.cc`: the four "no match on the other end" loops use the pairing condition
(same bar, time difference below `TIME_COINCIDENCE_CUT`, one end above `E_THRESHOLD`) instead of "same bar". A hit
then becomes a one-ended paddle hit exactly when it was not paired, as the factory's comment says. Four conditions,
no other line. The patch applies to release 5.9.0 unchanged.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-28-tof-one-ended-hit-dropped-unpaired-partner/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-28-tof-one-ended-hit-dropped-unpaired-partner

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`libraries/TOF/DTOFPaddleHit_factory.cc`, `BeginRun`: two lines set `TOF_POINT_TAG` to the empty tag and register it
as `TOF:TOF_POINT_TAG`, the name the header documents. With the parameter unset the factory reads the untagged
DTOFHit objects as before. The patch applies unchanged to release 5.9.0.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-13-tof-point-tag-never-registered/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-13-tof-point-tag-never-registered

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hit twice and no ADC digihit

`libraries/TOF/DTOFHit_factory.cc`, the duplicate branch of `Process`: the copy takes the ADC digihit of the hit it is
copied from (`hit->GetSingle(adcdigihit)`) in place of the TDC digihit, which the common code after the branch
associates anyway. Nothing else changes. `patches/master.patch` applies unchanged to release 5.9.0.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-16-tof-duplicate-hit-no-adc-digihit/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-16-tof-duplicate-hit-no-adc-digihit

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`libraries/TOF/DTOFPoint_factory.cc`, end of `Process`: the walk over the pointer set is replaced by two loops over the
horizontal and the vertical spacetime-hit lists, in their insertion order. A hit makes an unmatched point when it is
still in the unused set. The set itself and the time sort stay. The output no longer depends on the pointer values.
The patch applies to release 5.9.0 without offset.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-21c-tof-unmatched-points-pointer-order/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-21c-tof-unmatched-points-pointer-order

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TOF flags, CDC DIGI_THRESHOLD)

`COSMIC_DATA`, `OVERRIDE_HIGH_TIME_CUT`, `OVERRIDE_LOW_TIME_CUT` and `TOF_DEBUG` move from file scope in
`libraries/TOF/DTOFHit_factory.cc` to members of `DTOFHit_factory` (declared in `DTOFHit_factory.h` with the same
defaults). `DIGI_THRESHOLD` moves from file scope in `libraries/CDC/DCDCHit_factory.cc` to a member of
`DCDCHit_factory`. Each thread's factory then writes and reads its own copy, which is what JANA's one instance per
thread intends. No line that uses the names changes. `TOF_DEBUG` is named in no other file of halld_recon.

`patches/master.patch` applies at master and at release 5.9.0 without offset (the four files are the same there, byte for byte).
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-21d-tof-cdc-statics-written-per-thread/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-21d-tof-cdc-statics-written-per-thread

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ype is missing, before FillCalibTable

`patches/master.patch`, one line in `libraries/TOF/DTOFHit_factory.cc`: the plain `return` after "Error loading
<dir>/walkcorr_type" becomes a `JException` that names the table and the run. JANA1 returned error 101 here; the
throw is the JANA2 way to report an error from `BeginRun`. The run no longer goes on with the tables of the previous
run or with empty ones.

The authors may prefer to go on without walk correction. That needs the time offsets loaded outside the switch on
the walk type, a larger change, and the run would then be processed with a partial calibration.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-24-tof-walkcorr-missing-plain-return/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-24-tof-walkcorr-missing-plain-return

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o ForwardTOF (run 0 of a BOR-only skim), and segfaults

`libraries/TOF/DTOFGeometry.cc`: after the three XPath queries, the constructor checks that each returned at least
three values and throws a `JException` naming the missing ForwardTOF position otherwise. This is the minimal change:
the constructor cannot work without the position, and an exception lets JANA report the cause and stop cleanly.
`patches/master.patch` applies at master and at release 5.9.0.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r6-29-tof-geometry-missing-forwardtof-segfault/index.html
Evidence folder: https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r6-29-tof-geometry-missing-forwardtof-segfault

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

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

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-9c S1 (commit e2487fc)

In a job over two run periods, the TOF keeps the first run's time-walk correction and crashes

What is wrong. At each run start the TOF hit step reads which time-walk correction the run uses and switches
that one on. It never switches the others off, and each hit takes the first one that is on, in a fixed order. In a
job that reads a 2018 run (correction type 3) and then a 2025 run (type 4), the 2025 hits get the 2018 correction,
and the job crashes in it after a few events: the old table has 44 bars, the 2025 TOF 46. Release 5.9.0 has the same
lines.

The code, shortened (on GitHub):

// at every run start:
switch ((int)walkcorrtype[0]) {
  ...
  case 3: ... USE_NEWAMP_4WALKCORR = 1; ...   // <-- switched on, never off again
  case 4: ... USE_NEW_WALK_NEW = 1; ...
}
// for every hit:
if (USE_AMP_4WALKCORR) { ... }
else if (USE_NEWAMP_4WALKCORR) tcorr = CalcWalkCorrNEWAMP(hit);   // <-- still taken in the 2025 run
else if (USE_NEW_WALK_NEW)     tcorr = CalcWalkCorrNEW5PAR(hit);

Fixed, before the switch:

USE_AMP_4WALKCORR = 0;  USE_NEWAMP_4WALKCORR = 0;  USE_NEW_WALK_NEW = 0;

What it does (raw data, 300 events of run 51030 then 300 of run 132404 in one job):

today with the fix
run-132404 event blocks read, of 300 11, then a crash 300
TOF hit times unlike run 132404 alone, events 1-8, bars 1-22 77 of 86 0 of 86
the same, all 297 events not reached 0 of 3680

Plot: BH-928: run 132404 read after run 51030 in one job crashes after 11 events today, and its TOF hit times differ; with the fix all 300 events are read and equal the run alone

BH-928. Against the run alone. Bars 23-46 use the first run's channel map, another finding.

Who is affected. Raw-data jobs over several runs that read a 2017 or 2018 run and then a run of the 46-bar TOF:
they crash.

Who is not.

  • Jobs over one run: production, the 2025-01 pass, benchmark jobs (0 of 998 events change).
  • Simulation and reduced (REST) files: this step does not run there.

The fix. Switch all three corrections off before choosing one.

Grade S1 (most severe of four): such a job crashes. Jobs over one run, or over 2025 runs only, are not
affected; use of such jobs is asserted, not shown.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-9c-tof-walk-flags-kept-across-runs/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-9c-tof-walk-flags-kept-across-runs

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-12 S2 (commit 4f9edd2)

The TOF switch that rejects faulty ADC pulses does nothing

What is wrong. The TOF has a switch, on by default, documented to drop ADC pulses the fADC250 flags as faulty.
The line that drops them is commented out, so the switch does nothing. Seven other detectors use the same switch and
drop them. The TOF code elsewhere handles such pulses (zero peak, overflow), so keeping them may be meant; then the
switch and its text are what is wrong.

The code, shortened (on GitHub):

CHECK_FADC_ERRORS = true;    // "Set to 1 to reject hits with fADC250 errors"
...
if(CHECK_FADC_ERRORS && !locTTabUtilities->CheckFADC250_NoErrors(digihit->QF)){
  if (TOF_DEBUG){ ... print the pulse ... }
  //continue;                // <-- commented out: the flagged pulse is used anyway
}

Fixed as measured here:

  continue;

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

now with the line restored
flagged ADC pulses made into TOF hits 1254 of 25905 0
TOF points 7325 7002

Benchmark reactions with the line restored:

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

reaction today → fixed change
ω → π⁺π⁻π⁰ 7996 → 8068 +0.9%, 5.9σ
ρ → π⁺π⁻ 12696 → 12804 +0.9%, 6.6σ
φ → K⁺K⁻ 6118 → 6266 +2.4%, 9.5σ

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

Plot: BH-81: 1694 of 25905 TOF ADC pulses are flagged, and 1254 of them are used anyway

BH-81. TOF ADC pulse times, 1000 raw events of a 2025-01 run: top, not flagged; bottom, flagged by the fADC. Limits: one run; which side is right is open.

Most flagged pulses are random late pulses cut by the window end; the rest are in-time pulses that
saturated, and restoring the line drops those too.

Who is affected.

  • Charged particle identification by TOF timing; tracks timed by the TOF.
  • Readers of TOF hits and points.

Who is not. Simulation, which never runs this code. Photon reactions: net yields move by 2 events or less.

The fix. For the TOF experts: restore the line, or keep the pulses and make the switch say so.

Grade S2 (second of four levels of how widely an output moves) if the line is restored: TOF points change by
4.4%. 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/r4-12-tof-fadc-error-check-disabled/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-12-tof-fadc-error-check-disabled

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-28 S2 (commit e45ca56)

A TOF hit is lost when the other end of its bar fired at another time

What is wrong. A TOF bar is read at both ends. Two end hits close in time make a two-ended paddle hit; a hit
with no partner should make a one-ended one. But "no partner" is tested as "no hit at all on the other end", so a hit
whose other end fired at another time is lost. Release 5.9.0 has the same code.

The code. Shortened; the test stands four times (on GitHub):

// pairing: same bar, in time, and one end above the energy threshold
if (bar==P1hitsR[j]->bar && fabs(P1hitsR[j]->t-P1hitsL[i]->t)<TIME_COINCIDENCE_CUT && ...)
...
// "in case no match is found": make a one-ended paddle hit
for (unsigned int j=0; j<P1hitsR.size(); j++){
  if (bar==P1hitsR[j]->bar){      // <-- any hit on the other end counts as a match, in time or not
    found = 1;

Fixed, with the pairing condition:

if (bar==P1hitsR[j]->bar && fabs(P1hitsR[j]->t-P1hitsL[i]->t)<TIME_COINCIDENCE_CUT && ...)

What it does. Run 132404 (2025-01), 1000 raw events, 997 in both TOF printouts:

today fixed
end hits above threshold lost although the other end fired 369, in 252 events 0
of them on bars that give no paddle hit at all 107 0
TOF paddle hits 13759 14128 (+2.7%)
TOF points 7325 7325; 48 single-plane points gain the other plane

Benchmark reactions:

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

Plot: BH-564: the fix keeps 369 TOF end hits whose other end fired out of time; 107 are on bars that make no paddle hit today

BH-564. Each lost hit by its time to the other end of its bar. Orange: the bar gives no paddle hit today. Grey: an
extra pulse beside a two-ended hit. Lost hits sit 16.9 ns or more from the other end, pairs made today within 16.8 ns:
the pairing window lies between.

Who is affected. Studies of TOF paddle hits, efficiency and timing.

Who is hardly affected. Track matching and charged-particle timing: one hypothesis of 10510 changes. The
added hits mostly have no in-time hit in the other plane: TOF points keep their number.

The fix. Count only an in-time partner as a match. Open: are late extra pulses particles or
afterpulses?

Grade S2 (second of four levels, S1 the most severe): the TOF paddle-hit count moves by +2.7%, over the 1% of
the scale. No benchmark moves.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-28-tof-one-ended-hit-dropped-unpaired-partner/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-28-tof-one-ended-hit-dropped-unpaired-partner

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-13 S4 (commit e17f837)

The documented option to build TOF points from unsmeared simulated hits does nothing

What is wrong. The TOF paddle-hit code documents an option, TOF:TOF_POINT_TAG=TRUTH, that makes it build TOF
paddle hits and points from the unsmeared simulated hits. The code reads the tag when it asks for the hits, but the
option is never registered, so the tag stays empty and the smeared hits are used whatever the user sets. Release
5.9.0 has the same lines.

The code, shortened (on GitHub):

// header:
*+ Addition: command line parmeter -PTOF:TOF_POINT_TAG=TRUTH will initiate
*           the use of TOFHitRaw::TRUTH information to calculate the TOFHit positions
...
string TOF_POINT_TAG;      // <-- never registered as an option, so always empty
// void Init() override;   // the start-up step is commented out
...
// the hit loop:
event->Get(hits,TOF_POINT_TAG.c_str());   // empty tag: the smeared hits, always

Fixed, at the start of each run:

TOF_POINT_TAG = "";
GetApplication()->SetDefaultParameter("TOF:TOF_POINT_TAG", TOF_POINT_TAG, "...");

What it does (1000 simulated events, option set to TRUTH):

today with the fix
TOF points equal to a run without the option 953 of 953 events 0 of 953
TOF paddle hits (960 of 1000 events change) 14620 12071
TOF points (47 events have none today, 59 with the fix) 9229 7225

Plot: BH-931: with TOF_POINT_TAG=TRUTH the TOF points equal the run without it today; with the fix they come from the unsmeared hits, 9229 to 7225

BH-931. TOF point time with the option set: today, with the fix, and today without the option. Last bin: all
points above 145 ns.

Who is affected. Simulation studies that set the option to separate the TOF resolution from the
reconstruction. The framework reports the setting as unused at start-up, and the job goes on with the smeared hits.

Who is not.

  • Real data, which has no unsmeared hits.
  • Every job that leaves the option unset (by the code): production, simulation production, benchmark jobs.

The fix. Register the option the header describes.

With the fix, 22% fewer points are built, mostly points seen in one TOF plane only, and the late points (above
145 ns) halve. Why was not studied: the unsmeared path may have its own problem.

Grade S4 (lowest of four): an unused path. The option is not registered, so no job reaches the unsmeared
branch today.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-13-tof-point-tag-never-registered/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-13-tof-point-tag-never-registered

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-16 S4 (commit 1406e31)

A TOF hit copied for a second TDC time loses the link to its ADC pulse

What is wrong. When a second TDC time on one TOF bar end matches an ADC pulse that already has a TDC time, the
code makes a copy of the hit for it. The copy takes the pulse's time and energy, but the line meant to link it to
the raw ADC record links the TDC record instead. Every other TOF hit with a pulse carries its ADC record. Release 5.9.0 has the same lines.

The code, shortened (on GitHub):

} else if (hit->has_TDC) {
  // found matching ADC hit but this ADC hit has already a matching TDC, make new tof ADC hit
  DTOFHit *newhit = new DTOFHit;
  ...
  newhit->dE = hit->dE;
  newhit->t_fADC = hit->t_fADC;
  ...
  newhit->AddAssociatedObject(digihit);    // <-- digihit is the TDC record in this loop
  Insert(newhit);
  hit = newhit;
}

Fixed:

  const DTOFDigiHit *adcdigihit = NULL;
  hit->GetSingle(adcdigihit);               // the ADC record of the hit being copied
  if (adcdigihit != NULL) newhit->AddAssociatedObject(adcdigihit);

What it does (the real hit step, one event with two TDC times on one bar end):

today with the fix
ADC records linked to the first hit 1 1
ADC records linked to the copy 0 1
times and energies of both hits unchanged unchanged

In 10 000 raw events of a 2025-01 run such a copy is made 4 times.

Plot: BH-951: the copied TOF hit has 0 ADC links today and 1 with the fix

BH-951. Raw records linked to each TOF hit of the bar end, today and with the fix.

Who is affected. Code that follows a TOF hit back to its raw ADC record: a TOF online-monitoring plugin
(pedestals and raw pulse sizes) and the raw-data writer when it saves selected objects. Both skip a hit without the
record.

Who is not. Reconstruction, REST files and analyses: no reconstruction step reads this link, and the physics
benchmarks cannot see it.

The fix. Link the copy to the ADC record of the hit it copies.

Grade S4 (lowest of four): at most 4 of 10 000 events, and only a link that monitoring and a writer option
read.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-16-tof-duplicate-hit-no-adc-digihit/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-16-tof-duplicate-hit-no-adc-digihit

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-21c S4 (commit b2b1923)

TOF points with exactly equal times come out in an order set by memory addresses

What is wrong. A TOF bar hit with no partner in the other plane becomes an unmatched TOF point. The code makes
these points by walking a set ordered by memory address, then sorts all points by time with a sort that may reorder
equal times. Points with exactly equal times therefore keep an order set by where their hits sit in memory. The step
reuses that memory from one event to the next, so the same event can come out in another order. Release 5.9.0 has the
same lines.

The code, shortened (on GitHub):

set<tof_spacetimehit_t*> locUnusedTOFSpacetimeHits;    // <-- a set of pointers: ordered by address
...
// Loop over unused/unmatched TOF Spacetime hits, and create separate DTOFPoint's for them
set<tof_spacetimehit_t*>::iterator locSetIterator = locUnusedTOFSpacetimeHits.begin();
for(; locSetIterator != locUnusedTOFSpacetimeHits.end(); ++locSetIterator)
  Create_UnMatchedTOFPoint(*locSetIterator);

// make sure all the hits are sorted by time (why not?)
// this helps with reproducibiliy problems...
std::sort(mData.begin(), mData.end(), Compare_TOFPoint_Time);  // <-- equal times: any order

Fixed: walk the horizontal, then the vertical hit list in hit order, and make a point from each hit still unused.

What it does (the point step run three times on one event: three unmatched bars, equal times):

today with the fix
first pass bars 5, 20, 35 5, 20, 35
second and third pass 35, 20, 5 5, 20, 35
content of the points unchanged unchanged

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

Plot: BH-954: the same event gives bars 5, 20, 35, then 35, 20, 5 today; 5, 20, 35 every time with the fix

BH-954. Order of the unmatched TOF points when the step sees the same event three times.

Who is affected. Code that takes the first of several TOF points with exactly equal times, and checks that
compare two runs point by point. How often equal times occur in data was not counted.

Who is not. The content of every TOF point, the track-to-TOF match (it picks the closest point), and the physics
benchmarks.

The fix. Make unmatched points in hit order.

Grade S4 (lowest of four): only the order of equal-time points changes; the benchmarks do not move.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-21c-tof-unmatched-points-pointer-order/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-21c-tof-unmatched-points-pointer-order

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-21d S4 (commit 99f046e)

TOF and CDC hit settings are shared by all threads, and every thread rewrites them at start-up

What is wrong. The TOF and CDC hit steps keep a few user settings (the TOF time-cut overrides, cosmic mode and
debug level; the CDC charge threshold) in variables shared by the whole program. The framework makes one copy of each
step per thread, and each copy writes these variables when it starts, while other threads may already read them: a
data race, undefined behaviour in C++. Every thread writes the same value, so no output change is
expected. Release 5.9.0 has the same lines.

The code, TOF, shortened (on GitHub):

static bool COSMIC_DATA = false;              // <-- one variable for all threads
static bool OVERRIDE_HIGH_TIME_CUT = false;
static bool OVERRIDE_LOW_TIME_CUT = false;

int TOF_DEBUG = 0;
...
void DTOFHit_factory::Init()                  // runs once in every thread
{
  ...
  app->SetDefaultParameter("TOF:OVERRIDE_HIGH_TIME_CUT", OVERRIDE_HIGH_TIME_CUT, "...");  // <-- each thread writes

Fixed: the four TOF variables and the CDC threshold become members of the step, one copy per thread.

What it does (16 threads, 1000 raw events of a 2025-01 run, thread checker):

race reports today with the fix
TOF hit step 3 0
CDC hit step 1 0

At 4 threads no report showed. The outputs of the two sides were not compared.

Plot: BH-952: 4 data-race reports with 16 threads today, 0 with the fix

BH-952. Thread-checker reports with an access in the TOF or CDC hit step, today and with the fix.

Who is affected. Every multi-threaded job that makes TOF or CDC hits, production included, with no output change
expected; and thread-checker runs of the reconstruction, which get these reports among the real ones.

Who is not. One-thread jobs, the physics benchmark jobs among them: they cannot show a race.

The fix. Make the settings members of each step.

Grade S4 (lowest of four): no output change is expected in any event; the finding is the race itself.


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-21d-tof-cdc-statics-written-per-thread/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-21d-tof-cdc-statics-written-per-thread

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

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R4-24 S4 (commit 1715711)


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r4-24-tof-walkcorr-missing-plain-return/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r4-24-tof-walkcorr-missing-plain-return

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_tof.log
Build report: report_auto-hunt_tof.txt

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

R6-29 S4 (commit a6a5ac8)


Full card with plots and the evidence for the code owner: https://pages.jlab.org/halld/auto-hunt/cards/r6-29-tof-geometry-missing-forwardtof-segfault/index.html
Evidence folder (tests, patches, review): https://code.jlab.org/halld/auto-hunt/-/tree/main/bughunt/confirmed/halld_recon/TOF/r6-29-tof-geometry-missing-forwardtof-segfault

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

@zihlmann

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R4-16: my first look at this particular issue suggests that the original code is correct and there is no problem.
The code is written in a way that may sow confusion but it is correct. the logic is as follows:

  1. there is a loop over the TDC digi hits.
  2. in this look for each TDC digi hit a match to an ADC hit his searched for (That list has previously been established.)
  3. if no ADC hit match is found the loop jumps to the next TDC digi hit
    -> Note: the FindMatch() methode returns a DTOFHit object called "hit" NOT a DTOFDigiHit object!
  4. if a match is found it first tests if this match already has a TDC digi hit assigned.
  5. if this is true then a new DTOFHit is created and all ADC data are written to this new DTOFHit
    AND: the pointer "hit" is overwritten with this new DTOFHit Object pointer
  6. The TDC data is updated with the TDC data corresponding to the current TDC Digi hit data.
    the code in github is here for reference:
    } else if (hit->has_TDC) {
    // found matching ADC hit but this ADC hit has already a matching TDC, make new tof ADC hit
    DTOFHit *newhit = new DTOFHit;
    newhit->plane = hit->plane;
    newhit->bar = hit->bar;
    newhit->end = hit->end;
    newhit->dE = hit->dE;
    newhit->Amp = hit->Amp;
    newhit->t_fADC = hit->t_fADC;
    newhit->has_fADC = hit->has_fADC;
    newhit->t_TDC=numeric_limits<double>::quiet_NaN();
    newhit->t = hit->t_fADC; // set initial time to the ADC time, in case there's no matching TDC hit
    newhit->has_TDC=false;
    newhit->AddAssociatedObject(digihit);
    Insert(newhit);
    hit = newhit;
    }

@zihlmann

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R4-9c S1: I concur with the assessment and the proposed fix. However, this behavior would only happen if some analyzer would analyze two files from two different runs from two different run periods which certainly will never happen. But, from a "good programming" point of view this "bug" should be fixed.

@zihlmann

zihlmann commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

R4-12 S2: yes agree.

@zihlmann

zihlmann commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

R4-28 S2: yes, there needs to be an additional time difference condition added at each of the four conditions.
the proposed code correction is:
replace: if (bar==P1hitsR[j]->bar){

with: if (bar==P1hitsR[j]->bar
&& fabs(P1hitsR[j]->t-P1hitsL[i]->t)<TIME_COINCIDENCE_CUT
&& (P1hitsL[i]->dE>E_THRESHOLD || P1hitsR[j]->dE>E_THRESHOLD)){

I propose to not use Energy Cut condition as there will be such a condition applied when forming the single end paddle HIT as follows:
if (!found){
if (P1hitsL[i]->dE>E_THRESHOLD){
DTOFPaddleHit *hit = new DTOFPaddleHit;
......

@zihlmann

zihlmann commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

R4-13 S4: No, the flaged code should be REMOVED from the code base. The use of such a variable would imply that a factory with the TAG equals to TOF_POINT_TAG like "TRUTH" exists. However, this is not the case. So the proposal here is to remove the string definition TOF_POINT_TAG from the header file and remove its usage in the cc code.

@zihlmann

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R4-16 S4: yes, agreed. The fix looks fine.

@zihlmann

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R4-21c S4: Not pretending to understand the code the new proposed code looks more readable and understandable.

@zihlmann

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R4-21d S4: YES, Defining variables at the top of the code in DTOFHit_factory.cc outside of any block is bad. This makes them "global" variables:
static bool COSMIC_DATA = false;
static bool OVERRIDE_HIGH_TIME_CUT = false;
static bool OVERRIDE_LOW_TIME_CUT = false;

Similarly in DCDCHit_factory.cc at outside of any code block there is the definition:
static double DIGI_THRESHOLD = -1.0e8;
again creating a "global variable"

why this code would interfere with each other is unclear but the coding is definitely not good.

removal of these static global variables and put them into the class definitions in the header files is a good move.

@zihlmann

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R4 -24: S4: YES, the code just terminate with a useful message if the walk correction type is not given.

DraTeots and others added 2 commits December 1, 2026 18:10
…dence only, no energy threshold

`libraries/TOF/DTOFPaddleHit_factory.cc`: as the reviewer proposed, each of the four "no match on the other end"
loops counts a hit on the other end as a match when it is on the same bar and within `TIME_COINCIDENCE_CUT`. The
energy-threshold term of the first version is dropped: the one-ended paddle hit is made only above `E_THRESHOLD`
anyway, so the result is the same.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-28-tof-one-ended-hit-dropped-unpaired-partner/index.html

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`libraries/TOF/DTOFPaddleHit_factory.h` and `.cc`: as the reviewer asked, the `TOF_POINT_TAG` member, the header
comment that documents `-PTOF:TOF_POINT_TAG=TRUTH`, and the parameter registration added by the first version of
this fix are removed. The factory reads the untagged DTOFHit objects (`event->Get(hits)`), which is what every job
did before, since the tag was always empty.
Card: https://pages.jlab.org/halld/auto-hunt/cards/r4-13-tof-point-tag-never-registered/index.html

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

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

zihlmann commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

R6-29 S4: Yes, rather than just let the code crash, terminate it nicely when the TOF geometry is not found.

@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_tof.log
Build report: report_auto-hunt_tof.txt

@DraTeots

DraTeots commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review. Two commits are added on top of the branch, no force-push:

  • R4-28 (31dc8cd2b): each of the four "no match on the other end" tests is now bar==... && fabs(...->t - ...->t) < TIME_COINCIDENCE_CUT, as you gave it, without the energy-threshold term. The one-ended paddle hit still needs dE > E_THRESHOLD, so the result is the same as with the energy term.
  • R4-13 (714ebaffc): TOF_POINT_TAG is removed. That covers the header member, the header comment that documents -PTOF:TOF_POINT_TAG=TRUTH, and the parameter registration from the first commit. The factory now calls event->Get(hits), which reads the same untagged hits every job read before.

For R4-13, one note: TOF_init.cc still declares a JFactoryT<DTOFHit>("TRUTH") for the unsmeared simulated hits. Only the option to read them in the paddle-hit factory is gone.

Checked with a syntax-only compile of every changed TOF and CDC source file against the release headers. All pass. The earlier CI failure was the clone step (the "/" in the branch name), which has since been fixed in the CI scripts. The new push should start a fresh build.


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

@zihlmann

zihlmann commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

R4-16: my first look at this particular issue suggests that the original code is correct and there is no problem. The code is written in a way that may sow confusion but it is correct. the logic is as follows:

  1. there is a loop over the TDC digi hits.
  2. in this look for each TDC digi hit a match to an ADC hit his searched for (That list has previously been established.)
  3. if no ADC hit match is found the loop jumps to the next TDC digi hit
    -> Note: the FindMatch() methode returns a DTOFHit object called "hit" NOT a DTOFDigiHit object!
  4. if a match is found it first tests if this match already has a TDC digi hit assigned.
  5. if this is true then a new DTOFHit is created and all ADC data are written to this new DTOFHit
    AND: the pointer "hit" is overwritten with this new DTOFHit Object pointer
  6. The TDC data is updated with the TDC data corresponding to the current TDC Digi hit data.
    the code in github is here for reference:
    } else if (hit->has_TDC) {
    // found matching ADC hit but this ADC hit has already a matching TDC, make new tof ADC hit
    DTOFHit *newhit = new DTOFHit;
    newhit->plane = hit->plane;
    newhit->bar = hit->bar;
    newhit->end = hit->end;
    newhit->dE = hit->dE;
    newhit->Amp = hit->Amp;
    newhit->t_fADC = hit->t_fADC;
    newhit->has_fADC = hit->has_fADC;
    newhit->t_TDC=numeric_limits<double>::quiet_NaN();
    newhit->t = hit->t_fADC; // set initial time to the ADC time, in case there's no matching TDC hit
    newhit->has_TDC=false;
    newhit->AddAssociatedObject(digihit);
    Insert(newhit);
    hit = newhit;
    }

Yes, upon closer look, the issue is recognized. Indeed the wrong object is added as associated object. It should be the ADC object and not the tdc object. => using the same name for two different object types is not a good idea.

@zihlmann

zihlmann commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

I think all changes now are ready for merge.

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

Code was not tested but reviewed and deemed ok.

@zihlmann
zihlmann merged commit 27ac42a into master Dec 2, 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