Skip to content

Mcsmear random merge rtj - #423

Open
rjones30 wants to merge 2 commits into
masterfrom
mcsmear_random_merge_rtj
Open

rjones30 wants to merge 2 commits into
masterfrom
mcsmear_random_merge_rtj

Conversation

@rjones30

@rjones30 rjones30 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Branch mcsmear_random_merge_rtj (2 commits on master be7b14e). Independent of #422: either can be merged first, without conflicts, and the combined result is the same.

1. Multithreaded jobs lost the requested random-trigger offset (bug fix)

MyProcessor::BeginRun runs once in every processing thread, because the hits-merger configuration is thread_local. But the random-trigger input streams (files2merge) are shared by all threads, and each BeginRun call repositioned them to the start of the file plus the requested skip. The skip is zeroed after the first call, so with N threads the shared streams were rewound to the start of the file up to N>1 times while the threads started. Consequences for any multithreaded mcsmear job that merges random triggers:

  • the random triggers come from the first few thousand events of the file, whatever file:N+skip asked for, so jobs that use different skips on the same file all merge (nearly) the same random events;
  • the first few hundred events of the file are merged several times over within one job.

Where the start of a random-trigger file is not typical of the run (beam off, or the current ramping up after a trip), the merged background is biased, run by run. Single-threaded jobs are not affected.

Fix: position the shared streams once per run, by the first thread to begin that run. Single-threaded output is byte-identical to before.

2. New option MERGE:MIN_TAGGER_HITS (default 5 )

Random-trigger events with fewer tagger hits (hodoscope + microscope, all channels, any time) than MERGE:MIN_TAGGER_HITS were recorded with the beam off. With the option set, they are skipped at read time and the next event in the file is used, so beam-off events are never merged, whatever the random-trigger file contains. The numbers of random events read and skipped are printed at the end of the job.

  1. Random-trigger files in use contain sizable beam-off fractions: e.g. recon-2019_11-ver01.2 6?56% per run, recon-2023-01-ver04 11?42% per run (events with 0 tagger hits and an empty CDC/FDC). In those files beam-off events have 0 tagger hits (a few 2023-01 events have 1?4 noise hits);
  2. beam-on events typically have 40?100. We use -PMERGE:MIN_TAGGER_HITS=5.

Tests (run 71350, recon-2019_11-ver01.2 random triggers, which start with 591 beam-off events)

test result
MIN_TAGGER_HITS=0, 1 thread, 300 events vs the previous binary byte-identical output
MIN_TAGGER_HITS=5, 1 thread, 300 events, skip 0 925 read, 625 skipped: exactly the events with < 5 tagger hits in that range (offline scan)
same, vs MIN_TAGGER_HITS=0 on a copy of the file holding only the events with ? 5 tagger hits byte-identical output
before the fix: 16 threads, skip 1000, 3000 events 16 BeginRun calls; 12323 read, 9323 skipped (the file start re-read), vs 3000 read, 0 skipped with 1 thread
after the fix: 16 threads, skip 1000, 3000 events 3000 read, 0 skipped (as 1 thread)
after the fix: 16 threads, skip 0, MIN_TAGGER_HITS=5 and =1 3625 read / 625 skipped and 3590 / 590: identical to 1 thread and to the offline scan
after the fix: 16 threads vs 1 thread, MIN_TAGGER_HITS=5, merged hits per event CDC 41.9 vs 41.7, FDC anode 90.0 vs 89.8 (before the fix, 16 threads: 27.6 and 65.3)
after the fix: 1 thread vs before the fix byte-identical output
this branch alone on master (default FDC options) 1 thread: 925 read / 625 skipped; 16 threads, skip 1000: 3000 / 0

Found in the GlueX rho0 photoproduction data/MC study of 2026-11.

@gluex

gluex commented Nov 3, 2026

Copy link
Copy Markdown

Build status for this pull request: FAILURE

Build log: make_mcsmear_random_merge_rtj.log
Build report: report_mcsmear_random_merge_rtj.txt

rjones30 and others added 2 commits November 3, 2026 09:38
…random-trigger events in the merge [rtj]

