Skip to content

Commit 3645164

Browse files
committed
[RF] Fix dirty flag resetting when the normalization set is changed
If the proxy normSet changed, we also have to set the value dirty flag of the proxy owner. Otherwise, value for the new normalization set might not get recomputed, which causes bugs! The issue can be reproduced with this small code snippet: ```C++ using namespace RooFit; RooRealVar x("x", "x", 0, -10, 10); RooGaussian gauss("gauss", "gauss", x, RooConst(0), RooConst(2)); RooAddition add("add", "add", {gauss}); std::cout << add.getVal() << std::endl; std::cout << add.getVal(x) << std::endl; ``` Without this commit, the value will be the same with and without normalization set, because changing only the normalization set didn't trigger a recomputation. This code snippet has also been implemented as a unit test now, where it is tested that the values are different.
1 parent 7b7983f commit 3645164

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

roofit/roofitcore/src/RooAbsArg.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,10 @@ void RooAbsArg::setProxyNormSet(const RooArgSet* nset)
13901390
for ( auto& p : _proxyListCache.cache ) {
13911391
p->changeNormSet(nset);
13921392
}
1393+
1394+
// If the proxy normSet changed, we also have to set our value dirty flag.
1395+
// Otherwise, value for the new normalization set might not get recomputed!
1396+
setValueDirty();
13931397
}
13941398

13951399

roofit/roofitcore/test/testRooAbsPdf.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Authors: Stephan Hageboeck, CERN 04/2020
33
// Jonas Rembser, CERN 04/2021
44

5+
#include <RooAddition.h>
56
#include <RooAddPdf.h>
67
#include <RooCategory.h>
78
#include <RooConstVar.h>
@@ -328,3 +329,21 @@ TEST(RooAbsPdf, ProblemsWith2DSimultaneousFit)
328329

329330
simPdf.fitTo(data, PrintLevel(-1));
330331
}
332+
333+
// Verifies that a server pdf gets correctly reevaluated when the normalization
334+
// set is changed.
335+
TEST(RooAbsPdf, NormSetChange)
336+
{
337+
using namespace RooFit;
338+
339+
RooRealVar x("x", "x", 0, -10, 10);
340+
RooGaussian gauss("gauss", "gauss", x, RooConst(0), RooConst(2));
341+
RooAddition add("add", "add", {gauss});
342+
343+
double v1 = add.getVal();
344+
double v2 = add.getVal(x);
345+
346+
// The change of normalization set should trigger a recomputation of the
347+
// value, so val2 should be different from val1. }
348+
EXPECT_NE(v1, v2);
349+
}

0 commit comments

Comments
 (0)