Skip to content

Commit

Permalink
[RF] Make ROOT compile again also with -DROOFIT_MEMORY_SAFE_INTERFACES
Browse files Browse the repository at this point in the history
Thanks to Tomas Dado for noticing that this was broken.
  • Loading branch information
guitargeek committed Jun 27, 2024
1 parent 3e06a9c commit 8a9eb11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,12 @@ void ConstantTermsOptimizer::optimizeCaching(RooAbsReal *function, RooArgSet *no
function->getVal(norm_set);

// Set value caching mode for all nodes that depend on any of the observables to ADirty
bool delete_observables = false;
std::unique_ptr<RooArgSet> ownedObservables;
if (observables == nullptr) {
observables = function->getObservables(dataset);
delete_observables = true;
ownedObservables = std::unique_ptr<RooArgSet>{function->getObservables(dataset)};
observables = ownedObservables.get();
}
function->optimizeCacheMode(*observables);
if (delete_observables)
delete observables;

// Disable propagation of dirty state flags for observables
dataset->setDirtyProp(false);
Expand Down
14 changes: 7 additions & 7 deletions roofit/roofitcore/test/TestStatistics/testRooAbsL.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ TEST_F(BinnedDatasetTest, VSRooNLLVar)
{
// compare the value of the likelihood to that generated by a similarly configured RooNLLVar
pdf->setAttribute("BinnedLikelihood");
data.reset(pdf->generateBinned(*w.var("x")));
data = std::unique_ptr<RooAbsData>{pdf->generateBinned(*w.var("x"))};
likelihood = RooFit::TestStatistics::buildLikelihood(pdf, data.get());

// manually create NLL, ripping all relevant parts from RooAbsPdf::createNLL, except here we also set binnedL = true;
Expand All @@ -349,7 +349,7 @@ TEST_F(BinnedDatasetTest, VSRooNLLVar)
nll_config.cloneInputData = false;
nll_config.binnedL = true;
int extended = 2;
nll.reset(new RooNLLVar("nlletje", "-log(likelihood)", *pdf, *data, projDeps, extended, nll_config));
nll = std::make_unique<RooNLLVar>("nlletje", "-log(likelihood)", *pdf, *data, projDeps, extended, nll_config);

auto AbsL_value = likelihood->evaluatePartition({0, 1}, 0, likelihood->getNComponents());
auto RooNLL_value = nll->getVal();
Expand All @@ -358,15 +358,15 @@ TEST_F(BinnedDatasetTest, VSRooNLLVar)

TEST_F(SimBinnedConstrainedTest, VSRooNLLVar)
{
RooArgSet globalObservables{*w.var("alpha_bkg_obs_A"), *w.var("alpha_bkg_obs_B")};

// compare the value of the likelihood to that generated by a similarly configured RooNLLVar
likelihood = RooFit::TestStatistics::NLLFactory(*pdf, *data)
.GlobalObservables({*w.var("alpha_bkg_obs_A"), *w.var("alpha_bkg_obs_B")})
.build();
nll.reset(pdf->createNLL(*data, RooFit::GlobalObservables(*w.var("alpha_bkg_obs_A"), *w.var("alpha_bkg_obs_B"))));
likelihood = RooFit::TestStatistics::NLLFactory(*pdf, *data).GlobalObservables(globalObservables).build();
nll = std::unique_ptr<RooAbsReal>{pdf->createNLL(*data, RooFit::GlobalObservables(globalObservables))};

auto AbsL_value = likelihood->evaluatePartition({0, 1}, 0, likelihood->getNComponents());
auto RooNLL_value = nll->getVal();
EXPECT_EQ(AbsL_value.Sum(), RooNLL_value);
}

// TODO: add tests covering all constOptimizeTestStatistic opcode cases.
// TODO: add tests covering all constOptimizeTestStatistic opcode cases.

0 comments on commit 8a9eb11

Please sign in to comment.