Skip to content

[RF] Keep RooRealSumPdf integral code out of the codegen event loop - #23723

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:roofit-codegen-realsumpdf-integral-scope
Oct 15, 2026
Merged

guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:roofit-codegen-realsumpdf-integral-scope

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

The integral of a RooRealSumPdf reuses the translation of the sum itself, which placed its generated code via addToCodeBody(&arg, ...). Since the sum depends on the observables, the integral code ended up inside the event loop, even though the integral itself is data-independent.

For an extended RooRealSumPdf, the same integral is the pdf normalization inside the loop and the expected number of events that the extended term reads after the loop. Because codegen caches results by node name, the post-loop term referenced a loop-local variable and cling refused to compile the generated function:

error: use of undeclared identifier 't14'
    RooNLLVarNewResult += t14 - RooNLLVarNewWeightSum * std::log(t14);

Decide the scope of the generated code from the inputs of the sum instead of from the pdf node: the code is scope-independent if all functions (or component integrals) and coefficients are. For the pdf itself this is equivalent to the previous check, because the sum depends on the data exactly when one of its inputs does. For the integral it keeps the code outside the loop unless a coefficient depends on the data. This needs CodegenContext::isScopeIndependent() to be public.

Add an extended RooRealSumPdf case to testRooFuncWrapper that fails without the fix.

🤖 Done with the help of AI

The integral of a RooRealSumPdf reuses the translation of the sum
itself, which placed its generated code via addToCodeBody(&arg, ...).
Since the sum depends on the observables, the integral code ended up
inside the event loop, even though the integral itself is
data-independent.

For an extended RooRealSumPdf, the same integral is the pdf
normalization inside the loop and the expected number of events that the
extended term reads after the loop. Because codegen caches results by
node name, the post-loop term referenced a loop-local variable and cling
refused to compile the generated function:

    error: use of undeclared identifier 't14'
        RooNLLVarNewResult += t14 - RooNLLVarNewWeightSum * std::log(t14);

Decide the scope of the generated code from the inputs of the sum
instead of from the pdf node: the code is scope-independent if all
functions (or component integrals) and coefficients are. For the pdf
itself this is equivalent to the previous check, because the sum depends
on the data exactly when one of its inputs does. For the integral it
keeps the code outside the loop unless a coefficient depends on the
data. This needs CodegenContext::isScopeIndependent() to be public.

Add an extended RooRealSumPdf case to testRooFuncWrapper that fails
without the fix.

🤖 Done with the help of AI
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Test Results

    24 files      24 suites   4d 3h 5m 29s ⏱️
 3 889 tests  3 884 ✅ 0 💤 5 ❌
83 243 runs  83 238 ✅ 0 💤 5 ❌

For more details on these failures, see this check.

Results for commit 6d079f2.

♻️ This comment has been updated with latest results.

@guitargeek
guitargeek merged commit 2a8c520 into root-project:master Oct 15, 2026
62 of 67 checks passed
@guitargeek
guitargeek deleted the roofit-codegen-realsumpdf-integral-scope branch October 15, 2026 14:18
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.

2 participants