Random-trigger events with fewer tagger hits (hodoscope + microscope, all
channels, any time) than MERGE:MIN_TAGGER_HITS were recorded with the beam
off; they are skipped at read time and the next event in the file is used,
so beam-off events are never merged, whatever the random-trigger file
contains. The default is 5; -PMERGE:MIN_TAGGER_HITS=0 merges every event,
as before this change. The numbers of random events read and skipped are
printed at the end of the job.

Beam-off events have 0 tagger hits (plus 1-4 noise hits in some 2023-01
events), beam-on events typically 40-100 (GlueX rho0 data/MC study,
2026-11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n, not once per thread [rtj]

BeginRun runs in every processing thread, because the hits-merger
configuration is thread_local, but the merge input streams are shared.
Each call repositioned the streams to the start of the file plus the
requested skip, and the skip was zeroed after the first call, so with
N threads the streams were rewound to the start of the file up to N-1
times during start-up. Multithreaded jobs therefore took their random
triggers from the start of the file whatever skip was requested, and
merged the first events of the file several times over.

Now the streams are positioned once per run, by the first thread to
start that run. Single-threaded output is unchanged.

Found in the GlueX rho0 data/MC study of 2026-11: with 16 threads and
skip 1000, 12323 random events were read and 9323 beam-off events
skipped, where a single thread reads 3000 and skips none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rjones30
rjones30 force-pushed the mcsmear_random_merge_rtj branch from f5c36dc to 4d77929 Compare November 3, 2026 15:00
@gluex

gluex commented Nov 3, 2026

Copy link
Copy Markdown

Build status for this pull request: FAILURE

Build log: make_mcsmear_random_merge_rtj.log
Build report: report_mcsmear_random_merge_rtj.txt

@sdobbs

sdobbs commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for looking into these issues, Richard. Regarding the MERGE:MIN_TAGGER_HITS cut, I looked more closely at the random trigger files generated for one of the 2023-01 runs, and indeed there were events in these files that should have been excluded due to the electron beam fiducial cuts (but not consistently included!). This means we have to look into the process of how the random trigger files are created, but in the meantime I think this cut is a good idea - it should efficiently reject these events that should have been excluded.

@gluex

gluex commented Nov 3, 2026

Copy link
Copy Markdown

Test status for this pull request: SUCCESS

Summary: summary.txt
Logs: results/log

Build log: make_mcsmear_random_merge_rtj.log
Build report: report_mcsmear_random_merge_rtj.txt

rjones30 added a commit that referenced this pull request Nov 9, 2026
New command-line options for the FDC smearing. Every default leaves the
output unchanged.

  FDC:GAIN_SCALE        gas-gain factor on the strip charge q and on the
                        anode wire dE, applied before the thresholds (1)
  FDC:GAIN_PKG1..4      extra gain factor per FDC package (modules 1-2,
                        3-4, 5-6, 7-8), times FDC:GAIN_SCALE (1)
  FDC:GAIN_SIGMA s      avalanche gain fluctuation: one log-normal factor
                        exp(s G - s^2/2) per chamber and track, shared by
                        the wire hit and the strips it induces (0)
  FDC:DOCA_ATTEN a      wire dE and the track's strip q in the chamber
                        scaled by max(0.05, 1 - a doca^2), doca in cm (0)
  FDC:STRIP_THRESHOLD   strip charge threshold in pC; < 0 keeps
                        FDC_THRESHOLD_FACTOR * FDC_PED_NOISE from CCDB (-1)
  FDC:WIRE_THRESHOLD_KEV  anode threshold on the gain-scaled wire dE in keV;
                        < 0 keeps FDC_THRESH_KEV from CCDB (-1)

Motivation: the FDC gas gain of the real detector changes with time and
differs between packages (e.g. a 40% drop of the strip signal between
2019-11 runs 71362 and 71483), which changes the FDC hit efficiency and
with it the tracking efficiency. With per-period gains fitted only to the
data's FDC plane-used fractions (not to any cross section), the rho(0)
photoproduction cross section of ten run segments (2018-01 to 2023-01)
agrees to about 2% (RMS, beyond statistics).

Builds on the FDC options and peakAmp of PR #422; independent of #423.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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