Skip to content

Fit speed develop - #3

Closed
anthoak13 wants to merge 12 commits into
developfrom
fit-speed-develop
Closed

anthoak13 wants to merge 12 commits into
developfrom
fit-speed-develop

Conversation

@anthoak13

Copy link
Copy Markdown
Owner

No description provided.

anthoak13 and others added 12 commits October 17, 2026 14:45
CATIMA replaced the extern catima::default_config with
catima::get_default_config() which broke how we were building it.

ROOT_INCLUDE_PATH needs a generator expression, so it was written to a
side file and appended to config.sh by a build-time sed/cat target.
This was overly fragile so now we write the full file at configure time.
 Also passed the AtPatternEvent to the GetModifiedTrack method since it may be useful too.
* Added a method to inhibit all beam pads from a csv map file. Actually prevented the inhibited pads from being unpacked. Added mappings of RCNP and e23031 experiments, with their respective beam pads mappings.

* Added a macro to draw the padplane with the pads that are actually in the beam region list, to check if it makes sense. Changed the check on the test to make sure it tests for kXTalk. Removed the 0,1,2,3,4 line from the beam pads list, since padID=4 does not actually belong to the beam region.

* Only skip unpacking total or x-talk, but not other types of inhibited pads

---------

Co-authored-by: anthoak13 <aanthon2@highpoint.edu>
Co-authored-by: pemi7269 <perine.miriot@orange.fr>
* Added AtENCourseEvent class to store information about the ENCourse, which for now is just the PPAC information stored in the AtPPACPair class, both for F2 and F3. Added test macros to run the merger and to plot the ENCourse PPAC data.

* Added the RF_ToF and TDC_Ref to the merger.

* Compile failure on GitHub because I forgot to include TTree.

* Added a check to see if the timestamps match between the ENCourse daq and the GET daq.

* Forgot to add memory header to the AtPPACPair class header.

* Make ENCourse tree a raw pointer

Its memory is already owned by its TFile which is a unique_ptr.

---------

Co-authored-by: anthoak13 <aanthon2@highpoint.edu>
* Implemented the calibration mapping as well as an example macro for testing.

* Applied the calibration map to the AtPSA so that it should be applied automatically to AtPSATask in case a calibration has been passed.

* Cleanup AtMap and re-use existing csv reader

Parse the calibration parameter file with CSVRange instead of
a custom reader. Require both a function and parameters in IsCalibrationSet
 and forward declare AtMap in AtPSA.h to avoid AtPSA needing the full
 header.

---------

Co-authored-by: anthoak13 <aanthon2@highpoint.edu>
AtMCFitterTask::Exec returned for an event without a good pattern
before clearing its result and saved-event arrays. That entry of the
output tree carried the previous event's results, which plots then
paired with the current event's truth, and if the first event was bad
its arrays were empty. Clear the arrays first, so a skipped event is
written with no results.

Fit files made before this repeat the previous event's results on
every skipped event. Refit them before plotting.
AtELossTable::GetRange already clamped the final energy to the table
minimum; clamp the initial energy to the table maximum the same way
instead of integrating past the end of the table. Log "Energy
converged" at debug level, since it fires on every GetEnergy call.

Also ignore the .cache directory (clangd index).
Add AtTools::Random: Get() returns the calling thread's generator, or
*gRandom when none is installed, so single-threaded sim and digi draw
exactly as before. ScopedGenerator installs a TRandom3 for its lifetime.

AtMCFitter::SetSeed sets the fit seed (drawn from random_device in Init
if unset). Each worker thread of each round installs a generator seeded
by MixSeed(seed, entry number, round, thread). Parameter distributions,
AtClusterize, AtPulse (including TF1::GetRandom), AtPulseLine and
AtPulseLineTask draw from Get(), replacing the per-thread mt19937
seeded from random_device and the shared gRandom. SetDoF now reaches
the Student sampler.
- AtMap::GetPadNum: look up the pad in a prebuilt grid (AtPadLookup)
  over the pad plane at 0.1 mm, built once under std::call_once and
  shared read-only by all threads (60 MB for the AT-TPC plane). A cell
  stores a pad only if its centre and four inset corners agree and no
  pad edge crosses it; otherwise it asks TH2Poly::FindBin. A scan of
  the whole plane has no mismatches with FindBin. The first lookup
  builds the table (~5 s). AtMap::SetUsePadLookup(false) turns it off.
- AtPulse: look up pad inhibition once per pad per line, not twice per
  time bucket (ThrowGain takes the low-gain factor).
- AtPulseLine: hoist bin centers and the fPadsWithCharge insert out of
  the time bucket loop.
- AtPulse::GetGain: draw the mean gain of 1 to 10 electrons as one
  exact Gamma(n(b+1), G/(b+1)) deviate (Erlang product of uniforms for
  integer shape up to 16) instead of averaging n TF1::GetRandom draws.
  The Polya gain with shape b is a Gamma distribution, so this is
  exact; GetRandom was interpolated from a table and cut off at 5 times
  the gain, lowering the one-electron mean by ~0.2% and variance by
  ~2%. The fast Gaussian path above 10 electrons is unchanged.

Only the gain change alters the random stream; output is statistically
equivalent but not bit-identical. Unit tests compare the pad lookup
with FindBin and the new gain draw with the old loop (mean, variance,
two-sample KS) and the exact moments.
ROOT::Fit::Fitter creates its minimizer through the plugin manager,
which takes ROOT's global write lock on every fit. The PSA makes about
250 fits per fitter iteration, so above ~4 threads the workers queue on
that lock. AtTools::MinimizeMigrad constructs a Minuit2Minimizer with a
Chi2FCN directly, with the same step sizes and call limit as Fitter;
AtPSADeconvFit and AtMCFission use it, and fit results are
bit-identical.

The TF1s built per hit in the E12014 hit sums, AtPSADeconvFit and
AtMCFission only evaluated a Gaussian. Replace them with a plain
AtTools::GaussianTB from GetHitGaussianTB.

Also build histograms in CreateHistFromData without toggling the global
TH1::AddDirectory flag from worker threads, compare AtMCResult by const
reference in the result set, and stop AtPSADeconv with a fatal error
when SetUseSimCharge(true) meets a pad without charge instead of
reading a missing augment.
Add the speed study (what changed, the Geant4 digitization check, fit
CPU and thread-scaling measurements, usage advice and open items), the
MC fitter threading model and its known bugs, and design notes on MC
truth and on units. Fix the fitting-status link in the index.
@anthoak13 anthoak13 closed this Oct 18, 2026
anthoak13 added a commit that referenced this pull request Oct 18, 2026
Adds code to get the true Z and A simulated. Adds two additional plots:
- `zHistSim` which plots the true simulated Zs. The pair to `zHist`.
- `hZvsObjSim` which plots the objective function vs true Z. This is the
pair to `hZvsObj`.
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.

2 participants