Skip to content

Store a cumulative fraction of 1 in 32-bit histogram contents as the largest value instead of converting out of range - #211

Merged
jbeirer merged 1 commit into
mainfrom
histogram-content-saturate
Nov 24, 2026
Merged

jbeirer merged 1 commit into
mainfrom
histogram-content-saturate

Conversation

@jbeirer

@jbeirer jbeirer commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

TFCS1DFunction_Numeric<T, Tfloat>::MaxCeilOnlyForInt stores a cumulative fraction in [0, 1] as ceil(MaxValueFloat * value). For T = uint32_t and Tfloat = float, MaxValueFloat = float(UINT32_MAX) rounds up to 2^32, so a fraction of 1 converts 4294967296.0f to uint32_t. That is undefined behaviour (-fsanitize=float-cast-overflow reports it). On x86-64 GCC 15 it gives 0, i.e. a cumulative fraction of 1 is stored as 0. It is reached by TFCS1DFunctionTemplateHistogram::Initialize (set_fraction) of TFCS1DFunctionInt8Int32Histogram and TFCS1DFunctionInt32Int32Histogram when a bin before the last reaches a fraction of 1 in single precision. The last bin's fraction is not stored, and after merged bins the stored value is dropped by the final resize, so only some histograms are affected. The bug is inherited: Athena upstream/main (ISF_FastCaloSimEvent, the uint32_t specialization of TFCS1DFunction_Numeric) has the same conversion. Nothing to port from Athena. 8 and 16 bit are not affected (255 and 65535 are exact in float).

Change

A fraction of 1 or more is stored as std::numeric_limits<T>::max(). For all other values, and for the 8 and 16-bit types, the result is unchanged. Only parametrization creation (Initialize) calls it, so simulation with existing files does not change. New HistogramContentTests: a fraction of 1 is stored as the largest value for 32 bit (and as before for 8 and 16 bit), and set_fraction/get_fraction of a 32-bit content round-trip 1.

Checks

Run on main (73c5cc7) with #205 to #213 together, against main:

  • GCC 15 (LCG_110, developer build): 0 warnings; ctest 138/138 passed (main: 128/128), incl. the unchanged AtlasTransportTests and AtlasSimTests references
  • AtlasBenchmark dump (BENCH_N=50): byte-identical to main
  • SliceCheck on the MC23 file TFCSparam_dev_Hybrid_Ha_v5_all_baryons_0_500.root (BENCH_N=20): byte-identical to main, max RSS 4.76 GB on both
  • clang-format 20.1.8
  • GCC 16 and Clang 22 with the CI flags: 0 warnings
  • Alma 10 ci-linux (clang-tidy 21, cppcheck): 0 warnings; its ctest 138/138 passed

…largest value instead of converting out of range
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74c9b3f2-2047-480c-a796-ccb0c522c1ad
Commits

Reviewing files that changed from the base of the PR and between 73c5cc7 and c0e99ab.

Files selected for processing: 2

  • include/FastCaloSim/Core/TFCS1DFunctionTemplateHelpers.h
  • test/source/HistogramContentTests.cxx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
test/source/HistogramContentTests.cxx 81.25% 3 Missing ⚠️
Files with missing lines Coverage Δ
...e/FastCaloSim/Core/TFCS1DFunctionTemplateHelpers.h 20.76% <100.00%> (+20.76%) ⬆️
test/source/HistogramContentTests.cxx 81.25% <81.25%> (ø)

@jbeirer
jbeirer merged commit 67b1a32 into main Nov 24, 2026
19 checks passed
@jbeirer
jbeirer deleted the histogram-content-saturate branch November 24, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Issues affecting the CI tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant