Skip to content

Commit 88e5f8a

Browse files
committed
[RF] Make sure RooProjectedPdf compiled for normset is still RooAbsPdf
Also have a `dynamic_cast` check if the pdfClone inside createNLLImpl is actually a RooAbsPdf to prevent similar problems in the future.
1 parent 06cb8ba commit 88e5f8a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

roofit/roofitcore/src/FitHelpers.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ std::unique_ptr<RooAbsReal> createNLL(RooAbsPdf &pdf, RooAbsData &data, const Ro
764764
RooFit::Detail::CompileContext ctx{normSet};
765765
ctx.setLikelihoodMode(true);
766766
std::unique_ptr<RooAbsArg> head = pdf.compileForNormSet(normSet, ctx);
767-
std::unique_ptr<RooAbsPdf> pdfClone = std::unique_ptr<RooAbsPdf>{static_cast<RooAbsPdf *>(head.release())};
767+
std::unique_ptr<RooAbsPdf> pdfClone = std::unique_ptr<RooAbsPdf>{&dynamic_cast<RooAbsPdf &>(*head.release())};
768768

769769
// reset attributes
770770
pdf.setAttribute("SplitRange", false);

roofit/roofitcore/src/RooProjectedPdf.cxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ is therefore identical to that of <pre>f->createProjection(RooArgSet(x,y))</pre>
3434
#include "RooAbsReal.h"
3535
#include "RooRealVar.h"
3636
#include "RooNameReg.h"
37+
#include "RooWrapperPdf.h"
3738

3839

3940

@@ -286,6 +287,15 @@ RooProjectedPdf::compileForNormSet(RooArgSet const &normSet, RooFit::Detail::Com
286287
nset2.add(intobs);
287288

288289
auto newArg = std::unique_ptr<RooAbsReal>{intpdf->createIntegral(intobs, &nset2)};
290+
291+
std::string namePdf = std::string{newArg->GetName()} + "_wrapped_pdf";
292+
293+
auto newArgPdf = std::make_unique<RooWrapperPdf>(namePdf.c_str(), namePdf.c_str(), *newArg);
294+
289295
ctx.markAsCompiled(*newArg);
290-
return newArg;
296+
ctx.markAsCompiled(*newArgPdf);
297+
298+
newArgPdf->addOwnedComponents(std::move(newArg));
299+
300+
return newArgPdf;
291301
}

0 commit comments

Comments
 (0)