Skip to content

TrackerMC: compute the straw response geometry once per cluster - #2143

Merged
oksuzian merged 2 commits into
Mu2e:mainfrom
RobMina:trk-response-geometry
Nov 18, 2026
Merged

oksuzian merged 2 commits into
Mu2e:mainfrom
RobMina:trk-response-geometry

Conversation

@RobMina

@RobMina RobMina commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What

StrawWaveform calls StrawElectronics::linearResponse (and maxResponseTime / maxLinearResponse) for every
(waveform sample, cluster) pair. Each call recomputes terms that depend only on the cluster's wire distance and the
straw: the reflection time, the reflection scale (an exp), and a linear scan of the wire-distance points for the
interpolation interval and weight.

This PR computes them once per cluster:

  • StrawElectronics::ResponseGeometry and responseGeometry(straw, distance) hold and compute those terms.
  • linearResponse, maxResponseTime and maxLinearResponse get overloads that take a ResponseGeometry. The
    existing distance-based overloads now call them with the same arithmetic, so their results do not change.
  • StrawCluster::responseGeometry(strawele, straw) caches the geometry per cluster, keyed by the straw id.
  • All six call sites in StrawWaveform.cc use the cached geometry.

Files: TrackerConditions/inc/StrawElectronics.hh, TrackerConditions/src/StrawElectronics.cc,
TrackerMC/inc/StrawCluster.hh, TrackerMC/src/StrawWaveform.cc.

Validation

The output is bitwise identical to main.

  • Reference. Offline main ca7b6580 (the CI build), with the same Production and mu2e-trig-config commits in both
    arms.
  • Sample. Mix1BB digitisation (Production JobConfig/mixing/Mix.fcl + OneBB.fcl) of 2,000
    CeMLeadingLog.MDC2025ap events, with the four MDC2025ac/ad pileup streams and a fixed seed.
  • Digitisation. The products were dumped per event with PrintModule: straw digis, ADC waveforms, StrawDigiMC,
    calo and CRV digis, and the trigger reco built on them (combo hits, KalSeeds, calo clusters). All 2,000 events are
    identical: 9.0M dump lines, 1.38M straw digis. TrigReport is identical.
  • Reco. OnSpill reco ran on the 1,528 events each arm writes. Combo hits, time clusters, helix seeds, KalSeeds,
    calo clusters and CRV pulses are identical, and TrigReport is identical.

Performance

Both arms ran on the same host, 1,000 events per run, in two repeats alternating base and PR. Times are art
TimeTracker means.

PR / main, repeat 1 repeat 2
makeSD (StrawDigisFromStrawGasSteps) 0.79 0.82
full event 0.94 0.95

Main's own repeat-to-repeat spread is 2 %. makeSD is the most expensive module of the Mix1BB digitisation job, at
86 of 297 ms/event on this host.

🤖 Generated with Claude Code

StrawElectronics::responseGeometry precomputes the reflection time and scale and the wire-distance interpolation of a cluster; linearResponse, maxResponseTime and maxLinearResponse take it, and the distance overloads call them with the same arithmetic. StrawCluster caches it per straw and StrawWaveform uses it. Output bitwise identical; makeSD about 20 % faster in Mix1BB digitisation.

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

Copy link
Copy Markdown
Collaborator

Hi @RobMina,
You have proposed changes to files in these packages:

  • TrackerConditions
  • TrackerMC

which require these tests: build.

@Mu2e/fnalbuild-users, @Mu2e/write have access to CI actions on main.

⌛ The following tests have been triggered for 685a483: build (Build queue - API unavailable)

About FNALbuild. Code review on Mu2e/Offline.

@FNALbuild

Copy link
Copy Markdown
Collaborator

☀️ The build tests passed at 685a483.

Test Result Details
test with ✅ Command did not list any other PRs to include
merge ✅ Merged 685a483 at 152833a
build (prof) ✅ Log file. Build time: 05 min 50 sec
ceSimReco ✅ Log file.
g4test_03MT ✅ Log file.
transportOnly ✅ Log file.
POT ✅ Log file.
g4study ✅ Log file.
cosmicSimReco ✅ Log file.
cosmicOffSpill ✅ Log file.
ceSteps ✅ Log file.
ceDigi ✅ Log file.
muDauSteps ✅ Log file.
ceMix ✅ Log file.
rootOverlaps ✅ Log file.
g4surfaceCheck ✅ Log file.
trigger ❓ Log file. Return Code 1.
check_cmake ✅ Log file.
FIXME, TODO ➡️ TODO (0) FIXME (3) in 4 files
clang-tidy ➡️ 0 errors 81 warnings
whitespace check ✅ no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 685a483 after being merged into the base branch at 152833a.

