diff --git a/roofit/roofitcore/src/RooAddPdf.cxx b/roofit/roofitcore/src/RooAddPdf.cxx index ccbce5a3fc0c7..edc8f8963ec79 100644 --- a/roofit/roofitcore/src/RooAddPdf.cxx +++ b/roofit/roofitcore/src/RooAddPdf.cxx @@ -985,7 +985,7 @@ RooAddPdf::compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileCo } else { coefListNew.add(coefList()); } - auto newArg = std::make_unique(GetName(), GetTitle(), pdfList(), coefListNew, _recursive); + auto newArg = std::make_unique(GetName(), GetTitle(), pdfList(), coefListNew); // Copy some other info that the RooAddPdf copy constructor would otherwise take care of. newArg->setNormRange(normRange()); newArg->_codeReg = _codeReg; diff --git a/roofit/roofitcore/test/testRooAddPdf.cxx b/roofit/roofitcore/test/testRooAddPdf.cxx index 3a963f6bac0d2..1a299aaf39640 100644 --- a/roofit/roofitcore/test/testRooAddPdf.cxx +++ b/roofit/roofitcore/test/testRooAddPdf.cxx @@ -2,6 +2,7 @@ // Authors: Jonas Rembser, CERN 07/2022 #include +#include #include #include #include @@ -424,3 +425,31 @@ TEST(RooAddPdf, IntegralsForRangedFitWithIdenticalCoefRange) // of the component pdfs. EXPECT_EQ(iIntegrals, 2); } + +// Verify that likelihoods for Pdfs with recursive fractions can be created. +// Covers GitHub issues #21635 and #2144. +TEST(RooAddPdf, NLLWithRecursiveFractions) +{ + // Create observables + RooRealVar x("x", "x", -8, 8); + + // Construct signal pdf + RooRealVar mean("mean", "mean", 0, -8, 8); + RooRealVar sigma("sigma", "sigma", 0.3, 0.1, 10); + RooGaussian gx("gx", "gx", x, mean, sigma); + + // Construct background pdf + RooRealVar a0("a0", "a0", -0.1, -1, 1); + RooRealVar a1("a1", "a1", 0.004, -1, 1); + RooChebychev px("px", "px", x, RooArgList(a0, a1)); + + // Construct composite pdf + RooRealVar b("b", "b", 200, 0.0, 10000); + RooRealVar s("s", "s", 800, 0.0, 10000); + RooRealVar f("f", "f", 0.5, 0.0, 1.0); + RooAddPdf model("model", "model", RooArgList(gx, px), RooArgList(f), true); + + std::unique_ptr data{model.generate(RooArgSet(x), 1000)}; + + std::unique_ptr nll{model.createNLL(*data)}; +}