diff --git a/roofit/histfactory/src/HistFactoryModelUtils.cxx b/roofit/histfactory/src/HistFactoryModelUtils.cxx index e0a163525d2e8..5d20d1b80db67 100644 --- a/roofit/histfactory/src/HistFactoryModelUtils.cxx +++ b/roofit/histfactory/src/HistFactoryModelUtils.cxx @@ -56,7 +56,7 @@ namespace HistFactory{ if( ! FoundSumPdf ) { if(verbose) { std::cout << "Failed to find RooRealSumPdf for channel: " << sim_channel->GetName() << std::endl; - sim_channel->getComponents()->Print("V"); + components->Print("V"); } sum_pdf=nullptr; //throw std::runtime_error("Failed to find RooRealSumPdf for channel"); diff --git a/roofit/roofit/test/testFitPerf.cxx b/roofit/roofit/test/testFitPerf.cxx index b3d9522a46fb4..749a289ad139f 100644 --- a/roofit/roofit/test/testFitPerf.cxx +++ b/roofit/roofit/test/testFitPerf.cxx @@ -549,7 +549,7 @@ int FitUsingRooFit(TTree *tree, TF1 *func) int level = 3; std::cout << "num entries = " << data.numEntries() << std::endl; bool save = true; - (pdf.getVariables())->Print("v"); // print the parameters + std::unique_ptr{pdf.getVariables()}->Print("v"); // print the parameters #else int level = -1; bool save = false; @@ -630,7 +630,7 @@ int FitUsingRooFit2(TTree *tree) int level = 3; std::cout << "num entries = " << data.numEntries() << std::endl; bool save = true; - (pdf[N - 1]->getVariables())->Print("v"); // print the parameters + std::unique_ptr{pdf[N - 1]->getVariables()}->Print("v"); // print the parameters std::cout << "\n\nDo the fit now \n\n"; #else int level = -1; diff --git a/roofit/roofit/test/vectorisedPDFs/VectorisedPDFTests.cxx b/roofit/roofit/test/vectorisedPDFs/VectorisedPDFTests.cxx index 6d2c5adb01e7d..282865e692304 100644 --- a/roofit/roofit/test/vectorisedPDFs/VectorisedPDFTests.cxx +++ b/roofit/roofit/test/vectorisedPDFs/VectorisedPDFTests.cxx @@ -457,7 +457,7 @@ std::unique_ptr PDFTest::runBatchFit(RooAbsPdf *pdf) kickParameters(); makePlots(::testing::UnitTest::GetInstance()->current_test_info()->name() + std::string("_batch_prefit")); - auto pars = pdf->getParameters(*_dataFit); + std::unique_ptr pars{pdf->getParameters(*_dataFit)}; *pars = _parameters; for (unsigned int index = 0; index < pars->size(); ++index) { diff --git a/roofit/roofitcore/src/RooAbsReal.cxx b/roofit/roofitcore/src/RooAbsReal.cxx index 789034be93928..72e354575bf50 100644 --- a/roofit/roofitcore/src/RooAbsReal.cxx +++ b/roofit/roofitcore/src/RooAbsReal.cxx @@ -2247,10 +2247,10 @@ RooPlot* RooAbsReal::plotAsymOn(RooPlot *frame, const RooAbsCategoryLValue& asym // Take out data-projected dependents from projectedVars - RooArgSet* projDataNeededVars = nullptr ; + std::unique_ptr projDataNeededVars; if (o.projData) { - projDataNeededVars = projectedVars.selectCommon(projDataVars); - projectedVars.remove(projDataVars,true,true) ; + projDataNeededVars.reset(projectedVars.selectCommon(projDataVars)); + projectedVars.remove(projDataVars, true, true); } // Take out plotted asymmetry from projection diff --git a/roofit/roofitcore/src/RooRealMPFE.cxx b/roofit/roofitcore/src/RooRealMPFE.cxx index cd87846508e01..cc3529a15adb9 100644 --- a/roofit/roofitcore/src/RooRealMPFE.cxx +++ b/roofit/roofitcore/src/RooRealMPFE.cxx @@ -53,6 +53,7 @@ For general multiprocessing in ROOT, please refer to the TProcessExecutor class. #endif #include +#include #include #include "RooRealMPFE.h" #include "RooArgSet.h" @@ -170,7 +171,7 @@ void RooRealMPFE::initVars() _saveVars.removeAll() ; // Retrieve non-constant parameters - auto vars = _arg->getParameters(RooArgSet()); + std::unique_ptr vars{_arg->getParameters(RooArgSet())}; // RooArgSet *ncVars = vars->selectByAttrib("Constant", false); RooArgList varList(*vars) ; diff --git a/roofit/roofitcore/src/RooVectorDataStore.cxx b/roofit/roofitcore/src/RooVectorDataStore.cxx index 96c20887e309c..2f1b22d1b64b8 100644 --- a/roofit/roofitcore/src/RooVectorDataStore.cxx +++ b/roofit/roofitcore/src/RooVectorDataStore.cxx @@ -829,6 +829,7 @@ void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, std::vector nsetList ; std::vector> argObsList ; + std::vector> ownedNsets; // Now need to attach branch buffers of clones for (const auto arg : cloneSet) { @@ -844,8 +845,8 @@ void RooVectorDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, // std::cout << "RooVectorDataStore::cacheArgs() cached node " << arg->GetName() << " has a normalization set specification CATNormSet = " << catNset << std::endl ; RooArgSet anset = RooHelpers::selectFromArgSet(nset ? *nset : RooArgSet{}, catNset); - normSet = anset.selectCommon(*argObs); - + ownedNsets.emplace_back(anset.selectCommon(*argObs)); + normSet = ownedNsets.back().get(); } const char* catCset = arg->getStringAttribute("CATCondSet") ; if (catCset) { diff --git a/roofit/roofitcore/src/TestStatistics/RooAbsL.cxx b/roofit/roofitcore/src/TestStatistics/RooAbsL.cxx index 76ad278c4dfc8..badd019b14964 100644 --- a/roofit/roofitcore/src/TestStatistics/RooAbsL.cxx +++ b/roofit/roofitcore/src/TestStatistics/RooAbsL.cxx @@ -129,7 +129,7 @@ void RooAbsL::initClones(RooAbsPdf &inpdf, RooAbsData &indata) // ****************************************************************** // Attach FUNC to data set - auto _funcObsSet = pdf_->getObservables(indata); + std::unique_ptr _funcObsSet{pdf_->getObservables(indata)}; if (pdf_->getAttribute("BinnedLikelihood")) { pdf_->setAttribute("BinnedLikelihoodActive"); diff --git a/roofit/roostats/src/AsymptoticCalculator.cxx b/roofit/roostats/src/AsymptoticCalculator.cxx index 450604729bee8..899c604faeb1d 100644 --- a/roofit/roostats/src/AsymptoticCalculator.cxx +++ b/roofit/roostats/src/AsymptoticCalculator.cxx @@ -245,8 +245,8 @@ bool AsymptoticCalculator::Initialize() const { if (!fNominalAsimov) { if (verbose >= 0) oocoutI(nullptr,InputArguments) << "AsymptoticCalculator: Asimov data will be generated using fitted nuisance parameter values" << std::endl; - RooArgSet * tmp = (RooArgSet*) poiAlt.snapshot(); - fAsimovData = MakeAsimovData( data, *GetNullModel(), poiAlt, fAsimovGlobObs,tmp); + std::unique_ptr tmp{static_cast(poiAlt.snapshot())}; + fAsimovData = MakeAsimovData(data, *GetNullModel(), poiAlt, fAsimovGlobObs, tmp.get()); } else { diff --git a/roofit/roostats/src/HypoTestInverter.cxx b/roofit/roostats/src/HypoTestInverter.cxx index 9fa2bed777aaf..16f12bb86d21a 100644 --- a/roofit/roostats/src/HypoTestInverter.cxx +++ b/roofit/roostats/src/HypoTestInverter.cxx @@ -1237,7 +1237,8 @@ SamplingDistribution * HypoTestInverter::RebuildDistributions(bool isUpper, int inverter.SetData(*bkgdata); // print global observables - auto gobs = bModel->GetPdf()->getVariables()->selectCommon(* sbModel->GetGlobalObservables() ); + std::unique_ptr bModelVars{bModel->GetPdf()->getVariables()}; + std::unique_ptr gobs{bModelVars->selectCommon(*sbModel->GetGlobalObservables())}; gobs->Print("v"); HypoTestInverterResult * r = inverter.GetInterval(); diff --git a/roofit/roostats/src/LikelihoodIntervalPlot.cxx b/roofit/roostats/src/LikelihoodIntervalPlot.cxx index 5d4d669f5aa28..d072e35d1459a 100644 --- a/roofit/roostats/src/LikelihoodIntervalPlot.cxx +++ b/roofit/roostats/src/LikelihoodIntervalPlot.cxx @@ -194,7 +194,8 @@ void LikelihoodIntervalPlot::Draw(const Option_t *options) const double xcont_min = fInterval->LowerLimit(*myparam); const double xcont_max = fInterval->UpperLimit(*myparam); - RooRealVar* myarg = static_cast(newProfile->getVariables()->find(myparam->GetName())); + std::unique_ptr vars{newProfile->getVariables()}; + RooRealVar *myarg = static_cast(vars->find(myparam->GetName())); double x1 = myarg->getMin(); double x2 = myarg->getMax(); @@ -336,7 +337,8 @@ void LikelihoodIntervalPlot::Draw(const Option_t *options) double cont_level = ROOT::Math::chisquared_quantile(fInterval->ConfidenceLevel(),fNdimPlot); // level for -2log LR cont_level = cont_level/2; // since we are plotting -log LR - RooArgList params(*newProfile->getVariables()); + std::unique_ptr vars{newProfile->getVariables()}; + RooArgList params(*vars); // set values and error for the POI to the best fit values for (std::size_t i = 0; i < params.size(); ++i) { RooRealVar & par = static_cast( params[i]); diff --git a/roofit/roostats/src/PdfProposal.cxx b/roofit/roostats/src/PdfProposal.cxx index bbfbd2d0199f9..7abba52c9235e 100644 --- a/roofit/roostats/src/PdfProposal.cxx +++ b/roofit/roostats/src/PdfProposal.cxx @@ -177,8 +177,9 @@ double PdfProposal::GetProposalDensity(RooArgSet& x1, RooArgSet& x2) void PdfProposal::AddMapping(RooRealVar& proposalParam, RooAbsReal& update) { - fMaster.add(*update.getParameters(static_cast(nullptr))); - if (update.getParameters(static_cast(nullptr))->empty()) + std::unique_ptr params{update.getParameters(static_cast(nullptr))}; + fMaster.add(*params); + if (params->empty()) fMaster.add(update); fMap.insert(std::pair(&proposalParam, &update)); } diff --git a/roofit/roostats/src/SPlot.cxx b/roofit/roostats/src/SPlot.cxx index c18eefd053ecd..227948497bcf0 100644 --- a/roofit/roostats/src/SPlot.cxx +++ b/roofit/roostats/src/SPlot.cxx @@ -466,7 +466,8 @@ void SPlot::AddSWeight(RooAbsPdf *pdf, const RooArgList &yieldsTmp, const RooArg } const Int_t nspec = yieldsTmp.size(); - RooArgList yields = *static_cast(yieldsTmp.snapshot(false)); + std::unique_ptr yieldsSnapshot{static_cast(yieldsTmp.snapshot(false))}; + RooArgList &yields = *yieldsSnapshot; if (RooMsgService::instance().isActive(this, RooFit::InputArguments, RooFit::DEBUG)) { coutI(InputArguments) << "Printing Yields" << std::endl; diff --git a/roofit/roostats/src/SimpleLikelihoodRatioTestStat.cxx b/roofit/roostats/src/SimpleLikelihoodRatioTestStat.cxx index 03731ee4a1135..324514445e2c3 100644 --- a/roofit/roostats/src/SimpleLikelihoodRatioTestStat.cxx +++ b/roofit/roostats/src/SimpleLikelihoodRatioTestStat.cxx @@ -37,8 +37,10 @@ double RooStats::SimpleLikelihoodRatioTestStat::Evaluate(RooAbsData& data, RooAr // strip pdfs of constraints (which cancel out in the ratio) to avoid unnecessary computations and computational errors if (fFirstEval) { - fNullPdf = RooStats::MakeUnconstrainedPdf(*fNullPdf, *fNullPdf->getObservables(data)); - fAltPdf = RooStats::MakeUnconstrainedPdf(*fAltPdf , *fAltPdf->getObservables(data) ); + std::unique_ptr nullObs{fNullPdf->getObservables(data)}; + fNullPdf = RooStats::MakeUnconstrainedPdf(*fNullPdf, *nullObs); + std::unique_ptr altObs{fAltPdf->getObservables(data)}; + fAltPdf = RooStats::MakeUnconstrainedPdf(*fAltPdf, *altObs); } fFirstEval = false; diff --git a/roofit/roostats/src/ToyMCImportanceSampler.cxx b/roofit/roostats/src/ToyMCImportanceSampler.cxx index 2c997814b52f5..377c3a09699db 100644 --- a/roofit/roostats/src/ToyMCImportanceSampler.cxx +++ b/roofit/roostats/src/ToyMCImportanceSampler.cxx @@ -302,7 +302,7 @@ RooAbsData* ToyMCImportanceSampler::GenerateToyData( std::unique_ptr allVarsImpDens{fImportanceDensities[fIndexGenDensity]->getVariables()}; allVars->add(*allVarsImpDens); } - const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot(); + std::unique_ptr saveVars{static_cast(allVars->snapshot())}; double globalWeight = 1.0; if(fNuisanceParametersSampler) { // use nuisance parameters? @@ -413,10 +413,7 @@ RooAbsData* ToyMCImportanceSampler::GenerateToyData( ooccoutD(nullptr,InputArguments) << "weights["<assign(*saveVars); - delete saveVars; return data; } diff --git a/roofit/xroofit/src/xRooNode.cxx b/roofit/xroofit/src/xRooNode.cxx index 047756e6285fb..1505ccfef23dc 100644 --- a/roofit/xroofit/src/xRooNode.cxx +++ b/roofit/xroofit/src/xRooNode.cxx @@ -8905,9 +8905,9 @@ TH1 *xRooNode::BuildHistogram(RooAbsLValue *v, bool empty, bool errors, int binS for (auto pdf : bins()) { // auto _pdf = // pdf->get()->createProjection(*pdf->get()->getObservables(*_obs.get())); - auto _pdf = - new xRooProjectedPdf(TString::Format("%s_projection", pdf->GetName()), "", *pdf->get(), - *pdf->get()->getObservables(*_obs.get())); + std::unique_ptr projObs{pdf->get()->getObservables(*_obs.get())}; + auto _pdf = new xRooProjectedPdf(TString::Format("%s_projection", pdf->GetName()), "", + *pdf->get(), *projObs); if (hasRange) { dynamic_cast(_pdf)->setNormRange("coordRange"); }