For more information, please check the job page here.
Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #2143

Reviewed at head 685a483b276f0467e99798e12be50d0c38b7f866. First pass.

Decision

  • 🟢 approve. The per-cluster terms are computed with exactly the old arithmetic, and the tracker digitisation output is identical to main on four samples (15,916 straw digis with their waveforms and truth). makeSD takes about 20% less time per event, as the description says. FNALbuild build 3596 passed at this head, apart from the trigger row, which shows the same warning on every build against current main and does not exercise this change (see Validation check). One optional simplification is below (finding 1).

Scope understood

  • StrawElectronics::responseGeometry(straw, distance) returns a ResponseGeometry: the reflection time, the reflection scale, and the wire-distance interpolation index and weight. linearResponse, maxResponseTime and maxLinearResponse get overloads that take it. The distance overloads stay and now call the new ones.
  • StrawCluster::responseGeometry caches the result in two mutable members, keyed by straw id, and the six calls in StrawWaveform.cc use it.

Findings

  1. ⚪ [S3] The cache could be filled once when the cluster is made, with no mutable state.
    • Evidence: in StrawDigisFromStrawGasSteps, both waveforms of a sequence, including the cross-talk ones, are built with the sequence's own straw (createDigis, :585-586, called with straw for self and every XTalk at :538, :550). So the key check in StrawCluster.hh:64 only ever misses the first time. The primary clusters are made at :672, where strawele, straw and weq._wdist are all in hand, and the ghost copies (:794, :796) copy the cluster.
    • Computing the ResponseGeometry there, as a constructor argument, would remove the two mutable members and the key check, and StrawCluster.hh would no longer need the TrackerConditions and TrackerGeom includes. A related sharp edge: ResponseGeometry is a public aggregate whose all-zero default (index 0, no reflection) is accepted by linearResponse without complaint, and maxResponseTime(…, distance) builds such a partial object internally.
    • This is a simplification and does not gate.

Checked, no action needed

  • 🟢 Same arithmetic. fillDistanceInterval is the old loop and weight, line for line, including the clamp to _wPoints.size()-2 and the extrapolating weight past the last point. responseGeometry computes straw_length, the reflection time and the reflection scale with the old expressions, from the same float _wdist the old calls received through wireDistance(). linearResponse then forms index_refl with the same expression.
  • 🟢 The cache stays correct. _rgeomStraw starts invalid (StrawId() is 0xFFFF, StrawId.hh:62), the result depends only on the straw and _wdist, which never changes after construction, and clusters live for one event, so a StrawElectronics change between runs cannot leave a stale value. StrawDigisFromStrawGasSteps is a legacy art::EDProducer, so there is no concurrent access to the mutable members.
  • 🟢 Other callers are unaffected. StrawElectronicsMaker.cc:274 (building the _tmax/_linmax tables) and the diagnostic in StrawDigisFromStrawGasSteps_module.cc:1115 still use the distance overloads, which give the same values. Nothing persists TrackerMC::StrawCluster.
  • 🟢 Memory. sizeof(StrawCluster) grows from 96 to 128 bytes. The peak RSS of my jobs did not change measurably (for example 893-902 MB on main and 882-896 MB at this head in the timing runs below).

Validation check

  • Build/tests run: yes. A muse build of this head on the CI build of its merge base, main ca7b6580 (p110), exited with status 0 and no warnings; main ran from that CI build. Each job ran in both arms with the same configuration and seeds, with a PrintModule dump of every StrawDigi, StrawDigiADCWaveform and StrawDigiMC. All jobs exited with status 0, and every dump is identical:

    job events makeSD digis
    FNALbuild ceDigi 53 2,248
    FNALbuild cosmicOffSpill 400 5,984
    FNALbuild ceMix 53 2,472
    ceMix with 15 times the muon-stop pileup rate 53 5,212

    Digis and ADC samples are integers, so these compare exactly; the truth printout carries times to 0.01 ns.

  • Timing: the high-pileup job without the printer, three repeats with main and this head running side by side. makeSD median per event: 23.6, 24.4, 25.4 ms on main and 18.8, 19.9, 19.4 ms at this head, a ratio of about 0.79.

  • FNALbuild build 3596 (merged on main 152833a9, 16:33 UTC; checked 17:45 UTC): every test passed except trigger, which shows ":question: Return Code 1". Every build against main since ca7b6580 shows the same warning (mpr_TrkDe_80m70p_D0200 445 → 414 against the reference), and the trigger job reads already-digitised files, so it does not run this code; its TrigReport is identical to that of #2107, #2141 and #2142 on the same main.

  • Config contract check: not applicable, no fcl change.

  • Cross-repo consistency: pass.

