diff --git a/AGENTS.md b/AGENTS.md index 083b7c0f..5646aaae 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,7 +15,8 @@ footprint. - `include/aare/` contains the public C++ API and header-defined templates. - `src/` contains C++ implementations and colocated Catch2 tests named - `*.test.cpp`. + `*.test.cpp`, grouped into `src/fit/`, `src/hist/` and `src/utils/` where + a component has several private files. - `tests/` contains the C++ test executable, configuration, and shared helpers. - `python/src/` contains pybind11 bindings and module registration. - `python/aare/` contains Python facades, convenience APIs, and public exports. @@ -147,18 +148,24 @@ lives in `python/aare/transform.py` on top of C++ generators. `RisingScurve`, `FallingScurve`, `GaussianErfcPlateau`, `GaussianChargeSharing`, ...) form the public fitting API. Each model provides `eval`, `eval_and_grad`, `is_valid`, `estimate_par`, and -`param_info`. `FitModel` is plain data (limits, fixed flags, start values, -minimizer settings) and selects one of three minimizers through -`aare::Minimizer`: Minuit2's Migrad (default) and Fumili, or the built-in -Levenberg-Marquardt solver in `src/LevenbergMarquardt.hpp`. `src/Fit.cpp` -holds the `FitModel` method bodies, the per-thread `detail::PixelFitter` -that dispatches on the minimizer, `fit_pixel`/`fit_3d`, and the explicit -instantiations; `src/FitHelpers.hpp` holds the start-value precedence and -shape checks. `src/FitMinuit2.cpp` (with `src/Chi2.hpp` and -`src/MinuitSteps.hpp`) is the only translation unit that includes Minuit2 -headers; Minuit2 is a private, `BUILD_INTERFACE`-only dependency of -`aare_core`. The `[fit]` tests run every configuration through all three -minimizers and check that they agree; run them when changing any solver. +`param_info`; the separable models also declare their linear parameters +(`linear_par`, `basis_and_grad`, `basis_columns`). `FitModel` is plain data +(limits, fixed flags, start values, minimizer settings) and selects one of +four minimizers through `aare::Minimizer`: Minuit2's Migrad (default) and +Fumili, or the built-in Levenberg-Marquardt and variable projection +solvers. The private implementation lives in `src/fit/`: `Fit.cpp` holds +the `FitModel` method bodies, the per-thread `detail::PixelFitter` that +dispatches on the minimizer and falls back from VarPro to +Levenberg-Marquardt, `fit_pixel`/`fit_3d`, and the explicit +instantiations; `FitHelpers.hpp` holds the start-value precedence and +shape checks; `DampedGaussNewton.hpp` is the damped Gauss-Newton driver +shared by `LevenbergMarquardt.hpp` and `VariableProjection.hpp`, with the +small fixed-size linear algebra on `std::array` (`Vec`, `Mat`). +`FitMinuit2.cpp` (with `Chi2.hpp` and `MinuitSteps.hpp`) is the only +translation unit that includes Minuit2 headers; Minuit2 is a private, +`BUILD_INTERFACE`-only dependency of `aare_core`. The `[fit]` tests run +every configuration through all four minimizers and check that they +agree; run them when changing any solver. ### Python layer diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f088391..8a1aa4eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -400,8 +400,8 @@ set(SourceFiles ${CMAKE_CURRENT_SOURCE_DIR}/src/Dtype.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/FilePtr.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/Fit.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/FitMinuit2.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/fit/Fit.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/fit/FitMinuit2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Interpolator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/JungfrauDataFile.cpp @@ -462,7 +462,7 @@ if(AARE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/src/decode.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Dtype.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/FilePtr.test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/Fit.test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/fit/Fit.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/DetectorGeometry.test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Interpolation.test.cpp diff --git a/src/Chi2.hpp b/src/fit/Chi2.hpp similarity index 100% rename from src/Chi2.hpp rename to src/fit/Chi2.hpp diff --git a/src/DampedGaussNewton.hpp b/src/fit/DampedGaussNewton.hpp similarity index 100% rename from src/DampedGaussNewton.hpp rename to src/fit/DampedGaussNewton.hpp diff --git a/src/Fit.cpp b/src/fit/Fit.cpp similarity index 100% rename from src/Fit.cpp rename to src/fit/Fit.cpp diff --git a/src/Fit.test.cpp b/src/fit/Fit.test.cpp similarity index 100% rename from src/Fit.test.cpp rename to src/fit/Fit.test.cpp diff --git a/src/FitHelpers.hpp b/src/fit/FitHelpers.hpp similarity index 100% rename from src/FitHelpers.hpp rename to src/fit/FitHelpers.hpp diff --git a/src/FitMinuit2.cpp b/src/fit/FitMinuit2.cpp similarity index 100% rename from src/FitMinuit2.cpp rename to src/fit/FitMinuit2.cpp diff --git a/src/FitMinuit2.hpp b/src/fit/FitMinuit2.hpp similarity index 100% rename from src/FitMinuit2.hpp rename to src/fit/FitMinuit2.hpp diff --git a/src/LevenbergMarquardt.hpp b/src/fit/LevenbergMarquardt.hpp similarity index 100% rename from src/LevenbergMarquardt.hpp rename to src/fit/LevenbergMarquardt.hpp diff --git a/src/MinuitSteps.hpp b/src/fit/MinuitSteps.hpp similarity index 100% rename from src/MinuitSteps.hpp rename to src/fit/MinuitSteps.hpp diff --git a/src/VariableProjection.hpp b/src/fit/VariableProjection.hpp similarity index 100% rename from src/VariableProjection.hpp rename to src/fit/VariableProjection.hpp