diff --git a/roofit/roostats/inc/RooStats/ToyMCImportanceSampler.h b/roofit/roostats/inc/RooStats/ToyMCImportanceSampler.h index c306c0a0a594430ff3069155aa35c2fac7073fbc..07900b378972c4a0b5581e7092b0d35f25e90df5 100644 --- a/roofit/roostats/inc/RooStats/ToyMCImportanceSampler.h +++ b/roofit/roostats/inc/RooStats/ToyMCImportanceSampler.h @@ -106,7 +106,7 @@ class ToyMCImportanceSampler: public ToyMCSampler { } if( p == NULL && fNullDensities.size() >= 1 ) p = fNullDensities[0]; - if( s == NULL ) s = fParametersForTestStat; + if( s == NULL ) s = fParametersForTestStat.get(); if( s ) s = (const RooArgSet*)s->snapshot(); fNullDensities.push_back( p ); diff --git a/roofit/roostats/inc/RooStats/ToyMCSampler.h b/roofit/roostats/inc/RooStats/ToyMCSampler.h index 9f42674b1d3f9efbd9267071e657ca0dda7e2a0a..372223dfc4c8c9fa7bd3b09470a3f155d079c4e7 100644 --- a/roofit/roostats/inc/RooStats/ToyMCSampler.h +++ b/roofit/roostats/inc/RooStats/ToyMCSampler.h @@ -31,9 +31,10 @@ #include "RooMsgService.h" #include "RooAbsPdf.h" #include "RooRealVar.h" - #include "RooDataSet.h" +#include <memory> + namespace RooStats { class DetailedOutputAggregator; @@ -155,8 +156,7 @@ class ToyMCSampler: public TestStatSampler { // Set the Pdf, add to the the workspace if not already there virtual void SetParametersForTestStat(const RooArgSet& nullpoi) { - if( fParametersForTestStat ) delete fParametersForTestStat; - fParametersForTestStat = (const RooArgSet*)nullpoi.snapshot(); + fParametersForTestStat.reset( nullpoi.snapshot() ); } virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; ClearCache(); } @@ -249,7 +249,7 @@ class ToyMCSampler: public TestStatSampler { // densities, snapshots, and test statistics to reweight to RooAbsPdf *fPdf; // model (can be alt or null) - const RooArgSet* fParametersForTestStat; + std::unique_ptr<const RooArgSet> fParametersForTestStat; std::vector<TestStatistic*> fTestStatistics; std::string fSamplingDistName; // name of the model @@ -296,7 +296,7 @@ class ToyMCSampler: public TestStatSampler { Bool_t fUseMultiGen ; // Use PrepareMultiGen? protected: - ClassDef(ToyMCSampler,3) // A simple implementation of the TestStatSampler interface + ClassDef(ToyMCSampler, 4) // A simple implementation of the TestStatSampler interface }; } diff --git a/roofit/roostats/src/ToyMCSampler.cxx b/roofit/roostats/src/ToyMCSampler.cxx index 245ea16f7541044ee76a35a7281fb98ed8ce2634..c6e75a31a152912218a7a402d7efd284909fea5a 100644 --- a/roofit/roostats/src/ToyMCSampler.cxx +++ b/roofit/roostats/src/ToyMCSampler.cxx @@ -154,7 +154,6 @@ ToyMCSampler::ToyMCSampler() : fSamplingDistName("SD"), fNToys(1) { fPdf = NULL; - fParametersForTestStat = NULL; fPriorNuisance = NULL; fNuisancePars = NULL; fObservables = NULL; @@ -194,7 +193,6 @@ ToyMCSampler::ToyMCSampler() : fSamplingDistName("SD"), fNToys(1) ToyMCSampler::ToyMCSampler(TestStatistic &ts, Int_t ntoys) : fSamplingDistName(ts.GetVarName().Data()), fNToys(ntoys) { fPdf = NULL; - fParametersForTestStat = NULL; fPriorNuisance = NULL; fNuisancePars = NULL; fObservables = NULL;