diff --git a/roofit/roofitcore/src/TestStatistics/ConstantTermsOptimizer.cxx b/roofit/roofitcore/src/TestStatistics/ConstantTermsOptimizer.cxx index 51a341084c80e..926c39c94743f 100644 --- a/roofit/roofitcore/src/TestStatistics/ConstantTermsOptimizer.cxx +++ b/roofit/roofitcore/src/TestStatistics/ConstantTermsOptimizer.cxx @@ -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 ownedObservables; if (observables == nullptr) { - observables = function->getObservables(dataset); - delete_observables = true; + ownedObservables = std::unique_ptr{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); diff --git a/roofit/roofitcore/test/TestStatistics/testRooAbsL.cxx b/roofit/roofitcore/test/TestStatistics/testRooAbsL.cxx index f5aeb9e684284..871e232d2368d 100644 --- a/roofit/roofitcore/test/TestStatistics/testRooAbsL.cxx +++ b/roofit/roofitcore/test/TestStatistics/testRooAbsL.cxx @@ -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{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; @@ -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("nlletje", "-log(likelihood)", *pdf, *data, projDeps, extended, nll_config); auto AbsL_value = likelihood->evaluatePartition({0, 1}, 0, likelihood->getNComponents()); auto RooNLL_value = nll->getVal(); @@ -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{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. \ No newline at end of file +// TODO: add tests covering all constOptimizeTestStatistic opcode cases.