Skip to content

Refactor PRA#4

Draft
anthoak13 wants to merge 11 commits intoYassid:OpenKF-Claudefrom
anthoak13:OpenKFYassidClaude
Draft

Refactor PRA#4
anthoak13 wants to merge 11 commits intoYassid:OpenKF-Claudefrom
anthoak13:OpenKFYassidClaude

Conversation

@anthoak13
Copy link
Copy Markdown

This was the easiest way I could think of to see the summary of changes made in the refactor so far

anthoak13 and others added 11 commits March 8, 2026 13:41
* Add CLAUDE.md file

* Add AtELossBetheBloch analytic energy loss model

Implements the Bethe-Bloch stopping power formula as a new AtELossModel
subclass supporting heavy charged particles (PDG 2022, Eq. 34.1) and
electrons (Leo 1994, Eq. 2.38). A tk::spline cache of dx/dE enables
O(log n) range integrals. Newton's method is used for GetEnergy,
matching the AtELossTable strategy. Straggling uses the Bohr
approximation. Low-energy breakdown of the formula is handled by
extrapolating dEdx ∝ sqrt(E) below the validity threshold.

Includes 8 unit tests (proton/alpha/pion/electron in H2 and Ar,
self-consistency, straggling sanity, Bloch approximation) and a ROOT
macro to plot proton stopping power in Al for visual comparison against
the PDG reference curve.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add more robust pion tests

* Fix AtELossBetheBloch setters to rebuild spline automatically

SetMaterial, SetI, and SetDensity all change physical parameters that
the cached dx/dE spline depends on, but previously left it stale.
SetMaterial now calls BuildSpline at the end (removing the redundant
explicit call from the constructor). SetI is moved from an inline
header one-liner to a proper definition that rebuilds the spline.
SetDensity overrides the base class virtual and rebuilds the spline
after updating fDensity.

Adds SettersRebuildSpline test to verify each setter takes effect
immediately without a manual BuildSpline call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add record of Claude log for Bethe Impl

* Move level of debug statement

* Fix clang-formatting

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
* First attempt at fixing bug

* Fix Bethe-Bloch straggling and add CATIMA benchmark tests

- GetElossStraggling/GetdEdxStraggling: evaluate dEdx at energyFin
  (Tschalar formula requires stopping power at the exit point, not
  entrance; error was largest near the Bragg peak)
- BuildSpline: replace manual trapezoidal rule for Ω²(E) with a spline
  of 1/dEdx³ and segment-wise Simpson integration (exact for cubics)
- AtELossCATIMA: add fConfig member and SetConfig() so callers can
  tune the CATIMA calculation model; thread fConfig through all catima
  API calls (default_config preserves existing behaviour)
- AtELossBetheBlochTest: add AtELossBetheBlochVsCATIMAFixture comparing
  GetRangeVariance and GetElossStraggling against pure-Bohr CATIMA
  (z_eff_type::none) at narrow and wide energy traversals up to 10→1 MeV

* Add energy loss model comparison macro

* Add documentation useful for agents/humans

Add documentation into four subdirectories directly under docs/:
- tooling/: installation, daily-use (merged setup+building), testing
- contributing/: contributor guide, new-module, code-style
- reference/: modules, data-model, branch-io-contracts, macro-cookbook
- subsystems/: simulation/reconstruction pipelines, generators, psa, energy-loss

docs/development/ is reserved for branch-specific in-progress
notes (fitting-status.md, UKF.md, etc.).

Update all cross-links and the CLAUDE.md to point to the new docs
rather than repeat the information.

* Fix MeV/cm vs MeV/mm unit error in AtELossCATIMA

GetBraggCurve stored result.dEdxi * fDensity directly (MeV/cm) into
the output vector, while all other paths (GetdEdx, base-class
GetBraggCurve) divide by 10 to convert to MeV/mm.  The energy-step
calculation in the same loop used dEdx * rangeStepSize / 10, which
accidentally cancelled the unit error during tracking, so range and
energy results were unaffected — only the returned dEdx y-values were
10× too large, inflating the displayed Bragg peak height relative to
BB and SRIM curves.

Adds a fourth model per scenario — CATIMA with bare projectile charge
(z_eff_type::none) and dEdx corrections disabled (no Barkas, Lindhard,
or shell corrections) — to isolate which physics differences drive the
disagreement between Bethe-Bloch and full CATIMA:

- dEdx/range divergence at low energy → effective charge (Pierce-Blann)
- Range straggling floor in BB vs steep fall in CATIMA → Firsov/Lindhard-X
  straggling correction (hardwired in CATIMA, absent in BB)
- Bragg peak shape difference → effective charge suppressing dEdx as v→0

* Update checkout github action version
This commit captures the current midpoint in the cluster-covariance comparison plan.

Included here:
- behavior-preserving refactor scaffolding in AtTrackTransformer
- explicit covariance mode selection for transformer_direct vs hit_cluster_online
- characterization tests that lock down current transformer behavior
- synthetic and digi comparison hooks in the OpenKF test harness
- the planning document being used to drive the remaining work

Not complete yet:
- digi file generation and end-to-end digi comparison execution
- full test sweep and result interpretation
- any follow-on physics cleanup or production hardening
Add a small interpreted 16C(p,p) simulation regression for the PRA -> UKF path in macro/tests/AT-TPC.

The new macros generate the simulation sample, run the reconstruction chain, and assert that the output contains nontrivial AtPatternEvent and AtTrackingEvent content. Update the AT-TPC macro test runner and document that repo macros must be run interpreted rather than through ACLiC.

The regression was run on the current branch and on baseline commit a36d13a. Both produced the same summary counts: entries=8, PRA events=3, PRA tracks=3, fitted events=5, fitted tracks=5.
Record the active PRA refactor plan and current status in development docs.

Separate the current transformer-direct and online covariance cluster-building logic into an internal AtTrackClusterBuilder helper while keeping AtTrackTransformer's public API unchanged.

Include the seam-1 characterization work already present in the tree: expose raw TC candidate construction as a distinct phase, add track refiner and seeder component tests, and register those reconstruction tests in CMake.

Verification:
- cmake --build build --target AtToolsTests AtReconstructionTests -j10
- ./build/tests/AtToolsTests '--gtest_filter=AtTrackTransformerCovarianceTest.*:AtTrackClusterBuilderTest.*'
- ./build/tests/AtReconstructionTests '--gtest_filter=AtPRABehaviorTest.*:AtTrackRefinerTest.*:AtTrackSeederTest.*'
Re-ran run_ukf_digi.C on 1000 events (20-90° CMS, H2 300 torr) to verify
the PRA seam-1 refactor preserved reconstruction performance. Results are
unchanged: bias +0.31%, RMS 1.09%, 100% convergence, ~1mm residual.

Update docs/development/UKF.md:
- Replace stale 50-event/-1.6% validation table with current 1000-event results
- Add bias history table tracing the -1.6% → +0.31% evolution across commits
- Preserve mitigation options discussion; update source-2 status to residual ~0.3%

Add macro/Simulation/ATTPC/16C_pp/README.md:
- New doc summarising the purpose and run instructions for all 16 macros
- Typical workflow section with current expected quantitative outcomes

Co-Authored-By: Claude Sonnet 4.6 <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.

1 participant