Residual risk

  • I did not run a full 1BB-intensity mixed sample; the description's Mix1BB comparison covers that.

Author follow-ups

  1. Optional: finding 1.

The primary constructor takes the StrawElectronics and the Straw and computes the ResponseGeometry from the cluster's own wire distance; responseGeometry() takes no arguments and the mutable cache and its straw-id check are removed. Output bitwise identical.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #2143

Reviewed at head 393ac9137d347f06e15907c0bfb5f583d9399e8a. Re-review of 685a483.

Decision

  • 🟡 comment now, approve when green. The new commit computes the response geometry in the StrawCluster constructor, as the first pass suggested, and it gives the same inputs as before for every cluster. The tracker digitisation output is still identical to main on the same four samples, and makeSD is still about 25% faster. FNALbuild has not built this head yet. I will approve once it passes. The two notes below are optional and do not gate.

What changed since 685a483

  • One commit, 393ac913, on top of the approved head. It is not a rebase, so the merge base is still main ca7b6580.
  • The primary StrawCluster constructor now takes the StrawElectronics and the Straw. It computes the ResponseGeometry from the cluster's own _wdist (StrawCluster.cc:30). responseGeometry() takes no arguments (StrawCluster.hh:65), and the six calls in StrawWaveform.cc use it. The module passes strawele and straw at its one construction site (StrawDigisFromStrawGasSteps_module.cc:672).

Prior findings

  • 🟢 [was S3] Compute the response geometry when the cluster is made, with no mutable state — FIXED in 393ac91, verified.
    • The two mutable members and the straw-id check are gone. git grep finds no mutable in TrackerMC and no caller of the old two-argument accessor.
    • Every cluster gets the same inputs as on main. The only primary construction is :672, where straw is _tracker->getStraw(sid) for the step's own straw (:627-629). The ghost copies (:794, :796) copy the cluster, so they keep its straw and _wdist. The waveform looks up its straw from the sequence's id (:535), and StrawClusterSequence::insert throws for a cluster from another straw (StrawClusterSequence.cc:48-53). So the constructor's straw is always the waveform's straw.
    • _rgeom is declared after _wdist (StrawCluster.hh:74, :80), so it is computed from the same float that wireDistance() returned on main.
    • The TrackerGeom include has left the header. The TrackerConditions include stays, which is right now that the header holds a ResponseGeometry by value.
  • 🟢 The "sharp edge" noted in the same finding is still there, but nothing reaches it. ResponseGeometry still defaults to all zeros, and the distance overloads of maxResponseTime and maxLinearResponse still fill only the index and weight (StrawElectronics.cc:141-160). The struct comment now says so (StrawElectronics.hh:48). The only cluster with the zero default is a default-constructed one, and insert rejects it because its type is unknown (StrawClusterSequence.cc:41-46). No action needed.

New findings

  1. ⚪ [S3] The cross-talk copy constructor would carry one straw's response terms to another straw. StrawCluster(const StrawCluster&, StrawId const&, float) (StrawCluster.cc:33-38) changes _strawId but keeps _rgeom, whose reflection terms depend on the original straw's length. Nothing in Offline calls it, because cross-talk is applied through XTalk in the waveform (StrawDigisFromStrawGasSteps_module.cc:537-551), so the output is not affected. Deleting it would remove the trap.
  2. ⚪ [S3] The PR description still describes the first design. It says StrawCluster::responseGeometry(strawele, straw) "caches the geometry per cluster, keyed by the straw id", and its file list leaves out StrawCluster.cc and the module. Please update it, since it becomes the record of the merge.

Validation check

  • Build/tests run: yes. A muse build of this head on the CI build of its merge base, main ca7b6580 (p110), exited with status 0 and no warnings. main ran from that CI build. I reran the first pass's four jobs in both arms with the same configuration and seeds, with a PrintModule dump of every StrawDigi, StrawDigiADCWaveform and StrawDigiMC. All jobs exited with status 0, and every dump is identical to main. The head dumps are also identical to the first pass's main dumps.

    job events makeSD digis
    FNALbuild ceDigi 53 2,248
    FNALbuild cosmicOffSpill 400 5,984
    FNALbuild ceMix 53 2,472
    ceMix with 15 times the muon-stop pileup rate 53 5,212
  • Timing: the high-pileup job without the printer, three repeats with main and this head running side by side on the same host as the first pass. makeSD median per event: 12.6, 12.6, 12.8 ms on main and 9.4, 9.4, 9.4 ms at this head, a ratio of 0.73 to 0.75. The absolute times are lower than in the first pass, so compare the ratio, which was about 0.79 then.

  • Memory: sizeof(StrawCluster) is 128 bytes, the same as at 685a483 (96 on main). The removed 2-byte straw id fitted in padding. Peak RSS was 917-920 MB on main and 911-913 MB at this head.

  • FNALbuild: no build at this head. The mu2e/buildtest status has read "This test has not been triggered yet" since 01:21 UTC on 11 November (checked 03:34 UTC). The last FNALbuild result on this PR is build 3596, at 685a483. This head needs a CI run.

  • Config contract check: not applicable, no fcl change.

  • Cross-repo consistency: pass. GitHub code search finds TrackerMC/inc/StrawCluster.hh used only in Offline.

Residual risk

  • No FNALbuild run at this head yet.
  • I did not run a full 1BB-intensity mixed sample; the description's Mix1BB comparison covers the first commit.

Author follow-ups

  1. Update the PR description (finding 2).
  2. Optional: finding 1.

@oksuzian

Copy link
Copy Markdown
Collaborator

@FNALbuild run build test

@FNALbuild

Copy link
Copy Markdown
Collaborator

⌛ The following tests have been triggered for 393ac91: build (Build queue - API unavailable)

@FNALbuild

Copy link
Copy Markdown
Collaborator

☀️ The build tests passed at 393ac91.

Test Result Details
test with ✅ Command did not list any other PRs to include
merge ✅ Merged 393ac91 at 30088f3
build (prof) ✅ Log file. Build time: 04 min 38 sec
ceSimReco ✅ Log file.
g4test_03MT ✅ Log file.
transportOnly ✅ Log file.
POT ✅ Log file.
g4study ✅ Log file.
cosmicSimReco ✅ Log file.
cosmicOffSpill ✅ Log file.
ceSteps ✅ Log file.
ceDigi ✅ Log file.
muDauSteps ✅ Log file.
ceMix ✅ Log file.
rootOverlaps ✅ Log file.
g4surfaceCheck ✅ Log file.
trigger ✅ Log file.
check_cmake ✅ Log file.
FIXME, TODO ➡️ TODO (0) FIXME (10) in 6 files
clang-tidy ➡️ 1 errors 298 warnings
whitespace check ✅ no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at 393ac91 after being merged into the base branch at 30088f3.

For more information, please check the job page here.
Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #2143

Reviewed at head 393ac9137d347f06e15907c0bfb5f583d9399e8a. Follow-up to my comment review at the same head.

Decision

  • 🟢 approve. FNALbuild build 3601 has now built this head, merged on main 30088f39, and every test passed: the prof build, all eleven validation jobs, rootOverlaps, g4surfaceCheck, trigger, check_cmake and the whitespace check. The FIXME/TODO count and clang-tidy rows are informational; the one clang-tidy error is in cetlib's LibraryManager.h, not in this PR. This is the approval my comment review promised once the build was green. The two optional notes from that review still stand and do not block.

@oksuzian

Copy link
Copy Markdown
Collaborator

Independent check on a different sample: Mix1BB digitization (Production Mix.fcl + OneBB.fcl) of 300 cosmic events (245 written), main 554ef9f sources against this PR's head 393ac91, two alternating rounds on one host.

makeSD (TimeTracker mean, ms/event): main 91.5 / 96.1, this PR 64.6 / 67.7, ratio 0.71 / 0.70. Job user CPU drops about 8%. Outputs match main in every Events branch except 8 that also differ between two runs of main itself (the trigger RecoCount branches, EventHeader, and the CFO products).

I had a similar change locally. Its extras on top of this one (tail sum, saturation once per waveform, skipping zero ADC samples) save only 2-7 ms/event, about 1-2% of the job, so I won't open a separate PR. I can send them as a small follow-up after this merges if useful.

@FNALbuild

Copy link
Copy Markdown
Collaborator

📝 The HEAD of main has changed to 554ef9f. Tests are now out of date.

@brownd1978 brownd1978 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the AI test that the output is identical and the execution time reduced I approve. Nothing in the new code looks wrong or hard to maintain, though I have not evaluated every part as correct.

@brownd1978
brownd1978 requested a review from bonventre November 18, 2026 00:52
@oksuzian
oksuzian merged commit 2a7865c into Mu2e:main Nov 18, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants