diff --git a/interface/AtlasPdfs.h b/interface/AtlasPdfs.h index 11964a8ba66..dcac0e486fa 100644 --- a/interface/AtlasPdfs.h +++ b/interface/AtlasPdfs.h @@ -372,9 +372,6 @@ class RooStarMomentMorph : public RooAbsPdf { mutable std::vector _nnuis; mutable std::vector _nref; - TIterator* _parItr ; //! do not persist - TIterator* _obsItr ; //! do not persist - TIterator* _pdfItr ; //! mutable TMatrixD* _M; //! Setting _setting; diff --git a/interface/FastTemplateFunc.h b/interface/FastTemplateFunc.h index b7cf2bad56a..e8120a64067 100644 --- a/interface/FastTemplateFunc.h +++ b/interface/FastTemplateFunc.h @@ -19,15 +19,12 @@ template class FastTemplateFunc_t : public RooAbsReal{ virtual inline ~FastTemplateFunc_t(){} void setProxyList(RooListProxy& proxyList, RooArgList& varList){ - TIterator* varIter = varList.createIterator(); - RooAbsArg* var; - while ((var = (RooAbsArg*)varIter->Next())) { + for (RooAbsArg *var : varList) { if (!dynamic_cast(var)) { assert(0); } proxyList.add(*var); } - delete varIter; } virtual TObject* clone(const char* newname) const = 0; diff --git a/interface/HZZ4L_RooSpinZeroPdf_1D.h b/interface/HZZ4L_RooSpinZeroPdf_1D.h index 8410e44e98a..c0c3939833f 100644 --- a/interface/HZZ4L_RooSpinZeroPdf_1D.h +++ b/interface/HZZ4L_RooSpinZeroPdf_1D.h @@ -28,7 +28,6 @@ class HZZ4L_RooSpinZeroPdf_1D : public RooAbsPdf { // RooRealProxy ksmd ; RooRealProxy fai ; RooListProxy _coefList ; // List of funcficients - TIterator* _coefIter ; //! Iterator over funcficient lis Double_t evaluate() const ; public: HZZ4L_RooSpinZeroPdf_1D() {} ; diff --git a/interface/ProcessNormalization.h b/interface/ProcessNormalization.h index d99aec236e3..dd09d64525e 100644 --- a/interface/ProcessNormalization.h +++ b/interface/ProcessNormalization.h @@ -1,7 +1,6 @@ #ifndef HiggsAnalysis_CombinedLimit_ProcessNormalization_h #define HiggsAnalysis_CombinedLimit_ProcessNormalization_h -#include #include #include "RooListProxy.h" diff --git a/interface/RooMultiPdf.h b/interface/RooMultiPdf.h index bb7f4176e49..6b196e0245a 100644 --- a/interface/RooMultiPdf.h +++ b/interface/RooMultiPdf.h @@ -17,7 +17,6 @@ #include "RooConstVar.h" -#include "TIterator.h" #include "RooListProxy.h" #include diff --git a/interface/SimpleCacheSentry.h b/interface/SimpleCacheSentry.h index 28d895298df..4a90b4ba1bc 100644 --- a/interface/SimpleCacheSentry.h +++ b/interface/SimpleCacheSentry.h @@ -3,7 +3,6 @@ #include "RooRealVar.h" #include "RooSetProxy.h" -#include "TIterator.h" class SimpleCacheSentry : public RooAbsArg { public: diff --git a/interface/VerticalInterpHistPdf.h b/interface/VerticalInterpHistPdf.h index 889437b23c6..a361ddfd59d 100644 --- a/interface/VerticalInterpHistPdf.h +++ b/interface/VerticalInterpHistPdf.h @@ -41,8 +41,6 @@ class VerticalInterpHistPdf : public RooAbsPdf { RooListProxy _coefList ; // List of coefficients Double_t _smoothRegion; Int_t _smoothAlgo; - TIterator* _funcIter ; //! Iterator over FUNC list - TIterator* _coefIter ; //! Iterator over coefficient list // TH1 containing the histogram of this pdf mutable SimpleCacheSentry _sentry; // !not to be serialized @@ -93,8 +91,6 @@ class FastVerticalInterpHistPdfBase : public RooAbsPdf { RooListProxy _coefList ; // List of coefficients Double_t _smoothRegion; Int_t _smoothAlgo; - TIterator* _funcIter ; //! Iterator over FUNC list - TIterator* _coefIter ; //! Iterator over coefficient list // TH1 containing the histogram of this pdf mutable bool _init; //! not to be serialized diff --git a/interface/VerticalInterpPdf.h b/interface/VerticalInterpPdf.h index 761b2f1194b..b655dc86376 100644 --- a/interface/VerticalInterpPdf.h +++ b/interface/VerticalInterpPdf.h @@ -46,8 +46,6 @@ class VerticalInterpPdf : public RooAbsPdf { RooListProxy _coefList ; // List of coefficients Double_t _quadraticRegion; Int_t _quadraticAlgo; - TIterator* _funcIter ; //! Iterator over FUNC list - TIterator* _coefIter ; //! Iterator over coefficient list Double_t _pdfFloorVal; // PDF floor should be customizable, default is 1e-15 Double_t _integralFloorVal; // PDF integral floor should be customizable, default is 1e-10 diff --git a/src/AsimovUtils.cc b/src/AsimovUtils.cc index d453443c0c6..7a5d99aec3f 100644 --- a/src/AsimovUtils.cc +++ b/src/AsimovUtils.cc @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -21,8 +20,7 @@ RooAbsData *asimovutils::asimovDatasetNominal(RooStats::ModelConfig *mc, double if (verbose>2) { CombineLogger::instance().log("AsimovUtils.cc",__LINE__,"Parameters after fit for asimov dataset",__func__); - std::unique_ptr iter(mc->GetPdf()->getParameters((const RooArgSet*) 0)->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *std::unique_ptr{mc->GetPdf()->getParameters((const RooArgSet*) 0)}) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("AsimovUtils.cc",__LINE__,std::string(Form("%s",varstring.Data())),__func__); } @@ -45,8 +43,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD } else { // Do we have free parameters anyway that need fitting? std::unique_ptr params(mc->GetPdf()->getParameters(realdata)); - std::unique_ptr iter(params->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *params) { RooRealVar *rrv = dynamic_cast(a); if ( rrv != 0 && rrv->isConstant() == false ) { needsFit &= true; break; } } @@ -67,8 +64,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD if (verbose>2) { CombineLogger::instance().log("AsimovUtils.cc",__LINE__,"Parameters after fit for asimov dataset",__func__); - std::unique_ptr iter(mc->GetPdf()->getParameters(realdata)->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *std::unique_ptr{mc->GetPdf()->getParameters(realdata)}) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("AsimovUtils.cc",__LINE__,std::string(Form("%s",varstring.Data())),__func__); } @@ -92,8 +88,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD std::unique_ptr nuispdf(utils::makeNuisancePdf(*mc)); RooProdPdf *prod = dynamic_cast(nuispdf.get()); if (prod == 0) throw std::runtime_error("AsimovUtils: the nuisance pdf is not a RooProdPdf!"); - std::unique_ptr iter(prod->pdfList().createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : prod->pdfList()) { RooAbsPdf *cterm = dynamic_cast(a); if (!cterm) throw std::logic_error("AsimovUtils: a factor of the nuisance pdf is not a Pdf!"); if (!cterm->dependsOn(nuis)) continue; // dummy constraints @@ -109,8 +104,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD if (cpars->getSize() == 1) { match = dynamic_cast(cpars->first()); } else { - std::unique_ptr iter2(cpars->createIterator()); - for (RooAbsArg *a2 = (RooAbsArg *) iter2->Next(); a2 != 0; a2 = (RooAbsArg *) iter2->Next()) { + for (RooAbsArg *a2 : *cpars) { RooRealVar *rrv2 = dynamic_cast(a2); if (rrv2 != 0 && !rrv2->isConstant()) { if (match != 0) throw std::runtime_error(Form("AsimovUtils: constraint term %s has multiple floating params", cterm->GetName())); @@ -138,10 +132,10 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD // we want to set the global obs to a value for which the current value // of the nuisance is the best fit one. // best fit x = (k-1)*theta ----> k = x/theta + 1 - RooArgList leaves; cterm->leafNodeServerList(&leaves); - std::unique_ptr iter2(leaves.createIterator()); + RooArgList leaves; + cterm->leafNodeServerList(&leaves); RooAbsReal *match2 = 0; - for (RooAbsArg *a2 = (RooAbsArg *) iter2->Next(); a2 != 0; a2 = (RooAbsArg *) iter2->Next()) { + for (RooAbsArg *a2 : leaves) { RooAbsReal *rar = dynamic_cast(a2); if (rar == 0 || rar == match || rar == &rrv) continue; if (!rar->isConstant()) throw std::runtime_error(Form("AsimovUtils: extra floating parameter %s of RooGamma %s.", rar->GetName(), cterm->GetName())); diff --git a/src/AsymptoticLimits.cc b/src/AsymptoticLimits.cc index 75563600626..7759064503b 100644 --- a/src/AsymptoticLimits.cc +++ b/src/AsymptoticLimits.cc @@ -107,8 +107,7 @@ bool AsymptoticLimits::run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStat */ hasDiscreteParams_ = false; if (params_.get() == 0) params_.reset(mc_s->GetPdf()->getParameters(data)); - std::unique_ptr itparam(params_->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) itparam->Next(); a != 0; a = (RooAbsArg *) itparam->Next()) { + for (RooAbsArg *a : *params_) { if (a->IsA()->InheritsFrom(RooCategory::Class())) { hasDiscreteParams_ = true; break; } } @@ -164,8 +163,7 @@ bool AsymptoticLimits::runLimit(RooWorkspace *w, RooStats::ModelConfig *mc_s, Ro if (params_.get() == 0) params_.reset(mc_s->GetPdf()->getParameters(data)); hasFloatParams_ = false; - std::unique_ptr itparam(params_->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) itparam->Next(); a != 0; a = (RooAbsArg *) itparam->Next()) { + for (RooAbsArg *a : *params_) { RooRealVar *rrv = dynamic_cast(a); if ( rrv != 0 && rrv != r && rrv->isConstant() == false ) { hasFloatParams_ = true; break; } } diff --git a/src/AtlasPdfs.cxx b/src/AtlasPdfs.cxx index 34e758a3ad2..2e463c89de7 100644 --- a/src/AtlasPdfs.cxx +++ b/src/AtlasPdfs.cxx @@ -433,10 +433,8 @@ RooBSpline::RooBSpline(const char* name, const char* title, //bool even = fabs(_n/2-_n/2.) < 0.0000000001; bool first=1; - TIterator* pointIter = controlPoints.createIterator() ; - RooAbsArg* point ; RooAbsArg* lastPoint=NULL ; - while((point = (RooAbsArg*)pointIter->Next())) { + for (RooAbsArg * point : controlPoints) { if (!dynamic_cast(point)) { coutE(InputArguments) << "RooBSpline::ctor(" << GetName() << ") ERROR: control point " << point->GetName() << " is not of type RooAbsReal" << std::endl ; @@ -456,19 +454,9 @@ RooBSpline::RooBSpline(const char* name, const char* title, lastPoint=point; } for (int i=0;i<(_n)/2;i++) _controlPoints.add(*lastPoint); - delete pointIter ; - TIterator* varItr = vars.createIterator(); - RooAbsArg* arg; - while ((arg=(RooAbsArg*)varItr->Next())) { - //std::cout << "======== Adding "<GetName()<<" to list of _vars of "<Next())) { + for (RooAbsArg *point : weights) { if (!dynamic_cast(point)) { coutE(InputArguments) << "RooBSpline::ctor(" << GetName() << ") ERROR: control point " << point->GetName() << " is not of type RooAbsReal" << std::endl ; @@ -577,7 +563,6 @@ void RooBSpline::setWeights(const RooArgList& weights) lastPoint=point; } for (int i=0;i<(_n+1)/2;i++) _weights.add(*lastPoint); - delete pointIter; } @@ -1235,9 +1220,6 @@ RooStarMomentMorph::RooStarMomentMorph() : { // coverity[UNINIT_CTOR] - _parItr = _parList.createIterator() ; - _obsItr = _obsList.createIterator() ; - _pdfItr = _pdfList.createIterator() ; } @@ -1269,45 +1251,31 @@ RooStarMomentMorph::RooStarMomentMorph(const char *name, const char *title, // CTOR // fit parameters - TIterator* parItr = parList.createIterator() ; - RooAbsArg* par ; - for (Int_t i=0; (par = (RooAbsArg*)parItr->Next()); ++i) { + for (RooAbsArg *par : parList) { if (!dynamic_cast(par)) { coutE(InputArguments) << "RooStarMomentMorph::ctor(" << GetName() << ") ERROR: parameter " << par->GetName() << " is not of type RooAbsReal" << endl ; throw std::string("RooStarMomentMorh::ctor() ERROR parameter is not of type RooAbsReal") ; } _parList.add(*par) ; } - delete parItr ; // observables - TIterator* obsItr = obsList.createIterator() ; - RooAbsArg* var ; - for (Int_t i=0; (var = (RooAbsArg*)obsItr->Next()); ++i) { + for (RooAbsArg *var : obsList) { if (!dynamic_cast(var)) { coutE(InputArguments) << "RooStarMomentMorph::ctor(" << GetName() << ") ERROR: variable " << var->GetName() << " is not of type RooAbsReal" << endl ; throw std::string("RooStarMomentMorh::ctor() ERROR variable is not of type RooAbsReal") ; } _obsList.add(*var) ; } - delete obsItr ; // reference p.d.f.s - TIterator* pdfItr = pdfList.createIterator() ; - RooAbsPdf* pdf ; - for (Int_t i=0; (pdf = dynamic_cast(pdfItr->Next())); ++i) { - if (!pdf) { + for (RooAbsArg *pdf : pdfList) { + if (!dynamic_cast(pdf)) { coutE(InputArguments) << "RooStarMomentMorph::ctor(" << GetName() << ") ERROR: pdf " << pdf->GetName() << " is not of type RooAbsPdf" << endl ; throw std::string("RooStarMomentMorph::ctor() ERROR pdf is not of type RooAbsPdf") ; } _pdfList.add(*pdf) ; } - delete pdfItr ; - - _parItr = _parList.createIterator() ; - _obsItr = _obsList.createIterator() ; - _pdfItr = _pdfList.createIterator() ; - // initialization initialize(); @@ -1329,12 +1297,6 @@ RooStarMomentMorph::RooStarMomentMorph(const RooStarMomentMorph& other, const ch _nnuisvar(other._nnuisvar), _useHorizMorph(other._useHorizMorph) { - - - _parItr = _parList.createIterator() ; - _obsItr = _obsList.createIterator() ; - _pdfItr = _pdfList.createIterator() ; - // nref is resized in initialize, so reduce the size here if (_nref.size()>0) { _nref.resize( _nref.size()-1 ); @@ -1347,9 +1309,6 @@ RooStarMomentMorph::RooStarMomentMorph(const RooStarMomentMorph& other, const ch //_____________________________________________________________________________ RooStarMomentMorph::~RooStarMomentMorph() { - if (_parItr) delete _parItr; - if (_obsItr) delete _obsItr; - if (_pdfItr) delete _pdfItr; if (_M) delete _M; } @@ -1512,15 +1471,11 @@ RooStarMomentMorph::CacheElem* RooStarMomentMorph::getCache(const RooArgSet* /*n //} // construction of unit pdfs - _pdfItr->Reset(); - RooAbsPdf* pdf; RooArgList transPdfList; for (Int_t i=0; iReset() ; - RooRealVar* var ; - pdf = (RooAbsPdf*)_pdfItr->Next(); + RooAbsPdf* pdf = &(RooAbsPdf&)_pdfList[i]; std::string pdfName = Form("pdf_%d",i); RooCustomizer cust(*pdf,pdfName.c_str()); @@ -1545,7 +1500,7 @@ RooStarMomentMorph::CacheElem* RooStarMomentMorph::getCache(const RooArgSet* /*n ownedComps.add(RooArgSet(*slope[sij(i,j)],*offsetVar[sij(i,j)])) ; // linear transformations, so pdf can be renormalized easily - var = (RooRealVar*)(_obsItr->Next()); + RooRealVar *var = (RooRealVar*)(_obsList[j]); std::string transVarName = Form("%s_transVar_%d_%d",GetName(),i,j); transVar[sij(i,j)] = new RooLinearVar(transVarName.c_str(),transVarName.c_str(),*var,*slope[sij(i,j)],*offsetVar[sij(i,j)]); @@ -1680,7 +1635,6 @@ void RooStarMomentMorph::CacheElem::calculateFractions(const RooStarMomentMorph& //int nObs=self._obsList.getSize(); // loop over parList - self._parItr->Reset(); int nnuis=0; // zero all fractions @@ -1691,7 +1645,7 @@ void RooStarMomentMorph::CacheElem::calculateFractions(const RooStarMomentMorph& } for (Int_t j=0; jNext()); + RooRealVar* m = &(RooRealVar&)self._parList[j]; double m0=m->getVal(); if (m0==0.) continue; diff --git a/src/CMSHggFormula.cc b/src/CMSHggFormula.cc index 34aa8abe6b6..54e10224ec6 100644 --- a/src/CMSHggFormula.cc +++ b/src/CMSHggFormula.cc @@ -11,8 +11,7 @@ CMSHggFormulaA1::CMSHggFormulaA1(const char* name, const char* title, RooAbsReal p3_("p3", "p3", this, p3), terms_("terms", "terms", this), coeffs_(coeffs) { - RooFIter iter = terms.fwdIterator(); - for (RooAbsArg* a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg* a : terms) { RooAbsReal* rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Component ") + a->GetName() + @@ -61,8 +60,7 @@ CMSHggFormulaA2::CMSHggFormulaA2(const char* name, const char* title, RooAbsReal p3_("p3", "p3", this, p3), terms_("terms", "terms", this), coeffs_(coeffs) { - RooFIter iter = terms.fwdIterator(); - for (RooAbsArg* a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg *a : terms) { RooAbsReal* rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Component ") + a->GetName() + @@ -107,8 +105,7 @@ CMSHggFormulaB1::CMSHggFormulaB1(const char* name, const char* title, RooAbsReal p0_("p0", "p0", this, p0), terms_("terms", "terms", this), coeffs_(coeffs) { - RooFIter iter = terms.fwdIterator(); - for (RooAbsArg* a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg *a : terms) { RooAbsReal* rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Component ") + a->GetName() + @@ -150,8 +147,7 @@ CMSHggFormulaB2::CMSHggFormulaB2(const char* name, const char* title, double con p0_(p0), terms_("terms", "terms", this), coeffs_(coeffs) { - RooFIter iter = terms.fwdIterator(); - for (RooAbsArg* a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg* a : terms) { RooAbsReal* rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Component ") + a->GetName() + @@ -192,8 +188,7 @@ CMSHggFormulaC1::CMSHggFormulaC1(const char* name, const char* title, RooArgList : RooAbsReal(name, title), terms_("terms", "terms", this), coeffs_(coeffs) { - RooFIter iter = terms.fwdIterator(); - for (RooAbsArg* a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg* a : terms) { RooAbsReal* rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Component ") + a->GetName() + diff --git a/src/CMSHistErrorPropagator.cc b/src/CMSHistErrorPropagator.cc index 07b3de411bc..c84761082c9 100644 --- a/src/CMSHistErrorPropagator.cc +++ b/src/CMSHistErrorPropagator.cc @@ -249,9 +249,7 @@ void CMSHistErrorPropagator::setAnalyticBarlowBeeston(bool flag) const { if (bintypes_[j][0] == 1 && !vbinpars_[j][0]->isConstant()) { bb_.use.push_back(j); double gobs_val = 0.; - RooFIter iter = vbinpars_[j][0]->valueClientMIterator(); - RooAbsArg *arg = nullptr; - while((arg = iter.next())) { + for (RooAbsArg * arg : vbinpars_[j][0]->valueClients()) { if (arg == this || arg == &binsentry_) { // std::cout << "Skipping " << this << " " << this->GetName() << "\n"; } else { diff --git a/src/CMSHistFunc.cc b/src/CMSHistFunc.cc index 045f802e278..6beb68168f2 100644 --- a/src/CMSHistFunc.cc +++ b/src/CMSHistFunc.cc @@ -1202,9 +1202,7 @@ Double_t CMSHistFunc::analyticalIntegral(Int_t code, } CMSHistFuncWrapper const* CMSHistFunc::wrapper() const { - RooFIter iter = this->valueClientMIterator(); - RooAbsArg *arg = nullptr; - while((arg = iter.next())) { + for (RooAbsArg *arg : valueClients()) { CMSHistFuncWrapper const* wrapper = dynamic_cast(arg); if (wrapper) return wrapper; } diff --git a/src/CMSHistFuncWrapper.cc b/src/CMSHistFuncWrapper.cc index d7710021ae0..d8b18448f44 100644 --- a/src/CMSHistFuncWrapper.cc +++ b/src/CMSHistFuncWrapper.cc @@ -47,9 +47,7 @@ void CMSHistFuncWrapper::initialize() const { pfunc_ = dynamic_cast(&(func_.arg())); perr_ = dynamic_cast(err_.absArg()); auto sentry_args = perr_->getSentryArgs(); - RooFIter iter = sentry_args->fwdIterator() ; - RooAbsArg* arg; - while((arg = iter.next())) { + for (RooAbsArg *arg : *sentry_args) { sentry_.addArg(*arg); } sentry_.setValueDirty(); diff --git a/src/CMSHistSum.cc b/src/CMSHistSum.cc index a3aad9866e5..ad30f61ad03 100644 --- a/src/CMSHistSum.cc +++ b/src/CMSHistSum.cc @@ -474,9 +474,7 @@ void CMSHistSum::setAnalyticBarlowBeeston(bool flag) const { if (bintypes_[j][0] == 1 && !vbinpars_[j][0]->isConstant()) { bb_.use.push_back(j); double gobs_val = 0.; - RooFIter iter = vbinpars_[j][0]->valueClientMIterator(); - RooAbsArg *arg = nullptr; - while((arg = iter.next())) { + for (RooAbsArg *arg : vbinpars_[j][0]->valueClients()) { if (arg == this || arg == &binsentry_) { // std::cout << "Skipping " << this << " " << this->GetName() << "\n"; } else { diff --git a/src/CachingNLL.cc b/src/CachingNLL.cc index f50443deece..ed7c802f1cd 100644 --- a/src/CachingNLL.cc +++ b/src/CachingNLL.cc @@ -117,10 +117,7 @@ namespace { unsigned long CachingSimNLLEvalCount = 0; } cacheutils::ArgSetChecker::ArgSetChecker(const RooAbsCollection &set) { - std::unique_ptr iter(set.createIterator()); - for (RooAbsArg *a = dynamic_cast(iter->Next()); - a != 0; - a = dynamic_cast(iter->Next())) { + for (RooAbsArg *a : set) { RooRealVar *rrv = dynamic_cast(a); if (rrv) { // && !rrv->isConstant()) { vars_.push_back(rrv); @@ -375,10 +372,9 @@ cacheutils::ReminderSum::ReminderSum(const char *name, const char *title, const RooAbsReal(name,title), list_("deps","",this) { - RooLinkedListIter iter(sumSet.iterator()); - for (RooAbsReal *rar = (RooAbsReal *) iter.Next(); rar != 0; rar = (RooAbsReal *) iter.Next()) { + for (RooAbsArg * rar : sumSet) { list_.add(*rar); - terms_.push_back(rar); + terms_.push_back(static_cast(rar)); } } Double_t cacheutils::ReminderSum::evaluate() const { @@ -585,8 +581,7 @@ cacheutils::CachingAddNLL::setup_() } std::unique_ptr params(pdf_->getParameters(*data_)); - std::unique_ptr iter(params->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *params) { if (dynamic_cast(a)) params_.add(*a); else if (dynamic_cast(a)) catParams_.add(*a); } @@ -1309,8 +1304,7 @@ void cacheutils::CachingSimNLL::setMaskNonDiscreteChannels(bool mask) { unsigned int idx = 0; for (std::vector::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it, ++idx) { if ((*it) == 0) continue; - RooLinkedListIter iter = (*it)->catParams().iterator(); - for (RooAbsArg *P = (RooAbsArg *) iter.Next(); P != 0; P = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *P : (*it)->catParams()) { RooCategory *cat = dynamic_cast(P); if (!cat) continue; if (cat && !cat->isConstant()) { diff --git a/src/CascadeMinimizer.cc b/src/CascadeMinimizer.cc index 1c5be035728..2e07374d3c4 100644 --- a/src/CascadeMinimizer.cc +++ b/src/CascadeMinimizer.cc @@ -911,8 +911,7 @@ bool CascadeMinimizer::autoBoundsOk(int verbose) { for (int bothBounds = 0; bothBounds <= 1; ++bothBounds) { const RooArgSet * pois = (bothBounds ? poisForAutoBounds_ : poisForAutoMax_); if (!pois) continue; - RooFIter f = pois->fwdIterator(); - for (RooAbsArg *a = f.next(); a != 0; a = f.next()) { + for (RooAbsArg *a : *pois) { RooRealVar *rrv = dynamic_cast(a); if (rrv && !rrv->isConstant() && rrv->hasMax() && rrv->hasMin()) { double val = rrv->getVal(), lo = rrv->getMin(), hi = rrv->getMax(); diff --git a/src/Combine.cc b/src/Combine.cc index 38cef32c95c..bcbcd2ab3c3 100644 --- a/src/Combine.cc +++ b/src/Combine.cc @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -227,8 +226,7 @@ std::string Combine::parseRegex(std::string instr, const RooArgSet *nuisances, R std::regex rgx( reg_esp, std::regex::ECMAScript); std::string matchingParams=""; - std::unique_ptr iter(nuisances->createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : *nuisances) { const std::string &target = a->GetName(); std::smatch match; if (std::regex_match(target, match, rgx)) { @@ -251,8 +249,7 @@ std::string Combine::parseRegex(std::string instr, const RooArgSet *nuisances, R std::regex rgx( reg_esp, std::regex::ECMAScript); std::string matchingParams=""; - std::unique_ptr iter(w->componentIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : w->components()) { if ( ! (a->IsA()->InheritsFrom(RooRealVar::Class()) || a->IsA()->InheritsFrom(RooCategory::Class()))) continue; @@ -540,8 +537,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do if (nuisances && runtimedef::get("ADD_DISCRETE_FALLBACK")) { RooArgSet newNuis; std::string startswith = "u_CMS_Hgg_env_pdf_"; - TIterator *np = nuisances->createIterator(); - while (RooRealVar *arg = (RooRealVar*)np->Next()) { + for (RooAbsArg *arg : *nuisances) { if (std::string(arg->GetName()).compare(0, startswith.size(), startswith)) { newNuis.add(*arg); } else { @@ -616,11 +612,10 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do if (redefineSignalPOIs_ != "") { RooArgSet newPOIs(w->argSet(redefineSignalPOIs_.c_str())); - TIterator *np = newPOIs.createIterator(); - while (RooRealVar *arg = (RooRealVar*)np->Next()) { + for (RooAbsArg *arg : newPOIs) { RooRealVar *rrv = dynamic_cast(arg); if (rrv == 0) { std::cerr << "MultiDimFit: Parameter of interest " << arg->GetName() << " which is not a RooRealVar will be ignored" << std::endl; continue; } - arg->setConstant(0); + rrv->setConstant(0); // also set ignoreConstraint flag for constraint PDF if ( w->pdf(Form("%s_Pdf",arg->GetName())) ) w->pdf(Form("%s_Pdf",arg->GetName()))->setAttribute("ignoreConstraint"); } @@ -639,9 +634,8 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do } // Always reset the POIs to floating (post-fit workspaces can actually have them frozen in some cases, in any case they can be re-frozen in the next step - TIterator *pois = POI->createIterator(); - while (RooRealVar *arg = (RooRealVar*)pois->Next()) { - arg->setConstant(0); + for (RooAbsArg *arg : *POI) { + static_cast(arg)->setConstant(0); } if (floatNuisances_ != "") { @@ -671,8 +665,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do if (verbose > 0) { //std::cout << "Floating the following parameters: "; toFloat.Print(""); CombineLogger::instance().log("Combine.cc",__LINE__,"Floating the following parameters:",__func__); - std::unique_ptr iter(toFloat.createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : toFloat) { CombineLogger::instance().log("Combine.cc",__LINE__,a->GetName(),__func__); } } @@ -706,8 +699,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do if (verbose > 0) { //std::cout << "Freezing the following parameters: "; toFreeze.Print(""); CombineLogger::instance().log("Combine.cc",__LINE__,"Freezing the following parameters: ",__func__); - std::unique_ptr iter(toFreeze.createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : toFreeze) { CombineLogger::instance().log("Combine.cc",__LINE__,a->GetName(),__func__); } } @@ -764,9 +756,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do for (auto const& attr : nuisanceAttrs) { RooArgSet toFreeze; if (nuisances) { - RooAbsArg *arg = nullptr; - auto iter = nuisances->createIterator(); - while ((arg = (RooAbsArg*)iter->Next())) { + for (RooAbsArg *arg : *nuisances) { if (arg->attributes().count(attr)) toFreeze.add(*arg); } if (verbose > 0) { std::cout << "Freezing the following nuisance parameters: "; toFreeze.Print(""); } @@ -983,8 +973,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do // print the values of the parameters used to generate the toy if (verbose > 2) { CombineLogger::instance().log("Combine.cc",__LINE__, "Generate Asimov toy from parameter values ... ",__func__); - std::unique_ptr iter(genPdf->getParameters((const RooArgSet*)0)->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *std::unique_ptr{genPdf->getParameters((const RooArgSet*)0)}) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("Combine.cc",__LINE__,varstring.Data(),__func__); } @@ -1080,8 +1069,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do std::cout << "Generate toy " << iToy << "/" << nToys << std::endl; if (verbose > 2) { CombineLogger::instance().log("Combine.cc",__LINE__, std::string(Form("Generating toy %d/%d, from parameter values ... ",iToy,nToys)),__func__); - std::unique_ptr iter(genPdf->getParameters((const RooArgSet*)0)->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *std::unique_ptr{genPdf->getParameters((const RooArgSet*)0)}) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("Combine.cc" ,__LINE__,varstring.Data(),__func__); } @@ -1198,8 +1186,7 @@ void Combine::addPOI(const RooArgSet *poi){ // RooArgSet *nuisances = (RooArgSet*) w->set("nuisances"); CascadeMinimizerGlobalConfigs::O().parametersOfInterest = RooArgList(); if (poi != 0) { - TIterator *pp = poi->createIterator(); - while (RooAbsArg *arg = (RooAbsArg*)pp->Next()) (CascadeMinimizerGlobalConfigs::O().parametersOfInterest).add(*arg); + for (RooAbsArg *arg : *poi) (CascadeMinimizerGlobalConfigs::O().parametersOfInterest).add(*arg); } } @@ -1208,20 +1195,15 @@ void Combine::addNuisances(const RooArgSet *nuisances){ // RooArgSet *nuisances = (RooArgSet*) w->set("nuisances"); CascadeMinimizerGlobalConfigs::O().nuisanceParameters = RooArgList(); if (nuisances != 0) { - TIterator *np = nuisances->createIterator(); - while (RooAbsArg *arg = (RooAbsArg*)np->Next()) (CascadeMinimizerGlobalConfigs::O().nuisanceParameters).add(*arg); + for (RooAbsArg *arg : *nuisances) (CascadeMinimizerGlobalConfigs::O().nuisanceParameters).add(*arg); } } void Combine::addFloatingParameters(const RooArgSet ¶meters){ CascadeMinimizerGlobalConfigs::O().allFloatingParameters = RooArgList(); - //if (parameters != 0) { - TIterator *np = parameters.createIterator(); - while (RooAbsArg *arg = (RooAbsArg*)np->Next()) { + for (RooAbsArg *arg : parameters) { if (! arg->isConstant()) (CascadeMinimizerGlobalConfigs::O().allFloatingParameters).add(*arg); } - //} - } void Combine::addDiscreteNuisances(RooWorkspace *w){ @@ -1231,8 +1213,7 @@ void Combine::addDiscreteNuisances(RooWorkspace *w){ CascadeMinimizerGlobalConfigs::O().allRooMultiPdfParams = RooArgList(); if (discreteParameters != 0) { - TIterator *dp = discreteParameters->createIterator(); - while (RooAbsArg *arg = (RooAbsArg*)dp->Next()) { + for (RooAbsArg *arg : *discreteParameters) { RooCategory *cat = dynamic_cast(arg); if (cat && (!cat->isConstant() || runtimedef::get("ADD_DISCRETE_FALLBACK"))) { if (verbose){ @@ -1246,8 +1227,7 @@ void Combine::addDiscreteNuisances(RooWorkspace *w){ // Run through all of the categories in the workspace and look for "pdfindex" -> fall back option else if (runtimedef::get("ADD_DISCRETE_FALLBACK")) { RooArgSet discreteParameters_C = w->allCats(); - TIterator *dp = discreteParameters_C.createIterator(); - while (RooAbsArg *arg = (RooAbsArg*)dp->Next()) { + for (RooAbsArg *arg : discreteParameters_C) { RooCategory *cat = dynamic_cast(arg); if (! (std::string(cat->GetName()).find("pdfindex") != std::string::npos )) continue; if (cat/* && !cat->isConstant()*/) { @@ -1262,14 +1242,11 @@ void Combine::addDiscreteNuisances(RooWorkspace *w){ // Now lets go through the list of parameters which are associated to this discrete nuisance RooArgSet clients; utils::getClients(CascadeMinimizerGlobalConfigs::O().pdfCategories,(w->allPdfs()),clients); - TIterator *it = clients.createIterator(); - // clients.Print(); - while (RooAbsArg *arg = (RooAbsArg*)it->Next()) { + for (RooAbsArg *arg : clients) { (CascadeMinimizerGlobalConfigs::O().allRooMultiPdfs).add(*(dynamic_cast(arg))); RooAbsPdf *pdf = dynamic_cast(arg); - RooArgSet *pdfPars = pdf->getParameters((const RooArgSet*)0); - std::unique_ptr iter_v(pdfPars->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter_v->Next(); a != 0; a = (RooAbsArg *) iter_v->Next()) { + std::unique_ptr pdfPars{pdf->getParameters((const RooArgSet*)0)}; + for (RooAbsArg *a : *pdfPars) { RooRealVar *v = dynamic_cast(a); if (!v) continue; if (! (v->isConstant())) (CascadeMinimizerGlobalConfigs::O().allRooMultiPdfParams).add(*v) ; @@ -1289,8 +1266,7 @@ void Combine::addBranches(const std::string& trackString, RooWorkspace* w, std:: std::regex rgx( reg_esp, std::regex::ECMAScript); RooArgSet allParams(w->allVars()); - std::unique_ptr iter(allParams.createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : allParams) { Var *tmp = dynamic_cast(a); if(tmp==nullptr) continue; const std::string &target = tmp->GetName(); diff --git a/src/FitDiagnostics.cc b/src/FitDiagnostics.cc index acd7caebca2..c0a29ef2b57 100644 --- a/src/FitDiagnostics.cc +++ b/src/FitDiagnostics.cc @@ -1211,16 +1211,14 @@ void FitDiagnostics::getNormalizations(RooAbsPdf *pdf, const RooArgSet &obs, Roo //void FitDiagnostics::setFitResultTrees(const RooArgSet *args, std::vector *vals){ void FitDiagnostics::setFitResultTrees(const RooArgSet *args, double * vals){ - TIterator* iter(args->createIterator()); int count=0; - for (TObject *a = iter->Next(); a != 0; a = iter->Next()) { + for (RooAbsArg *a : *args) { RooRealVar *rrv = dynamic_cast(a); //std::string name = rrv->GetName(); vals[count]=rrv->getVal(); count++; } - delete iter; return; } @@ -1259,17 +1257,15 @@ void FitDiagnostics::resetFitResultTrees(bool withSys){ } void FitDiagnostics::setNormsFitResultTrees(const RooArgSet *args, double * vals){ - TIterator* iter(args->createIterator()); int count=0; - for (TObject *a = iter->Next(); a != 0; a = iter->Next()) { + for (RooAbsArg *a : *args) { RooRealVar *rcv = dynamic_cast(a); // std::cout << "index " << count << ", Name " << rcv->GetName() << ", val " << rcv->getVal() << std::endl; //std::string name = rcv->GetName(); vals[count]=rcv->getVal(); count++; } - delete iter; return; } @@ -1346,8 +1342,7 @@ void FitDiagnostics::createFitResultTrees(const RooStats::ModelConfig &mc, bool nuisanceParameters_= new double[nuis->getSize()]; overallNuis_ = nuis->getSize(); - TIterator* iter_c(cons->createIterator()); - for (TObject *a = iter_c->Next(); a != 0; a = iter_c->Next()) { + for (RooAbsArg * a : *cons) { RooRealVar *rrv = dynamic_cast(a); std::string name = rrv->GetName(); globalObservables_[count]=0; @@ -1357,8 +1352,7 @@ void FitDiagnostics::createFitResultTrees(const RooStats::ModelConfig &mc, bool count++; } count = 0; - TIterator* iter_n(nuis->createIterator()); - for (TObject *a = iter_n->Next(); a != 0; a = iter_n->Next()) { + for (RooAbsArg * a : *nuis) { RooRealVar *rrv = dynamic_cast(a); std::string name = rrv->GetName(); nuisanceParameters_[count] = 0; @@ -1371,8 +1365,7 @@ void FitDiagnostics::createFitResultTrees(const RooStats::ModelConfig &mc, bool } count = 0; - TIterator* iter_no(norms->createIterator()); - for (TObject *a = iter_no->Next(); a != 0; a = iter_no->Next()) { + for (RooAbsArg * a : *norms) { RooRealVar *rcv = dynamic_cast(a); std::string name = rcv->GetName(); processNormalizations_[count] = -999; diff --git a/src/FitterAlgoBase.cc b/src/FitterAlgoBase.cc index a11fcd80ecd..7455028977b 100644 --- a/src/FitterAlgoBase.cc +++ b/src/FitterAlgoBase.cc @@ -151,9 +151,8 @@ bool FitterAlgoBase::run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats: break; } - std::unique_ptr params(mc_s->GetPdf()->getParameters(data)); - RooLinkedListIter iter = params->iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + ; + for (RooAbsArg *a : *std::unique_ptr{mc_s->GetPdf()->getParameters(data)}) { RooRealVar *rrv = dynamic_cast(a); if (rrv == 0 || rrv->isConstant()) continue; if (profileMode_ == ProfileUnconstrained && mc_s->GetNuisanceParameters()->find(*rrv) != 0) { @@ -679,8 +678,7 @@ double FitterAlgoBase::findCrossingNew(CascadeMinimizer &minim, RooAbsReal &nll, void FitterAlgoBase::optimizeBounds(const RooWorkspace *w, const RooStats::ModelConfig *mc) { if (runtimedef::get("UNBOUND_GAUSSIANS") && mc->GetNuisanceParameters() != 0) { - RooLinkedListIter iter = mc->GetNuisanceParameters()->iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : *mc->GetNuisanceParameters()) { RooRealVar *rrv = dynamic_cast(a); if (rrv != 0) { RooAbsPdf *pdf = w->pdf((std::string(a->GetName())+"_Pdf").c_str()); @@ -692,8 +690,7 @@ void FitterAlgoBase::optimizeBounds(const RooWorkspace *w, const RooStats::Model } } if (runtimedef::get("OPTIMIZE_BOUNDS") && mc->GetNuisanceParameters() != 0) { - RooLinkedListIter iter = mc->GetNuisanceParameters()->iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : *mc->GetNuisanceParameters()) { RooRealVar *rrv = dynamic_cast(a); //std::cout << (rrv ? "Var" : "Arg") << ": " << a->GetName() << ": " << a->getAttribute("optimizeBounds") << std::endl; if (rrv != 0 && rrv->getAttribute("optimizeBounds")) { @@ -707,8 +704,7 @@ void FitterAlgoBase::optimizeBounds(const RooWorkspace *w, const RooStats::Model } void FitterAlgoBase::restoreBounds(const RooWorkspace *w, const RooStats::ModelConfig *mc) { if (runtimedef::get("OPTIMIZE_BOUNDS") && mc->GetNuisanceParameters() != 0) { - RooLinkedListIter iter = mc->GetNuisanceParameters()->iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : *mc->GetNuisanceParameters()) { RooRealVar *rrv = dynamic_cast(a); if (rrv != 0 && rrv->getAttribute("optimizeBounds")) { rrv->setRange(rrv->getMin("optimizeBoundRange"), rrv->getMax("optimizeBoundRange")); diff --git a/src/HWWLVJJRooPdfs.cc b/src/HWWLVJJRooPdfs.cc index ff687552428..a0d35ed6e03 100644 --- a/src/HWWLVJJRooPdfs.cc +++ b/src/HWWLVJJRooPdfs.cc @@ -16,16 +16,13 @@ RooChebyshevPDF::RooChebyshevPDF(const char *name, const char *title, x("x", "x", this, var), coefs("coefs", "coefs", this) { - TIterator *cx = coefList.createIterator(); - RooAbsReal *coef; - while ((coef = (RooAbsReal*)cx->Next())) { + for (RooAbsArg * coef : coefList) { if (!dynamic_cast(coef)) { std::cerr << "Coefficient " << coef->GetName() << " is not good." << std::endl; assert(0); } coefs.add(*coef); } - delete cx; } RooChebyshevPDF::RooChebyshevPDF(const RooChebyshevPDF& other, @@ -444,16 +441,13 @@ RooExpPoly::RooExpPoly(const char *name, const char *title, x("x","x",this,_x), coefs("coefs","coefs",this) { - TIterator *cx = _coefs.createIterator(); - RooAbsReal *coef; - while ((coef = (RooAbsReal*)cx->Next())) { + for (RooAbsArg * coef : _coefs) { if (!dynamic_cast(coef)) { std::cerr << "Coefficient " << coef->GetName() << " is not good." << std::endl; assert(0); } coefs.add(*coef); } - delete cx; } diff --git a/src/HWWLVJRooPdfs.cxx b/src/HWWLVJRooPdfs.cxx index 80bbab4b86d..dc45009be41 100755 --- a/src/HWWLVJRooPdfs.cxx +++ b/src/HWWLVJRooPdfs.cxx @@ -25,7 +25,6 @@ #include "TString.h" #include "TRandom3.h" #include "TCanvas.h" -#include "TIterator.h" #include "RooHist.h" #include "RooRealVar.h" #include "RooFitResult.h" diff --git a/src/HZGRooPdfs.cxx b/src/HZGRooPdfs.cxx index df8dede31a7..d6a24dafcd3 100644 --- a/src/HZGRooPdfs.cxx +++ b/src/HZGRooPdfs.cxx @@ -55,9 +55,7 @@ RooStepBernstein::RooStepBernstein(const char* name, const char* title, _coefList("coefficients","List of coefficients",this) { // Constructor - TIterator* coefIter = coefList.createIterator() ; - RooAbsArg* coef ; - while((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg* coef : coefList) { if (!dynamic_cast(coef)) { cout << "RooStepBernstein::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName() << " is not of type RooAbsReal" << endl ; @@ -65,7 +63,6 @@ RooStepBernstein::RooStepBernstein(const char* name, const char* title, } _coefList.add(*coef) ; } - delete coefIter ; } @@ -95,23 +92,22 @@ Double_t RooStepBernstein::evaluate() const x = (x - _stepThresh)/(1.0-_stepThresh); // now we get the full polynomial Int_t degree = _coefList.getSize() - 1; // n+1 polys of degree n - RooFIter iter = _coefList.fwdIterator(); if(degree == 0) { - return ((RooAbsReal *)iter.next())->getVal(); + return ((RooAbsReal &)_coefList[0]).getVal(); } else if(degree == 1) { - Double_t a0 = ((RooAbsReal *)iter.next())->getVal(); // c0 - Double_t a1 = ((RooAbsReal *)iter.next())->getVal() - a0; // c1 - c0 + Double_t a0 = ((RooAbsReal &)_coefList[0]).getVal(); // c0 + Double_t a1 = ((RooAbsReal &)_coefList[1]).getVal() - a0; // c1 - c0 return a1 * x + a0; } else if(degree == 2) { - Double_t a0 = ((RooAbsReal *)iter.next())->getVal(); // c0 - Double_t a1 = 2 * (((RooAbsReal *)iter.next())->getVal() - a0); // 2 * (c1 - c0) - Double_t a2 = ((RooAbsReal *)iter.next())->getVal() - a1 - a0; // c0 - 2 * c1 + c2 + Double_t a0 = ((RooAbsReal &)_coefList[0]).getVal(); // c0 + Double_t a1 = 2 * (((RooAbsReal &)_coefList[1]).getVal() - a0); // 2 * (c1 - c0) + Double_t a2 = ((RooAbsReal &)_coefList[2]).getVal() - a1 - a0; // c0 - 2 * c1 + c2 return (a2 * x + a1) * x + a0; } else if(degree > 2) { @@ -119,12 +115,12 @@ Double_t RooStepBernstein::evaluate() const Double_t t = x; Double_t s = 1 - x; - Double_t result = ((RooAbsReal *)iter.next())->getVal() * s; + Double_t result = ((RooAbsReal &)_coefList[0]).getVal() * s; for(Int_t i = 1; i < degree; i++) { - result = (result + t * TMath::Binomial(degree, i) * ((RooAbsReal *)iter.next())->getVal()) * s; + result = (result + t * TMath::Binomial(degree, i) * ((RooAbsReal &)_coefList[i]).getVal()) * s; t *= x; } - result += t * ((RooAbsReal *)iter.next())->getVal(); + result += t * ((RooAbsReal &)_coefList[degree]).getVal(); return result; } @@ -160,17 +156,15 @@ Double_t RooStepBernstein::analyticalIntegral(Int_t code, const char* rangeName) Int_t degree= _coefList.getSize()-1; // n+1 polys of degree n Double_t norm(0) ; - RooFIter iter = _coefList.fwdIterator() ; - Double_t temp=0; for (int i=0; i<=degree; ++i){ // for each of the i Bernstein basis polynomials // represent it in the 'power basis' (the naive polynomial basis) // where the integral is straight forward. - temp = 0; + Double_t temp = 0; for (int j=i; j<=degree; ++j){ // power basis≈ß temp += pow(-1.,j-i) * TMath::Binomial(degree, j) * TMath::Binomial(j,i) / (j+1); } - temp *= ((RooAbsReal*)iter.next())->getVal(); // include coeff + temp *= ((RooAbsReal&)_coefList[i]).getVal(); // include coeff norm += temp; // add this basis's contribution to total } @@ -725,9 +719,7 @@ RooGaussStepBernstein::RooGaussStepBernstein(const char* name, _coefList("coefficients","List of coefficients",this) { // Constructor - TIterator* coefIter = coefList.createIterator() ; - RooAbsArg* coef ; - while((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *coef : coefList) { if (!dynamic_cast(coef)) { cout << "RooGaussStepBernstein::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName() @@ -736,7 +728,6 @@ RooGaussStepBernstein::RooGaussStepBernstein(const char* name, } _coefList.add(*coef) ; } - delete coefIter ; } @@ -758,7 +749,6 @@ RooGaussStepBernstein::RooGaussStepBernstein(const RooGaussStepBernstein& other, Double_t RooGaussStepBernstein::evaluate() const { const Int_t degree = _coefList.getSize() - 1; // n+1 polys of degree n - RooFIter iter = _coefList.fwdIterator() ; double poly_vals[degree+1]; for( int i = 0; i <= degree; ++i ) { @@ -773,7 +763,7 @@ Double_t RooGaussStepBernstein::evaluate() const RooAbsReal* coef = NULL; for(Int_t i = 0; i <= degree; ++i) { // coef is the bernstein polynomial coefficient - coef = (RooAbsReal *)iter.next(); + coef = &(RooAbsReal &)_coefList[i]; // calculate the coefficient in the 'power basis' // i.e. the naive polynomial basis beta = 0.0; @@ -787,8 +777,6 @@ Double_t RooGaussStepBernstein::evaluate() const result += beta; } - //cout << result << endl; - return result; } @@ -811,7 +799,6 @@ Double_t RooGaussStepBernstein::analyticalIntegral(Int_t code, assert(code==1) ; const Int_t degree = _coefList.getSize() - 1; // n+1 polys of degree n - RooFIter iter = _coefList.fwdIterator() ; double integral_vals_hi[degree+1],integral_vals_lo[degree+1]; for( int i = 0; i <= degree; ++i ) { @@ -826,10 +813,9 @@ Double_t RooGaussStepBernstein::analyticalIntegral(Int_t code, double beta = 0.0; // iterate through each Double_t result = 0.0; - RooAbsReal* coef = NULL; for(Int_t i = 0; i <= degree; ++i) { // coef is the bernstein polynomial coefficient - coef = (RooAbsReal *)iter.next(); + RooAbsReal *coef = &(RooAbsReal &)_coefList[i]; // calculate the coefficient in the 'power basis' // i.e. the naive polynomial basis beta = 0.0; diff --git a/src/HZZ4L_RooCTauPdf_1D.cc b/src/HZZ4L_RooCTauPdf_1D.cc index 9aa0c86ea3a..76034e7a72c 100755 --- a/src/HZZ4L_RooCTauPdf_1D.cc +++ b/src/HZZ4L_RooCTauPdf_1D.cc @@ -31,16 +31,13 @@ _coefList("coefList", "List of funcficients", this), ctau_min(_ctau_min), ctau_max(_ctau_max) { - TIterator* coefIter = inCoefList.createIterator(); - RooAbsArg* func; - while ((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg* func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :HZZ4L_RooCTauPdf_1D(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << endl; assert(0); } _coefList.add(*func); } - delete coefIter; nbins_ctau = _coefList.getSize(); for(int mp=0;mp<(nbins_ctau>101 ? 101 : nbins_ctau);mp++) Integral_T[mp] = dynamic_cast(_coefList.at(mp))->analyticalIntegral(1000); diff --git a/src/HZZ4L_RooCTauPdf_1D_Expanded.cc b/src/HZZ4L_RooCTauPdf_1D_Expanded.cc index abe7062d0e5..ae443264f9b 100755 --- a/src/HZZ4L_RooCTauPdf_1D_Expanded.cc +++ b/src/HZZ4L_RooCTauPdf_1D_Expanded.cc @@ -42,9 +42,7 @@ nLinearVariations(nLinearVariations_) nCoef=0; nFuncs=0; - TIterator* coefIter = inCoefList.createIterator(); - RooAbsArg* coef; - while ((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *coef : inCoefList) { if (!dynamic_cast(coef)) { coutE(InputArguments) << "ERROR::HZZ4L_RooCTauPdf_1D_Expanded(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << endl; assert(0); @@ -52,7 +50,6 @@ nLinearVariations(nLinearVariations_) _coefList.add(*coef); nCoef++; } - delete coefIter; if (nCoef>2){ coutE(InputArguments) << "ERROR::HZZ4L_RooCTauPdf_1D_Expanded(" << GetName() << ") number coefficients " << nCoef << " is not supported." << endl; @@ -60,9 +57,7 @@ nLinearVariations(nLinearVariations_) } // else cout << "Number of coefficients: " << nCoef << endl; - TIterator* funcIter = inFuncList.createIterator(); - RooAbsArg* func; - while ((func = (RooAbsArg*)funcIter->Next())) { + for (RooAbsArg *func : inFuncList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR::HZZ4L_RooCTauPdf_1D_Expanded(" << GetName() << ") function " << func->GetName() << " is not of type RooAbsReal" << endl; assert(0); @@ -70,7 +65,6 @@ nLinearVariations(nLinearVariations_) _funcList.add(*func); nFuncs++; } - delete funcIter; if (nLinearVariations>nCoef){ coutE(InputArguments) << "ERROR::HZZ4L_RooCTauPdf_1D_Expanded(" << GetName() << ") number of linear variations (" << nLinearVariations << ") is more than the number of coefficients (" << nCoef << ")!!!" << endl; diff --git a/src/HZZ4L_RooCTauPdf_2D.cc b/src/HZZ4L_RooCTauPdf_2D.cc index 6c3a90a4717..2981755b410 100755 --- a/src/HZZ4L_RooCTauPdf_2D.cc +++ b/src/HZZ4L_RooCTauPdf_2D.cc @@ -33,16 +33,13 @@ _coefList("coefList", "List of funcficients", this), ctau_min(_ctau_min), ctau_max(_ctau_max) { - TIterator* coefIter = inCoefList.createIterator(); - RooAbsArg* func; - while ((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :HZZ4L_RooCTauPdf_2D(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << endl; assert(0); } _coefList.add(*func); } - delete coefIter; nbins_ctau = _coefList.getSize(); Integral_T = new double[nbins_ctau]; diff --git a/src/HZZ4L_RooSpinZeroPdf.cc b/src/HZZ4L_RooSpinZeroPdf.cc index 16736ed45ac..2e2231256e2 100755 --- a/src/HZZ4L_RooSpinZeroPdf.cc +++ b/src/HZZ4L_RooSpinZeroPdf.cc @@ -26,21 +26,17 @@ ClassImp(HZZ4L_RooSpinZeroPdf) _coefList("coefList","List of funcficients",this) { - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg* func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :HZZ4L_RooSpinZeroPdf(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*func) ; } - delete coefIter; Integral_T1 = dynamic_cast(_coefList.at(0))-> analyticalIntegral(1000); Integral_T2 = dynamic_cast(_coefList.at(1))-> analyticalIntegral(1000); Integral_T4 = dynamic_cast(_coefList.at(2))-> analyticalIntegral(1000); -// _coefIter = _coefList.createIterator() ; } @@ -55,7 +51,6 @@ ClassImp(HZZ4L_RooSpinZeroPdf) Integral_T1 = other.Integral_T1; Integral_T2 = other.Integral_T2; Integral_T4 = other.Integral_T4; - // _coefIter = _coefList.createIterator() ; } diff --git a/src/HZZ4L_RooSpinZeroPdf_1D.cc b/src/HZZ4L_RooSpinZeroPdf_1D.cc index 14f31e8ab8e..6b9e7d4c092 100644 --- a/src/HZZ4L_RooSpinZeroPdf_1D.cc +++ b/src/HZZ4L_RooSpinZeroPdf_1D.cc @@ -27,18 +27,13 @@ ClassImp(HZZ4L_RooSpinZeroPdf_1D) _coefList("coefList","List of funcficients",this) { - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :HZZ4L_RooSpinZeroPdf_1D(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*func) ; } - delete coefIter; - - _coefIter = _coefList.createIterator() ; } @@ -51,7 +46,6 @@ ClassImp(HZZ4L_RooSpinZeroPdf_1D) _coefList("coefList",this,other._coefList) { - _coefIter = _coefList.createIterator() ; } diff --git a/src/HZZ4L_RooSpinZeroPdf_1D_fast.cc b/src/HZZ4L_RooSpinZeroPdf_1D_fast.cc index 310704781ad..5d4cea09afc 100755 --- a/src/HZZ4L_RooSpinZeroPdf_1D_fast.cc +++ b/src/HZZ4L_RooSpinZeroPdf_1D_fast.cc @@ -28,27 +28,21 @@ HZZ4L_RooSpinZeroPdf_1D_fast::HZZ4L_RooSpinZeroPdf_1D_fast( obsList("obsList", "List of pdf observables", this), coefList("coefList", "List of pdf components", this) { - TIterator* coefIter = inObsList.createIterator(); - RooAbsArg* coef; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inObsList) { if (!dynamic_cast(coef)){ coutE(InputArguments) << "HZZ4L_RooSpinZeroPdf_1D_fast(" << GetName() << ") observable " << coef->GetName() << " is not of type RooAbsReal" << endl; assert(0); } obsList.add(*coef); } - delete coefIter; - coefIter = inCoefList.createIterator(); - coef=0; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inCoefList) { if (dynamic_cast(coef)==0 && dynamic_cast(coef)==0){ coutE(InputArguments) << "HZZ4L_RooSpinZeroPdf_1D_fast(" << GetName() << ") component " << coef->GetName() << " is not of type FastTemplateFunc_f" << endl; assert(0); } coefList.add(*coef); } - delete coefIter; } diff --git a/src/HZZ4L_RooSpinZeroPdf_2D.cc b/src/HZZ4L_RooSpinZeroPdf_2D.cc index d0dab44aa38..2cc39dffcad 100755 --- a/src/HZZ4L_RooSpinZeroPdf_2D.cc +++ b/src/HZZ4L_RooSpinZeroPdf_2D.cc @@ -32,16 +32,13 @@ ClassImp(HZZ4L_RooSpinZeroPdf_2D) _coefList("coefList","List of funcficients",this) { - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :HZZ4L_RooSpinZeroPdf_2D(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*func) ; } - delete coefIter; Integral_T1 = dynamic_cast(_coefList.at(0))-> analyticalIntegral(1000); Integral_T2 = dynamic_cast(_coefList.at(1))-> analyticalIntegral(1000); @@ -52,8 +49,6 @@ ClassImp(HZZ4L_RooSpinZeroPdf_2D) Integral_T7 = dynamic_cast(_coefList.at(6))-> analyticalIntegral(1000); Integral_T8 = dynamic_cast(_coefList.at(7))-> analyticalIntegral(1000); Integral_T9 = dynamic_cast(_coefList.at(8))-> analyticalIntegral(1000); - -// _coefIter = _coefList.createIterator() ; } @@ -78,8 +73,6 @@ ClassImp(HZZ4L_RooSpinZeroPdf_2D) Integral_T7 = other.Integral_T7; Integral_T8 = other.Integral_T8; Integral_T9 = other.Integral_T9; - - // _coefIter = _coefList.createIterator() ; } diff --git a/src/HZZ4L_RooSpinZeroPdf_2D_fast.cc b/src/HZZ4L_RooSpinZeroPdf_2D_fast.cc index 338c590d36e..3a2c933ab61 100755 --- a/src/HZZ4L_RooSpinZeroPdf_2D_fast.cc +++ b/src/HZZ4L_RooSpinZeroPdf_2D_fast.cc @@ -37,27 +37,21 @@ HZZ4L_RooSpinZeroPdf_2D_fast::HZZ4L_RooSpinZeroPdf_2D_fast( obsList("obsList", "List of pdf observables", this), coefList("coefList", "List of pdf components", this) { - TIterator* coefIter = inObsList.createIterator(); - RooAbsArg* coef; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inObsList) { if (!dynamic_cast(coef)){ coutE(InputArguments) << "HZZ4L_RooSpinZeroPdf_2D_fast(" << GetName() << ") observable " << coef->GetName() << " is not of type RooAbsReal" << endl; assert(0); } obsList.add(*coef); } - delete coefIter; - coefIter = inCoefList.createIterator(); - coef=0; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inCoefList) { if (dynamic_cast(coef)==0 && dynamic_cast(coef)==0){ coutE(InputArguments) << "HZZ4L_RooSpinZeroPdf_2D_fast(" << GetName() << ") component " << coef->GetName() << " is not of type FastTemplateFunc_f" << endl; assert(0); } coefList.add(*coef); } - delete coefIter; } diff --git a/src/HZZ4L_RooSpinZeroPdf_phase.cc b/src/HZZ4L_RooSpinZeroPdf_phase.cc index 8850b3f41ff..2853ed3f801 100755 --- a/src/HZZ4L_RooSpinZeroPdf_phase.cc +++ b/src/HZZ4L_RooSpinZeroPdf_phase.cc @@ -28,22 +28,18 @@ ClassImp(HZZ4L_RooSpinZeroPdf_phase) _coefList("coefList","List of funcficients",this) { - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :HZZ4L_RooSpinZeroPdf_phase(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*func) ; } - delete coefIter; Integral_T1 = dynamic_cast(_coefList.at(0))-> analyticalIntegral(1000); Integral_T2 = dynamic_cast(_coefList.at(1))-> analyticalIntegral(1000); Integral_T4 = dynamic_cast(_coefList.at(2))-> analyticalIntegral(1000); Integral_T5 = dynamic_cast(_coefList.at(3))-> analyticalIntegral(1000); -// _coefIter = _coefList.createIterator() ; } @@ -61,7 +57,6 @@ ClassImp(HZZ4L_RooSpinZeroPdf_phase) Integral_T2 = other.Integral_T2; Integral_T4 = other.Integral_T4; Integral_T5 = other.Integral_T5; - // _coefIter = _coefList.createIterator() ; } diff --git a/src/HZZ4L_RooSpinZeroPdf_phase_fast.cc b/src/HZZ4L_RooSpinZeroPdf_phase_fast.cc index 5ad8fe1cd99..0857cc5223d 100755 --- a/src/HZZ4L_RooSpinZeroPdf_phase_fast.cc +++ b/src/HZZ4L_RooSpinZeroPdf_phase_fast.cc @@ -31,27 +31,21 @@ HZZ4L_RooSpinZeroPdf_phase_fast::HZZ4L_RooSpinZeroPdf_phase_fast( obsList("obsList", "List of pdf observables", this), coefList("coefList", "List of pdf components", this) { - TIterator* coefIter = inObsList.createIterator(); - RooAbsArg* coef; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inObsList) { if (!dynamic_cast(coef)){ coutE(InputArguments) << "HZZ4L_RooSpinZeroPdf_phase_fast(" << GetName() << ") observable " << coef->GetName() << " is not of type RooAbsReal" << endl; assert(0); } obsList.add(*coef); } - delete coefIter; - coefIter = inCoefList.createIterator(); - coef=0; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inCoefList) { if (dynamic_cast(coef)==0 && dynamic_cast(coef)==0){ coutE(InputArguments) << "HZZ4L_RooSpinZeroPdf_phase_fast(" << GetName() << ") component " << coef->GetName() << " is not of type FastTemplateFunc_f" << endl; assert(0); } coefList.add(*coef); } - delete coefIter; } diff --git a/src/HybridNew.cc b/src/HybridNew.cc index 0c4688c094c..25b8a9dcd53 100644 --- a/src/HybridNew.cc +++ b/src/HybridNew.cc @@ -313,9 +313,8 @@ bool HybridNew::runSignificance(RooWorkspace *w, RooStats::ModelConfig *mc_s, Ro } if (saveHybridResult_) { TString name = TString::Format("HypoTestResult_mh%g",mass_); - RooLinkedListIter it = rValues_.iterator(); - for (RooRealVar *rIn = (RooRealVar*) it.Next(); rIn != 0; rIn = (RooRealVar*) it.Next()) { - name += Form("_%s%g", rIn->GetName(), rIn->getVal()); + for (RooAbsArg *rIn : rValues_) { + name += Form("_%s%g", rIn->GetName(), static_cast(rIn)->getVal()); } name += Form("_%u", RooRandom::integer(std::numeric_limits::max() - 1)); writeToysHere->WriteTObject(new HypoTestResult(*hcResult), name); @@ -693,8 +692,8 @@ std::pair HybridNew::eval(RooWorkspace *w, RooStats::ModelConfig } HybridNew::Setup setup; - RooLinkedListIter it = rVals.iterator(); - for (RooRealVar *rIn = (RooRealVar*) it.Next(); rIn != 0; rIn = (RooRealVar*) it.Next()) { + for (RooAbsArg *rInAbsArg : rVals) { + RooRealVar *rIn = static_cast(rInAbsArg); RooRealVar *r = dynamic_cast(mc_s->GetParametersOfInterest()->find(rIn->GetName())); r->setVal(rIn->getVal()); if (verbose) std::cout << " " << r->GetName() << " = " << rIn->getVal() << " +/- " << r->getError() << std::endl; @@ -811,8 +810,7 @@ std::unique_ptr HybridNew::create(RooWorkspace *w, R // print the values of the parameters used to generate the toy if (verbose > 2) { CombineLogger::instance().log("HybridNew.cc",__LINE__,"Using the following (post-fit) parameters for No signal hypothesis ",__func__); - std::unique_ptr iter(paramsToFit->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *paramsToFit) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("HybridNew.cc",__LINE__,std::string(Form(" %s",varstring.Data())),__func__); } @@ -839,8 +837,7 @@ std::unique_ptr HybridNew::create(RooWorkspace *w, R CombineLogger::instance().log("HybridNew.cc",__LINE__,"Using the following (post-fit) parameters for S+B hypothesis ",__func__); RooArgSet reportParams; reportParams.add(*paramsToFit); reportParams.add(poi); - std::unique_ptr iter(reportParams.createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : reportParams) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("HybridNew.cc",__LINE__,std::string(Form(" %s",varstring.Data())),__func__); } @@ -1148,9 +1145,8 @@ HybridNew::eval(RooStats::HybridCalculator &hc, const RooAbsCollection & rVals, } if (saveHybridResult_) { TString name = TString::Format("HypoTestResult_mh%g",mass_); - RooLinkedListIter it = rVals.iterator(); - for (RooRealVar *rIn = (RooRealVar*) it.Next(); rIn != 0; rIn = (RooRealVar*) it.Next()) { - name += Form("_%s%g", rIn->GetName(), rIn->getVal()); + for (RooAbsArg * rIn : rVals) { + name += Form("_%s%g", rIn->GetName(), static_cast(rIn)->getVal()); } name += Form("_%u", RooRandom::integer(std::numeric_limits::max() - 1)); writeToysHere->WriteTObject(new HypoTestResult(*hcResult), name); @@ -1454,8 +1450,8 @@ RooStats::HypoTestResult * HybridNew::readToysFromFile(const RooAbsCollection & if (verbose) std::cout << "Reading toys for "; TString prefix1 = TString::Format("HypoTestResult_mh%g",mass_); TString prefix2 = TString::Format("HypoTestResult"); - RooLinkedListIter it = rVals.iterator(); - for (RooRealVar *rIn = (RooRealVar*) it.Next(); rIn != 0; rIn = (RooRealVar*) it.Next()) { + for (RooAbsArg *rInAbsArg : rVals) { + RooRealVar *rIn = static_cast(rInAbsArg); if (verbose) std::cout << rIn->GetName() << " = " << rIn->getVal() << " "; prefix1 += Form("_%s%g", rIn->GetName(), rIn->getVal()); prefix2 += Form("_%s%g", rIn->GetName(), rIn->getVal()); diff --git a/src/MarkovChainMC.cc b/src/MarkovChainMC.cc index fe2e73e1864..5e72484e1d0 100644 --- a/src/MarkovChainMC.cc +++ b/src/MarkovChainMC.cc @@ -262,8 +262,7 @@ int MarkovChainMC::runOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStat if (verbose > 1) { std::cout << "\nDiscrete model point " << (i+1) << std::endl; discreteModelPointSets_[i].Print("V"); } } RooArgSet discretePOI; - RooLinkedListIter iter = poi.iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : poi) { if (discreteModelPointSets_[0].find(a->GetName())) discretePOI.add(*a); } if (verbose > 1) { std::cout << "Discrete POI: " ; discretePOI.Print(""); } diff --git a/src/MultiDimFit.cc b/src/MultiDimFit.cc index d8519559f56..683d9ff480e 100644 --- a/src/MultiDimFit.cc +++ b/src/MultiDimFit.cc @@ -166,9 +166,8 @@ bool MultiDimFit::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooS nOtherFloatingPoi_ = 0; deltaNLL_ = 0; int nConstPoi=0; - RooLinkedListIter iterP = mc_s->GetParametersOfInterest()->iterator(); std::string setConstPOI; - for (RooAbsArg *a = (RooAbsArg*) iterP.Next(); a != 0; a = (RooAbsArg*) iterP.Next()) { + for (RooAbsArg *a : *mc_s->GetParametersOfInterest()) { if (poiList_.contains(*a)) continue; RooRealVar *rrv = dynamic_cast(a); if (rrv == 0) { std::cerr << "MultiDimFit: Parameter of interest " << a->GetName() << " which is not a RooRealVar will be ignored" << std::endl; continue; } @@ -311,8 +310,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { RooArgSet mcPoi(*mc_s->GetParametersOfInterest()); if (poi_.empty()) { - RooLinkedListIter iterP = mc_s->GetParametersOfInterest()->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterP.Next(); a != 0; a = (RooAbsArg*) iterP.Next()) { + for (RooAbsArg *a : *mc_s->GetParametersOfInterest()) { poi_.push_back(a->GetName()); } } @@ -372,8 +370,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { RooArgSet mcNuis(*mc_s->GetNuisanceParameters()); if(saveSpecifiedNuis_=="all"){ specifiedNuis_.clear(); - RooLinkedListIter iterN = mc_s->GetNuisanceParameters()->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterN.Next(); a != 0; a = (RooAbsArg*) iterN.Next()) { + for (RooAbsArg *a : *mc_s->GetNuisanceParameters()) { if (poiList_.contains(*a)) continue; specifiedNuis_.push_back(a->GetName()); } @@ -384,8 +381,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { while(token) { const RooArgSet* group = mc_s->GetWS()->set((std::string("group_") + token).data()); if (group){ - RooLinkedListIter iterN = group->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterN.Next(); a != 0; a = (RooAbsArg*) iterN.Next()) { + for (RooAbsArg *a : *group) { specifiedNuis_.push_back(a->GetName()); } }else if (!poiList_.find(token)){ @@ -406,8 +402,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { } } if(saveInactivePOI_){ - RooLinkedListIter iterP = mc_s->GetParametersOfInterest()->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterP.Next(); a != 0; a = (RooAbsArg*) iterP.Next()) { + for (RooAbsArg *a : *mc_s->GetParametersOfInterest()) { if (poiList_.contains(*a)) continue; if (specifiedList_.contains(*a)) continue; RooRealVar *rrv = dynamic_cast(a); diff --git a/src/ProcessNormalization.cc b/src/ProcessNormalization.cc index 3ced2b9b58c..f61c9b17628 100644 --- a/src/ProcessNormalization.cc +++ b/src/ProcessNormalization.cc @@ -59,26 +59,23 @@ void ProcessNormalization::addOtherFactor(RooAbsReal &factor) { Double_t ProcessNormalization::evaluate() const { double logVal = 0.0; if (thetaListVec_.empty()) { - RooFIter iterTheta = thetaList_.fwdIterator(); std::vector & thetaListVec = const_cast&>(thetaListVec_); thetaListVec.reserve(thetaList_.getSize()); - for (RooAbsArg *a = iterTheta.next(); a != 0; a = iterTheta.next()) { + for (RooAbsArg *a : thetaList_) { thetaListVec.push_back(dynamic_cast(a)); } } if (asymmThetaListVec_.empty()) { - RooFIter iterTheta = asymmThetaList_.fwdIterator(); std::vector & asymmThetaListVec = const_cast&>(asymmThetaListVec_); asymmThetaListVec.reserve(asymmThetaList_.getSize()); - for (RooAbsArg *a = iterTheta.next(); a != 0; a = iterTheta.next()) { + for (RooAbsArg *a : asymmThetaList_) { asymmThetaListVec.push_back(dynamic_cast(a)); } } if (otherFactorListVec_.empty()) { - RooFIter iterOther = otherFactorList_.fwdIterator(); std::vector & otherFactorListVec = const_cast&>(otherFactorListVec_); otherFactorListVec.reserve(otherFactorList_.getSize()); - for (RooAbsArg *a = iterOther.next(); a != 0; a = iterOther.next()) { + for (RooAbsArg *a : otherFactorList_) { otherFactorListVec.push_back(dynamic_cast(a)); } } diff --git a/src/ProfiledLikelihoodRatioTestStatExt.cc b/src/ProfiledLikelihoodRatioTestStatExt.cc index b3378f154b0..5651a0da40f 100644 --- a/src/ProfiledLikelihoodRatioTestStatExt.cc +++ b/src/ProfiledLikelihoodRatioTestStatExt.cc @@ -152,8 +152,7 @@ ProfiledLikelihoodTestStatOpt::ProfiledLikelihoodTestStatOpt( DBG(DBG_PLTestStat_ctor, (std::cout << "All params: " << std::endl)) DBG(DBG_PLTestStat_ctor, (params_->Print("V"))) DBG(DBG_PLTestStat_ctor, (std::cout << "Snapshot: " << std::endl)) DBG(DBG_PLTestStat_ctor, (snap_.Print("V"))) DBG(DBG_PLTestStat_ctor, (std::cout << "POI: " << std::endl)) DBG(DBG_PLTestStat_ctor, (poi_.Print("V"))) - RooLinkedListIter it = poi.iterator(); - for (RooAbsArg *a = (RooAbsArg*) it.Next(); a != 0; a = (RooAbsArg*) it.Next()) { + for (RooAbsArg *a : poi) { // search for this poi in the parameters and in the snapshot RooAbsArg *ps = snap_.find(a->GetName()); RooAbsArg *pp = params_->find(a->GetName()); diff --git a/src/RobustHesse.cc b/src/RobustHesse.cc index 136682e83c5..ad5306b1c76 100644 --- a/src/RobustHesse.cc +++ b/src/RobustHesse.cc @@ -36,10 +36,8 @@ void RobustHesse::initialize() { // Get a list of the floating RooRealVars std::unique_ptr allpars(nll_->getParameters(RooArgSet())); - RooFIter iter = allpars->fwdIterator(); - RooAbsArg *item; std::vector allVars; - while ((item = iter.next())) { + for (RooAbsArg *item : *allpars) { RooRealVar *rrv = dynamic_cast(item); if (rrv && !rrv->isConstant()) { allVars.push_back(Var()); @@ -587,9 +585,7 @@ void RobustHesse::LoadHessianFromFile(std::string const& filename) { void RobustHesse::ProtectArgSet(RooArgSet const& set) { std::vector names; - RooFIter iter = set.fwdIterator(); - RooAbsArg *item; - while ((item = iter.next())) { + for (RooAbsArg *item : set) { RooRealVar *rrv = dynamic_cast(item); if (rrv && !rrv->isConstant()) { names.push_back(rrv->GetName()); diff --git a/src/RooCheapProduct.cc b/src/RooCheapProduct.cc index 4d5a95373ed..1583e076b44 100644 --- a/src/RooCheapProduct.cc +++ b/src/RooCheapProduct.cc @@ -6,8 +6,7 @@ RooCheapProduct::RooCheapProduct(const char *name, const char *title, const RooA terms_("!terms","Set of real product components",this), offset_(1.0) { - RooFIter iter = terms.fwdIterator(); - for (RooAbsArg *a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg *a : terms) { RooAbsReal *rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Component ")+a->GetName()+" of RooCheapProduct is a "+a->ClassName()); @@ -32,10 +31,9 @@ RooCheapProduct::RooCheapProduct(const RooCheapProduct& other, const char* name) Double_t RooCheapProduct::evaluate() const { if (vterms_.empty()) { - RooFIter iter = terms_.fwdIterator(); std::vector & vterms = const_cast&>(vterms_); vterms.reserve(terms_.getSize()); - for (RooAbsArg *a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg *a : terms_) { vterms.push_back(dynamic_cast(a)); } } diff --git a/src/RooEFTScalingFunction.cc b/src/RooEFTScalingFunction.cc index 699cae17ac3..cd6805e4688 100644 --- a/src/RooEFTScalingFunction.cc +++ b/src/RooEFTScalingFunction.cc @@ -1,4 +1,4 @@ -#include "HiggsAnalysis/CombinedLimit/interface/RooEFTScalingFunction.h" +#include "../interface/RooEFTScalingFunction.h" ClassImp(RooEFTScalingFunction) @@ -10,8 +10,7 @@ RooEFTScalingFunction::RooEFTScalingFunction(const char *name, const char *title { // Add Wilson coefficients to terms_ container - RooFIter iter = terms.fwdIterator(); - for( RooAbsArg *a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg *a : terms) { RooAbsReal *rar = dynamic_cast(a); if (!rar) { throw std::invalid_argument(std::string("Term ")+a->GetName()+" of RooEFTScalingFunction is a "+a->ClassName()); diff --git a/src/RooMorphingPdf.cc b/src/RooMorphingPdf.cc index 4c87c9df038..14ba9873667 100644 --- a/src/RooMorphingPdf.cc +++ b/src/RooMorphingPdf.cc @@ -48,11 +48,7 @@ RooMorphingPdf::RooMorphingPdf(const char* name, const char* title, mh_lo_(0.), mh_hi_(0.) { SetAxisInfo(); - TIterator* pdf_iter = pdfs.createIterator(); - RooAbsArg* pdf; - while ((pdf = reinterpret_cast(pdf_iter->Next()))) - pdfs_.add(*pdf); - delete pdf_iter; + pdfs_.add(pdfs); } RooMorphingPdf::RooMorphingPdf(const RooMorphingPdf& other, const char* name) diff --git a/src/RooMultiPdf.cxx b/src/RooMultiPdf.cxx index 7a2847eb4f4..6f86b18580a 100644 --- a/src/RooMultiPdf.cxx +++ b/src/RooMultiPdf.cxx @@ -24,11 +24,9 @@ RooMultiPdf::RooMultiPdf(const char *name, const char *title, RooCategory& _x, c c("_pdfs","The list of pdfs",this), x("_index","the pdf index",this,_x) { - TIterator *pdfIter=_c.createIterator(); int count=0; - RooAbsPdf *fPdf; - while ( (fPdf = (RooAbsPdf*) pdfIter->Next()) ){ + for (RooAbsArg *fPdf : _c) { c.add(*fPdf); // This is done by the user BUT is there a way to do it at construction? _x.defineType(Form("_pdf%d",count),count);//(fPdf->getParameters())->getSize()); @@ -54,10 +52,7 @@ RooMultiPdf::RooMultiPdf(const RooMultiPdf& other, const char* name) : fIndex=other.fIndex; nPdfs=other.nPdfs; - TIterator *pdfIter=(other.c).createIterator(); - - RooAbsPdf *fPdf; - while ( (fPdf = (RooAbsPdf*) pdfIter->Next()) ){ + for (RooAbsArg *fPdf : other.c) { c.add(*fPdf); std::unique_ptr variables(fPdf->getVariables()); std::unique_ptr nonConstVariables(variables->selectByAttrib("Constant", false)); diff --git a/src/RooParametricHist.cxx b/src/RooParametricHist.cxx index 59a825d5392..0efb3453448 100644 --- a/src/RooParametricHist.cxx +++ b/src/RooParametricHist.cxx @@ -17,9 +17,6 @@ #include "RooFit.h" #include "TFile.h" -#include "TIterator.h" - -//using namespace RooFit ; ClassImp(RooParametricHist) @@ -34,11 +31,7 @@ RooParametricHist::RooParametricHist(const char *name, pars("pars","pars",this) //SM_shape("SM_shape","SM_shape",this,_SM_shape), { - TIterator *varIter=_pars.createIterator(); - RooAbsReal *fVar; - while ( (fVar = (RooAbsReal*)varIter->Next()) ){ - pars.add(*fVar); - } + pars.add(_pars); if ( pars.getSize() != _shape.GetNbinsX() ){ std::cerr << " Warning, number of parameters not equal to number of bins in shape histogram! " << std::endl; assert(0); @@ -60,17 +53,8 @@ RooParametricHist::RooParametricHist(const RooParametricHist& other, const char* _hasMorphs=other._hasMorphs; _cval = other._cval; - TIterator *varIter=other.pars.createIterator(); - RooAbsReal *fVar; - while ( (fVar = (RooAbsReal*) varIter->Next()) ){ - pars.add(*fVar); - } - - TIterator *cIter=other._coeffList.createIterator(); - RooAbsReal *cVar; - while ( (cVar = (RooAbsReal*) cIter->Next()) ){ - _coeffList.add(*cVar); - } + pars.add(other.pars); + _coeffList.add(other._coeffList); for(int i=0; i<=N_bins; i++) { bins.push_back(other.bins[i]); @@ -109,11 +93,8 @@ RooArgList & RooParametricHist::getAllBinVars() const { double RooParametricHist::getFullSum() const { double sum=0; - TIterator *varIter=pars.createIterator(); - RooAbsReal *fVar; - int i=0; - while ( (fVar = (RooAbsReal*) varIter->Next()) ){ - double thisVal = fVar->getVal(); + for (int i = 0; i < pars.getSize(); ++i) { + double thisVal = static_cast(pars[i]).getVal(); if (_hasMorphs) thisVal*=evaluateMorphFunction(i); sum+=thisVal; i++; diff --git a/src/RooParametricHist2D.cxx b/src/RooParametricHist2D.cxx index 771c173499b..45434d2ec35 100644 --- a/src/RooParametricHist2D.cxx +++ b/src/RooParametricHist2D.cxx @@ -33,29 +33,13 @@ RooParametricHist2D::RooParametricHist2D( const char *name, pars("pars","pars",this) //SM_shape("SM_shape","SM_shape",this,_SM_shape), { - // std::cout << "Constructing..." << std::endl; - // std::cout << "_pars size... " << _pars.getSize() << std::endl; - // std::cout << "_pars type... " << typeid(_pars.first()).name() << std::endl; - - TIterator *varIter=_pars.createIterator(); - RooAbsReal *fVar; - while ( (fVar = (RooAbsReal*)varIter->Next()) ){ - // std::cout << "fVar type... " << typeid(fVar).name() << std::endl; - // std::cout << "*fVar type... " << typeid(*fVar).name() << std::endl; - - pars.add(*fVar); - } - - // std::cout << "Constructed..." << std::endl; - // std::cout << "pars size... " << pars.getSize() << std::endl; - // std::cout << "pars type... " << typeid(pars.first()).name() << std::endl; + pars.add(_pars); if ( pars.getSize() != _shape.GetNbinsY()*_shape.GetNbinsX() ){ std::cout << " Warning, number of parameters not equal to number of bins in shape histogram! " << std::endl; } initializeBins(_shape); - // std::cout << "Bins initialized" << std::endl; // initializeNorm(); cval = -1; @@ -75,20 +59,7 @@ RooParametricHist2D::RooParametricHist2D( const RooParametricHist2D& other, N_bins_y = other.N_bins_y; //sum = other.sum; - // std::cout << "Clone _pars size... " << other.pars.getSize() << std::endl; - // std::cout << "Clone other.pars.first() type... " << typeid(other.pars.first()).name() << std::endl; - // std::cout << "Clone *other.pars.first() type... " << typeid(*other.pars.first()).name() << std::endl; - // std::cout << "Clone &other.pars.first() type... " << typeid(&other.pars.first()).name() << std::endl; - - - TIterator *varIter=other.pars.createIterator(); - RooAbsReal *fVar; - // std::cout << "Check 1" << std::endl; - while ( (fVar = (RooAbsReal*)varIter->Next()) ){ - // std::cout << fVar->GetName() << ": " << typeid(&fVar).name() << std::endl; - pars.add(*fVar); - } - // std::cout << "Check 2" << std::endl; + pars.add(other.pars); for(int i=0; i<=N_bins_x; ++i) { bins_x.push_back(other.bins_x[i]); @@ -136,13 +107,10 @@ void RooParametricHist2D::initializeBins(const TH2 &shape) const { } double RooParametricHist2D::getFullSum() const { - //std::cout << "Getting full sum" << std::endl; double sum=0; - TIterator *varIter=pars.createIterator(); - RooAbsReal *fVar; - while ( (fVar = (RooAbsReal*)varIter->Next()) ){ - sum+=fVar->getVal(); + for (RooAbsArg *arg : pars) { + sum += static_cast(arg)->getVal(); } return sum; diff --git a/src/RooParametricShapeBinPdf.cc b/src/RooParametricShapeBinPdf.cc index 6b717750695..ff33ed60c6c 100644 --- a/src/RooParametricShapeBinPdf.cc +++ b/src/RooParametricShapeBinPdf.cc @@ -47,11 +47,7 @@ RooParametricShapeBinPdf::RooParametricShapeBinPdf(const char *name, const char xMin(0) { memset(&xArray, 0, sizeof(xArray)); - TIterator *varIter=_pars.createIterator(); - RooAbsReal *fVar; - while ( (fVar = (RooAbsReal*)varIter->Next()) ){ - pars.add(*fVar); - } + pars.add(_pars); setTH1Binning(_shape); RooAbsReal* myintegral; @@ -93,18 +89,8 @@ RooParametricShapeBinPdf::RooParametricShapeBinPdf(const RooParametricShapeBinPd xArray[i] = other.xArray[i]; } - TIterator *varIter=other.pars.createIterator(); - RooAbsReal *fVar; - while ( (fVar = (RooAbsReal*) varIter->Next()) ){ - pars.add(*fVar); - } - - TIterator *intIter=other.myintegrals.createIterator(); - RooAbsReal *fInt; - while ( (fInt = (RooAbsReal*) intIter->Next()) ){ - myintegrals.add(*fInt); - } - + pars.add(other.pars); + myintegrals.add(other.myintegrals); } //--------------------------------------------------------------------------- void RooParametricShapeBinPdf::setTH1Binning(const TH1 &_Hnominal){ diff --git a/src/RooSimultaneousOpt.cc b/src/RooSimultaneousOpt.cc index fd009151ac0..a10c3828a41 100644 --- a/src/RooSimultaneousOpt.cc +++ b/src/RooSimultaneousOpt.cc @@ -31,8 +31,7 @@ RooSimultaneousOpt::addExtraConstraints(const RooAbsCollection &pdfs) _extraConstraints.add(pdfs); } else { // slow - RooLinkedListIter iter = pdfs.iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : pdfs) { if (!_extraConstraints.contains(*a)) _extraConstraints.add(*a); } } diff --git a/src/RooSplineND.cc b/src/RooSplineND.cc index 56381ba7873..20fa95f2403 100644 --- a/src/RooSplineND.cc +++ b/src/RooSplineND.cc @@ -23,9 +23,8 @@ RooSplineND::RooSplineND(const char *name, const char *title, RooArgList &vars, float *b_map = new float(ndim_); - RooAbsReal *rIt; - TIterator *iter = vars.createIterator(); int it_c=0; - while( (rIt = (RooAbsReal*) iter->Next()) ){ + int it_c=0; + for (RooAbsArg *rIt : vars) { vars_.add(*rIt); std::vectortmpv(M_,0); v_map.insert(std::pair >(it_c,tmpv)); @@ -75,11 +74,7 @@ RooSplineND::RooSplineND(const RooSplineND& other, const char *name) : eps_ = other.eps_; axis_pts_ = other.axis_pts_; - RooAbsReal *rIt; - TIterator *iter = other.vars_.createIterator(); - while( (rIt = (RooAbsReal*) iter->Next()) ){ - vars_.add(*rIt); - } + vars_.add(other.vars_); w_mean = other.w_mean; w_rms = other.w_rms; @@ -113,11 +108,7 @@ RooSplineND::RooSplineND(const char *name, const char *title, const RooListProxy int ndim, int M, double eps, bool rescale, std::vector &w, std::map > &map, std::map > &rmap,double wmean, double wrms) : RooAbsReal(name, title),vars_("vars",this,RooListProxy()) { - RooAbsReal *rIt; - TIterator *iter = vars.createIterator(); - while( (rIt = (RooAbsReal*) iter->Next()) ){ - vars_.add(*rIt); - } + vars_.add(vars); ndim_ = ndim; M_ = M; eps_ = eps; diff --git a/src/SimpleCacheSentry.cc b/src/SimpleCacheSentry.cc index a3dff571d34..31b9627d856 100644 --- a/src/SimpleCacheSentry.cc +++ b/src/SimpleCacheSentry.cc @@ -31,8 +31,7 @@ SimpleCacheSentry::SimpleCacheSentry(const SimpleCacheSentry &other, const char void SimpleCacheSentry::addVars(const RooAbsCollection &vars) { - TIterator *iter = vars.createIterator(); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg* a : vars) { if (_deps.containsInstance(*a)) continue; // RooRealVars can return true to isDerived() if the ranges or binning depend on // other parameters, so always add RooRealVars to the list @@ -44,7 +43,6 @@ void SimpleCacheSentry::addVars(const RooAbsCollection &vars) _deps.add(*a); } } - delete iter; } void SimpleCacheSentry::addFunc(const RooAbsArg &func, const RooArgSet *obs) diff --git a/src/SimpleProdPdf.cc b/src/SimpleProdPdf.cc index 532f9c65f6c..0d2fb1bbd99 100644 --- a/src/SimpleProdPdf.cc +++ b/src/SimpleProdPdf.cc @@ -10,9 +10,7 @@ SimpleProdPdf::SimpleProdPdf() : RooAbsPdf() {} SimpleProdPdf::SimpleProdPdf(const char* name, const char* title, RooArgList const& pdfList) : RooAbsPdf(name, title), _pdfList("!pdfs", "List of PDFs", this) { - RooFIter iter = pdfList.fwdIterator(); - RooAbsArg* arg; - while ((arg = (RooAbsArg*)iter.next())) { + for (RooAbsArg *arg : pdfList) { RooAbsPdf* pdf = dynamic_cast(arg); if (!pdf) { coutW(InputArguments) << "SimpleProdPdf::SimpleProdPdf(" << GetName() << ") list arg " @@ -27,10 +25,8 @@ SimpleProdPdf::SimpleProdPdf(const char* name, const char* title, RooArgList con SimpleProdPdf::SimpleProdPdf(const char* name, const char* title, RooArgList& pdfList, std::vector const& pdfSettings) : RooAbsPdf(name, title), _pdfList("!pdfs", "List of PDFs", this) { - RooFIter iter = pdfList.fwdIterator(); - RooAbsArg* arg; int iSetting = -1; - while ((arg = (RooAbsArg*)iter.next())) { + for (RooAbsArg *arg : pdfList) { ++iSetting; RooAbsPdf* pdf = dynamic_cast(arg); if (!pdf) { @@ -130,10 +126,8 @@ void SimpleProdPdf::printMetaArgs(std::ostream& os) const std::list* SimpleProdPdf::binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const { - RooAbsPdf* pdf; - RooFIter pdfIter = _pdfList.fwdIterator(); - while ((pdf = (RooAbsPdf*)pdfIter.next())) { - std::list* hint = pdf->binBoundaries(obs, xlo, xhi); + for (RooAbsArg *pdf : _pdfList) { + std::list* hint = static_cast(pdf)->binBoundaries(obs, xlo, xhi); if (hint) { return hint; } diff --git a/src/SimplerLikelihoodRatioTestStatExt.cc b/src/SimplerLikelihoodRatioTestStatExt.cc index f62e441c72e..8e38d0d4379 100644 --- a/src/SimplerLikelihoodRatioTestStatExt.cc +++ b/src/SimplerLikelihoodRatioTestStatExt.cc @@ -56,11 +56,10 @@ SimplerLikelihoodRatioTestStatOpt::Evaluate(RooAbsData& data, RooArgSet& nullPOI if (paramsAlt_.get() == 0) paramsAlt_.reset(pdfAlt_->getParameters(data)); // if the dataset is not empty, redirect pdf nodes to the dataset - std::unique_ptr iterDepObs(pdfDepObs_.createIterator()); bool nonEmpty = data.numEntries() > 0; if (nonEmpty) { const RooArgSet *entry = data.get(0); - for (RooAbsArg *a = (RooAbsArg *) iterDepObs->Next(); a != 0; a = (RooAbsArg *) iterDepObs->Next()) { + for (RooAbsArg *a : pdfDepObs_) { a->redirectServers(*entry); } } @@ -76,8 +75,7 @@ SimplerLikelihoodRatioTestStatOpt::Evaluate(RooAbsData& data, RooArgSet& nullPOI // put back links in pdf nodes, otherwise if the dataset goes out of scope they have dangling pointers if (nonEmpty) { - iterDepObs->Reset(); - for (RooAbsArg *a = (RooAbsArg *) iterDepObs->Next(); a != 0; a = (RooAbsArg *) iterDepObs->Next()) { + for (RooAbsArg *a : pdfDepObs_) { a->redirectServers(*obs_); } } diff --git a/src/TestProposal.cc b/src/TestProposal.cc index f6df0e363b3..67b3f136825 100644 --- a/src/TestProposal.cc +++ b/src/TestProposal.cc @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -31,11 +30,10 @@ TestProposal::TestProposal(double divisor, const RooArgList &alwaysStepMe) : void TestProposal::Propose(RooArgSet& xPrime, RooArgSet& x ) { RooStats::SetParameters(&x, &xPrime); - RooLinkedListIter it(xPrime.iterator()); - RooRealVar* var; int n = xPrime.getSize(), j = floor(RooRandom::uniform()*n); const RooRealVar *indicatorPrime = discreteModelIndicator_ ? (RooRealVar*)xPrime.find(discreteModelIndicator_->GetName()) : 0; - for (int i = 0; (var = (RooRealVar*)it.Next()) != NULL; ++i) { + for (int i = 0; i < xPrime.getSize(); ++i) { + RooRealVar* var = static_cast(xPrime[i]); if (i == j) { if (alwaysStepMe_.contains(*var)) break; // don't step twice if (discreteModelIndicator_ != 0) { @@ -55,8 +53,7 @@ void TestProposal::Propose(RooArgSet& xPrime, RooArgSet& x ) break; } } - it = alwaysStepMe_.iterator(); - for (RooRealVar *poi = (RooRealVar*)it.Next(); poi != NULL; poi = (RooRealVar*)it.Next()) { + for (RooAbsArg *poi : alwaysStepMe_) { RooRealVar *var = (RooRealVar*) xPrime.find(poi->GetName()); if (var == 0) { std::cout << "ERROR: missing POI " << poi->GetName() << " in xPrime" << std::endl; diff --git a/src/ToyMCSamplerOpt.cc b/src/ToyMCSamplerOpt.cc index bbe2e8803c9..2f3c75c8763 100644 --- a/src/ToyMCSamplerOpt.cc +++ b/src/ToyMCSamplerOpt.cc @@ -145,8 +145,7 @@ toymcoptutils::SinglePdfGenInfo::generateAsimov(RooRealVar *&weightVar, double w if (boostAPA>0) { // trigger adaptive PA (setting boostAPA=1 will just use internal logic) if ( verbose > 0 ) CombineLogger::instance().log("ToyMCSamplerOpt.cc",__LINE__, "Using internal logic for binned/unbinned Asimov dataset generation",__func__); int nbins = 1; - RooLinkedListIter iter = observables_.iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : observables_) { RooRealVar *rrv = dynamic_cast(a); int mybins = rrv->getBins(); nbins *= (mybins ? mybins : 100); @@ -283,8 +282,7 @@ toymcoptutils::SinglePdfGenInfo::generateCountingAsimov() void toymcoptutils::SinglePdfGenInfo::setToExpected(RooProdPdf &prod, RooArgSet &obs) { - std::unique_ptr iter(prod.pdfList().createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : prod.pdfList()) { if (!a->dependsOn(obs)) continue; RooPoisson *pois = 0; if ((pois = dynamic_cast(a)) != 0) { @@ -302,8 +300,7 @@ toymcoptutils::SinglePdfGenInfo::setToExpected(RooPoisson &pois, RooArgSet &obs) { RooRealVar *myobs = 0; RooAbsReal *myexp = 0; - std::unique_ptr iter(pois.serverIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : pois.servers()) { if (obs.contains(*a)) { assert(myobs == 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): Two observables??"); myobs = dynamic_cast(a); diff --git a/src/VBFHZZ4L_RooSpinZeroPdf.cc b/src/VBFHZZ4L_RooSpinZeroPdf.cc index 156d658057d..d1846a5f8e8 100755 --- a/src/VBFHZZ4L_RooSpinZeroPdf.cc +++ b/src/VBFHZZ4L_RooSpinZeroPdf.cc @@ -34,23 +34,19 @@ ClassImp(VBFHZZ4L_RooSpinZeroPdf) ai("ai","ai",this,_ai), _coefList("coefList","List of funcficients",this) { - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *func : inCoefList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: :VBFHZZ4L_RooSpinZeroPdf(" << GetName() << ") funcficient " << func->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*func) ; } - delete coefIter; Integral_T1 = dynamic_cast(_coefList.at(0))-> analyticalIntegral(1000); Integral_T2 = dynamic_cast(_coefList.at(1))-> analyticalIntegral(1000); Integral_T3 = dynamic_cast(_coefList.at(2))-> analyticalIntegral(1000); Integral_T4 = dynamic_cast(_coefList.at(3))-> analyticalIntegral(1000); Integral_T5 = dynamic_cast(_coefList.at(4))-> analyticalIntegral(1000); -// _coefIter = _coefList.createIterator() ; } diff --git a/src/VBFHZZ4L_RooSpinZeroPdf_fast.cc b/src/VBFHZZ4L_RooSpinZeroPdf_fast.cc index 1688a1e5884..ca8b8c02333 100755 --- a/src/VBFHZZ4L_RooSpinZeroPdf_fast.cc +++ b/src/VBFHZZ4L_RooSpinZeroPdf_fast.cc @@ -31,27 +31,21 @@ VBFHZZ4L_RooSpinZeroPdf_fast::VBFHZZ4L_RooSpinZeroPdf_fast( obsList("obsList", "List of pdf observables", this), coefList("coefList", "List of pdf components", this) { - TIterator* coefIter = inObsList.createIterator(); - RooAbsArg* coef; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inObsList) { if (!dynamic_cast(coef)){ coutE(InputArguments) << "VBFHZZ4L_RooSpinZeroPdf_fast(" << GetName() << ") observable " << coef->GetName() << " is not of type RooAbsReal" << endl; assert(0); } obsList.add(*coef); } - delete coefIter; - coefIter = inCoefList.createIterator(); - coef=0; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inCoefList) { if (dynamic_cast(coef)==0 && dynamic_cast(coef)==0){ coutE(InputArguments) << "VBFHZZ4L_RooSpinZeroPdf_fast(" << GetName() << ") component " << coef->GetName() << " is not of type FastTemplateFunc_f" << endl; assert(0); } coefList.add(*coef); } - delete coefIter; } diff --git a/src/VVHZZ4L_RooSpinZeroPdf_1D_fast.cc b/src/VVHZZ4L_RooSpinZeroPdf_1D_fast.cc index 2118760435b..01a12dbd42a 100755 --- a/src/VVHZZ4L_RooSpinZeroPdf_1D_fast.cc +++ b/src/VVHZZ4L_RooSpinZeroPdf_1D_fast.cc @@ -28,27 +28,21 @@ VVHZZ4L_RooSpinZeroPdf_1D_fast::VVHZZ4L_RooSpinZeroPdf_1D_fast( obsList("obsList", "List of pdf observables", this), coefList("coefList", "List of pdf components", this) { - TIterator* coefIter = inObsList.createIterator(); - RooAbsArg* coef; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inObsList) { if (!dynamic_cast(coef)){ coutE(InputArguments) << "VVHZZ4L_RooSpinZeroPdf_1D_fast(" << GetName() << ") observable " << coef->GetName() << " is not of type RooAbsReal" << endl; assert(0); } obsList.add(*coef); } - delete coefIter; - coefIter = inCoefList.createIterator(); - coef=0; - while ((coef = (RooAbsArg*)coefIter->Next())){ + for (RooAbsArg *coef : inCoefList) { if (dynamic_cast(coef)==0 && dynamic_cast(coef)==0){ coutE(InputArguments) << "VVHZZ4L_RooSpinZeroPdf_1D_fast(" << GetName() << ") component " << coef->GetName() << " is not of type FastTemplateFunc_f" << endl; assert(0); } coefList.add(*coef); } - delete coefIter; } diff --git a/src/VerticalInterpHistPdf.cc b/src/VerticalInterpHistPdf.cc index cade9329b25..fca0b99a668 100644 --- a/src/VerticalInterpHistPdf.cc +++ b/src/VerticalInterpHistPdf.cc @@ -6,7 +6,6 @@ #include "RooFit.h" #include "Riostream.h" -#include "TIterator.h" #include "RooRealVar.h" #include "RooMsgService.h" #include "RooAbsData.h" @@ -103,8 +102,6 @@ VerticalInterpHistPdf::VerticalInterpHistPdf() : _cacheSingleGood(0) { // Default constructor - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; } @@ -127,9 +124,7 @@ VerticalInterpHistPdf::VerticalInterpHistPdf(const char *name, const char *title assert(0); } - TIterator* funcIter = inFuncList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)funcIter->Next())) { + for (RooAbsArg *func : inFuncList) { RooAbsPdf *pdf = dynamic_cast(func); if (!pdf) { coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") function " << func->GetName() << " is not of type RooAbsPdf" << std::endl; @@ -143,22 +138,14 @@ VerticalInterpHistPdf::VerticalInterpHistPdf(const char *name, const char *title delete params; _funcList.add(*func) ; } - delete funcIter; - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* coef; - while((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *coef : inCoefList) { if (!dynamic_cast(coef)) { coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*coef) ; } - delete coefIter; - - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; - } @@ -177,9 +164,6 @@ VerticalInterpHistPdf::VerticalInterpHistPdf(const VerticalInterpHistPdf& other, _cacheSingleGood(0) { // Copy constructor - - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; } @@ -188,8 +172,6 @@ VerticalInterpHistPdf::VerticalInterpHistPdf(const VerticalInterpHistPdf& other, VerticalInterpHistPdf::~VerticalInterpHistPdf() { // Destructor - delete _funcIter ; - delete _coefIter ; if (_cacheTotal) { delete _cacheTotal; for (int i = 0; i < _funcList.getSize(); ++i) delete _cacheSingle[i]; @@ -254,11 +236,11 @@ void VerticalInterpHistPdf::syncTotal() const { } for (int b = 1, nb = _cacheTotal->GetNbinsX(); b <= nb; ++b) { double val = _cacheSingle[0]->GetBinContent(b); - _coefIter->Reset(); - for (int i = 0; i < ndim; ++i) { + int i = 0; + for (RooAbsArg *coef : _coefList) { double dhi = _cacheSingle[2*i+1]->GetBinContent(b); double dlo = _cacheSingle[2*i+2]->GetBinContent(b); - double x = (dynamic_cast(_coefIter->Next()))->getVal(); + double x = dynamic_cast(coef)->getVal(); double alpha = x * 0.5 * ((dhi-dlo) + (dhi+dlo)*smoothStepFunc(x)); // alpha(0) = 0 // alpha(+1) = dhi @@ -271,6 +253,7 @@ void VerticalInterpHistPdf::syncTotal() const { } else { val += alpha; } + ++i; } if (val <= 0) val = 1e-9; _cacheTotal->SetBinContent(b, val); @@ -306,8 +289,6 @@ ClassImp(FastVerticalInterpHistPdf3D) FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase() { // Default constructor - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; } @@ -329,9 +310,7 @@ FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase(const char *name, c assert(0); } - TIterator* funcIter = inFuncList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)funcIter->Next())) { + for (RooAbsArg *func : inFuncList) { RooAbsPdf *pdf = dynamic_cast(func); if (!pdf) { coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") function " << func->GetName() << " is not of type RooAbsPdf" << std::endl; @@ -345,22 +324,14 @@ FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase(const char *name, c delete params; _funcList.add(*func) ; } - delete funcIter; - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* coef; - while((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *coef : inCoefList) { if (!dynamic_cast(coef)) { coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*coef) ; } - delete coefIter; - - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; - } //_____________________________________________________________________________ @@ -374,20 +345,13 @@ FastVerticalInterpHistPdfBase::FastVerticalInterpHistPdfBase(const FastVerticalI _morphs(other._morphs), _morphParams(other._morphParams) { // Copy constructor - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; _sentry.addVars(_coefList); _sentry.setValueDirty(); } //_____________________________________________________________________________ -FastVerticalInterpHistPdfBase::~FastVerticalInterpHistPdfBase() -{ - // Destructor - delete _funcIter ; - delete _coefIter ; -} +FastVerticalInterpHistPdfBase::~FastVerticalInterpHistPdfBase() = default; //_____________________________________________________________________________ @@ -627,12 +591,13 @@ void FastVerticalInterpHistPdf::setupCaches() const { _morphParams.resize(ndim); syncNominal(); //printf("Nominal template has been set up: \n"); _cacheNominal.Dump(); - _coefIter->Reset(); - for (int i = 0; i < ndim; ++i) { - _morphParams[i] = dynamic_cast(_coefIter->Next()); + int i = 0; + for (RooAbsArg *a : _coefList) { + _morphParams[i] = dynamic_cast(a); _morphs[i].sum.Resize(_cacheNominal.size()); _morphs[i].diff.Resize(_cacheNominal.size()); syncComponents(i); + ++i; } _cache = FastHisto(_cacheNominal); @@ -648,12 +613,13 @@ void FastVerticalInterpHistPdf2D::setupCaches() const { _morphParams.resize(ndim); syncNominal(); //printf("Nominal template has been set up: \n"); _cacheNominal.Dump(); - _coefIter->Reset(); - for (int i = 0; i < ndim; ++i) { - _morphParams[i] = dynamic_cast(_coefIter->Next()); + int i = 0; + for (RooAbsArg *a : _coefList) { + _morphParams[i] = dynamic_cast(a); _morphs[i].sum.Resize(_cacheNominal.size()); _morphs[i].diff.Resize(_cacheNominal.size()); syncComponents(i); + ++i; } _cache = FastHisto2D(_cacheNominal); @@ -668,12 +634,13 @@ void FastVerticalInterpHistPdf3D::setupCaches() const { _morphParams.resize(ndim); syncNominal(); //printf("Nominal template has been set up: \n"); _cacheNominal.Dump(); - _coefIter->Reset(); - for (int i = 0; i < ndim; ++i) { - _morphParams[i] = dynamic_cast(_coefIter->Next()); + int i = 0; + for (RooAbsArg *a : _coefList) { + _morphParams[i] = dynamic_cast(a); _morphs[i].sum.Resize(_cacheNominal.size()); _morphs[i].diff.Resize(_cacheNominal.size()); syncComponents(i); + ++i; } _cache = FastHisto3D(_cacheNominal); @@ -786,21 +753,17 @@ FastVerticalInterpHistPdf2Base::FastVerticalInterpHistPdf2Base(const char *name, assert(0); } if (pdf) { - RooArgSet *params = pdf->getParameters(obs); + std::unique_ptr params{pdf->getParameters(obs)}; if (params->getSize() > 0) { coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") pdf " << func->GetName() << " (" << func->ClassName()<<") has some parameters." << std::endl; obs.Print(""); params->Print(""); assert(0); } - delete params; } } - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* coef; - while((coef = (RooAbsArg*)coefIter->Next())) _coefList.add(*coef) ; - delete coefIter; + _coefList.add(inCoefList); } //_____________________________________________________________________________ @@ -851,9 +814,7 @@ FastVerticalInterpHistPdf2Base::initBase() const { if (_initBase) return; - TIterator* coefIter = _coefList.createIterator() ; - RooAbsArg* coef; - while((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *coef : _coefList) { const RooAbsReal *rrv = dynamic_cast(coef); if (!rrv) { coutE(InputArguments) << "ERROR: VerticalInterpHistPdf::VerticalInterpHistPdf(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << std::endl; @@ -861,8 +822,6 @@ FastVerticalInterpHistPdf2Base::initBase() const } _morphParams.push_back(rrv); } - delete coefIter; - _sentry.addVars(_coefList); _sentry.setValueDirty(); diff --git a/src/VerticalInterpPdf.cc b/src/VerticalInterpPdf.cc index aeaa3572bea..b68ee45bdab 100644 --- a/src/VerticalInterpPdf.cc +++ b/src/VerticalInterpPdf.cc @@ -4,7 +4,6 @@ #include "RooFit.h" #include "Riostream.h" -#include "TIterator.h" #include "TList.h" #include "RooRealProxy.h" #include "RooPlot.h" @@ -25,8 +24,6 @@ VerticalInterpPdf::VerticalInterpPdf() { // Default constructor // coverity[UNINIT_CTOR] - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; _quadraticRegion = 0; _pdfFloorVal = 1e-15; _integralFloorVal = 1e-10; @@ -51,30 +48,21 @@ VerticalInterpPdf::VerticalInterpPdf(const char *name, const char *title, const assert(0); } - TIterator* funcIter = inFuncList.createIterator() ; - RooAbsArg* func; - while((func = (RooAbsArg*)funcIter->Next())) { + for (RooAbsArg *func : inFuncList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: VerticalInterpPdf::VerticalInterpPdf(" << GetName() << ") function " << func->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _funcList.add(*func) ; } - delete funcIter; - TIterator* coefIter = inCoefList.createIterator() ; - RooAbsArg* coef; - while((coef = (RooAbsArg*)coefIter->Next())) { + for (RooAbsArg *coef : inCoefList) { if (!dynamic_cast(coef)) { coutE(InputArguments) << "ERROR: VerticalInterpPdf::VerticalInterpPdf(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*coef) ; } - delete coefIter; - - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; if (_quadraticAlgo == -1) { // multiplicative morphing: no way to do analytical integrals. @@ -100,50 +88,37 @@ VerticalInterpPdf::VerticalInterpPdf(const VerticalInterpPdf& other, const char* _integralFloorVal(other._integralFloorVal) { // Copy constructor - - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; } //_____________________________________________________________________________ -VerticalInterpPdf::~VerticalInterpPdf() -{ - // Destructor - delete _funcIter ; - delete _coefIter ; -} +VerticalInterpPdf::~VerticalInterpPdf() = default; //_____________________________________________________________________________ Double_t VerticalInterpPdf::evaluate() const { - // Calculate the current value - Double_t value(0) ; - // Do running sum of coef/func pairs, calculate lastCoef. - _funcIter->Reset() ; - _coefIter->Reset() ; - RooAbsReal* coef ; - RooAbsReal* func = (RooAbsReal*)_funcIter->Next(); + RooAbsReal* func = &(RooAbsReal&)_funcList[0]; + // Calculate the current value Double_t central = func->getVal(); - value = central; + Double_t value = central; if (_quadraticAlgo >= 0) { // additive interpolation - while((coef=(RooAbsReal*)_coefIter->Next())) { - Double_t coefVal = coef->getVal() ; - RooAbsReal* funcUp = (RooAbsReal*)_funcIter->Next() ; - RooAbsReal* funcDn = (RooAbsReal*)_funcIter->Next() ; + for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) { + Double_t coefVal = static_cast(_coefList[iCoef]).getVal() ; + RooAbsReal* funcUp = &(RooAbsReal&)_funcList[2 * iCoef + 1]; + RooAbsReal* funcDn = &(RooAbsReal&)_funcList[2 * iCoef + 2]; value += interpolate(coefVal, central, funcUp, funcDn); } } else { // multiplicative interpolation - while((coef=(RooAbsReal*)_coefIter->Next())) { - Double_t coefVal = coef->getVal() ; - RooAbsReal* funcUp = (RooAbsReal*)_funcIter->Next() ; - RooAbsReal* funcDn = (RooAbsReal*)_funcIter->Next() ; + for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) { + Double_t coefVal = static_cast(_coefList[iCoef]).getVal() ; + RooAbsReal* funcUp = &(RooAbsReal&)_funcList[2 * iCoef + 1]; + RooAbsReal* funcDn = &(RooAbsReal&)_funcList[2 * iCoef + 2]; value *= interpolate(coefVal, central, funcUp, funcDn); } } @@ -166,9 +141,7 @@ Bool_t VerticalInterpPdf::checkObservables(const RooArgSet* nset) const if (_quadraticAlgo == -1) return false; // multiplicative morphing. we don't care. - _coefIter->Reset() ; - RooAbsReal* coef ; - while((coef=(RooAbsReal*)_coefIter->Next())) { + for (RooAbsArg *coef : _coefList) { if (coef->dependsOn(*nset)) { coutE(InputArguments) << "RooRealPdf::checkObservables(" << GetName() << "): ERROR coefficient " << coef->GetName() << " depends on one or more of the following observables" ; nset->Print("1") ; @@ -176,12 +149,10 @@ Bool_t VerticalInterpPdf::checkObservables(const RooArgSet* nset) const } } - _funcIter->Reset() ; - _coefIter->Reset() ; - RooAbsReal* func ; - unsigned int ifunc = 0; - while((func = (RooAbsReal*)_funcIter->Next())) { - if (ifunc % 2 == 0) coef = (RooAbsReal*)_coefIter->Next(); + RooAbsReal * coef = nullptr; + for (int ifunc = 0; ifunc < _funcList.getSize(); ++ifunc) { + RooAbsReal* func = &(RooAbsReal&)_funcList[ifunc]; + if (ifunc % 2 == 0) coef = &(RooAbsReal&)_coefList[ifunc]; if (coef && func->observableOverlaps(nset,*coef)) { coutE(InputArguments) << "VerticalInterpPdf::checkObservables(" << GetName() << "): ERROR: coefficient " << coef->GetName() << " and FUNC " << func->GetName() << " have one or more observables in common" << std::endl; @@ -222,9 +193,8 @@ Int_t VerticalInterpPdf::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& cache = new CacheElem ; // Make list of function projection and normalization integrals - _funcIter->Reset() ; - RooAbsReal *func ; - while((func=(RooAbsReal*)_funcIter->Next())) { + for (RooAbsArg *funcAbsArg : _funcList) { + auto func = static_cast(funcAbsArg); RooAbsReal* funcInt = nullptr; if (isConditionalProdPdf(func)) { RooProdPdf *prod = static_cast(func); @@ -310,44 +280,33 @@ Double_t VerticalInterpPdf::analyticalIntegralWN(Int_t code, const RooArgSet* no // Handle trivial passthrough scenario if (code==0) return getVal(normSet2) ; - RooAbsReal *coef; Double_t value = 0; // WVE needs adaptation for rangeName feature CacheElem* cache = (CacheElem*) _normIntMgr.getObjByIndex(code-1) ; - TIterator* funcIntIter = cache->_funcIntList.createIterator() ; - RooAbsReal *funcInt = (RooAbsReal *) funcIntIter->Next(); - Double_t central = funcInt->getVal(); + Double_t central = static_cast(_funcList[0]).getVal(); value += central; - _coefIter->Reset() ; - while((coef=(RooAbsReal*)_coefIter->Next())) { - Double_t coefVal = coef->getVal(normSet2) ; - RooAbsReal * funcIntUp = (RooAbsReal*)funcIntIter->Next() ; - RooAbsReal * funcIntDn = (RooAbsReal*)funcIntIter->Next() ; + for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) { + Double_t coefVal = static_cast(_coefList[iCoef]).getVal(normSet2) ; + RooAbsReal * funcIntUp = &(RooAbsReal&)_funcList[2 * iCoef + 1]; + RooAbsReal * funcIntDn = &(RooAbsReal&)_funcList[2 * iCoef + 2]; value += interpolate(coefVal, central, funcIntUp, funcIntDn); } - delete funcIntIter ; - Double_t normVal(1) ; if (normSet2) { - TIterator* funcNormIter = cache->_funcNormList.createIterator() ; - - RooAbsReal* funcNorm = (RooAbsReal*) funcNormIter->Next(); - central = funcNorm->getVal(normSet2) ; + RooArgList& fnl = cache->_funcNormList; + central = static_cast(fnl[0]).getVal(normSet2) ; normVal = central; - _coefIter->Reset() ; - while((coef=(RooAbsReal*)_coefIter->Next())) { - RooAbsReal *funcNormUp = (RooAbsReal*)funcNormIter->Next() ; - RooAbsReal *funcNormDn = (RooAbsReal*)funcNormIter->Next() ; - Double_t coefVal = coef->getVal(normSet2) ; + for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) { + RooAbsReal *funcNormUp = &(RooAbsReal&)fnl[2 * iCoef + 1]; + RooAbsReal *funcNormDn = &(RooAbsReal&)fnl[2 * iCoef + 2]; + Double_t coefVal = static_cast(_coefList[iCoef]).getVal(normSet2) ; normVal += interpolate(coefVal, central, funcNormUp, funcNormDn); } - - delete funcNormIter ; } Double_t result = 0; diff --git a/src/utils.cc b/src/utils.cc index ad56448f1d5..7b6ecc61e47 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -57,11 +56,7 @@ namespace { RooProduct(other) {} RooArgList realTerms() const { RooArgList ret; - RooFIter compRIter = _compRSet.fwdIterator() ; - RooAbsReal* rcomp; - while((rcomp=(RooAbsReal*)compRIter.next())) { - ret.add(*rcomp); - } + ret.add(_compRSet); return ret; } }; @@ -76,15 +71,13 @@ RooArgList utils::factors(const RooProduct &prod) { void utils::printRDH(RooAbsData *data) { std::vector varnames, catnames; const RooArgSet *b0 = data->get(); - TIterator *iter = b0->createIterator(); - for (RooAbsArg *a = 0; (a = (RooAbsArg *)iter->Next()) != 0; ) { + for (RooAbsArg *a : *b0) { if (a->InheritsFrom("RooRealVar")) { varnames.push_back(a->GetName()); } else if (a->InheritsFrom("RooCategory")) { catnames.push_back(a->GetName()); } } - delete iter; size_t nv = varnames.size(), nc = catnames.size(); printf(" bin "); for (size_t j = 0; j < nv; ++j) { printf("%16.16s ", varnames[j].c_str()); } @@ -167,9 +160,8 @@ RooAbsPdf *utils::factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, Roo } if (id == typeid(RooSimultaneousOpt)) { RooSimultaneousOpt &o = dynamic_cast(pdf); - RooLinkedListIter iter = o.extraConstraints().iterator(); if (o.extraConstraints().getSize() > 0) needNew = true; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : o.extraConstraints()) { if (!constraints.contains(*a) && (!a->getAttribute("ignoreConstraint")) ) constraints.add(*a); } } @@ -215,8 +207,7 @@ void utils::factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgLis } else if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) { if (id == typeid(RooSimultaneousOpt)) { RooSimultaneousOpt &o = dynamic_cast(pdf); - RooLinkedListIter iter = o.extraConstraints().iterator(); - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *a : o.extraConstraints()) { if (!constraints.contains(*a) && (!a->getAttribute("ignoreConstraint"))) constraints.add(*a); } } @@ -251,10 +242,9 @@ void utils::factorizeFunc(const RooArgSet &observables, RooAbsReal &func, RooArg RooArgList components(prod->realComponents()); #endif //std::cout << "Function " << func.GetName() << " is a RooProduct with " << components.getSize() << " components." << std::endl; - std::unique_ptr iter(components.createIterator()); - for (RooAbsReal *funci = (RooAbsReal *) iter->Next(); funci != 0; funci = (RooAbsReal *) iter->Next()) { + for (RooAbsArg * funci : components) { //std::cout << " component " << funci->GetName() << " of type " << funci->ClassName() << "(dep obs? " << funci->dependsOn(observables) << ")" << std::endl; - factorizeFunc(observables, *funci, obsTerms, constraints, true); + factorizeFunc(observables, static_cast(*funci), obsTerms, constraints, true); } } else if (func.dependsOn(observables)) { if (!obsTerms.contains(func) || keepDuplicate) obsTerms.add(func); @@ -303,8 +293,7 @@ RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, const RooArgSet &obs, Ro RooArgSet tmp("RealBranchNodeList"), toClone; pdf->branchNodeServerList(&tmp); unsigned int nitems = tmp.getSize(); - RooFIter iter = tmp.fwdIterator(); - for (RooAbsArg *a = iter.next(); a != 0; a = iter.next()) { + for (RooAbsArg *a : tmp) { if (a == pdf) toClone.add(*a); else if (a->dependsOn(obs)) toClone.add(*a); } @@ -319,12 +308,9 @@ RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, const RooArgSet &obs, Ro void utils::getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients) { - std::unique_ptr iterAll(allObjects.createIterator()); - std::unique_ptr iterVal(values.createIterator()); - for (RooAbsArg *v = (RooAbsArg *) iterVal->Next(); v != 0; v = (RooAbsArg *) iterVal->Next()) { + for (RooAbsArg *v : values) { if (typeid(*v) != typeid(RooRealVar) && typeid(*v) != typeid(RooCategory)) continue; - std::unique_ptr clientIter(v->clientIterator()); - for (RooAbsArg *a = (RooAbsArg *) clientIter->Next(); a != 0; a = (RooAbsArg *) clientIter->Next()) { + for (RooAbsArg *a : v->clients()) { if (allObjects.containsInstance(*a) && !clients.containsInstance(*a)) clients.add(*a); } } @@ -332,8 +318,7 @@ void utils::getClients(const RooAbsCollection &values, const RooAbsCollection &a bool utils::setAllConstant(const RooAbsCollection &coll, bool constant) { bool changed = false; - std::unique_ptr iter(coll.createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : coll) { RooRealVar *v = dynamic_cast(a); RooCategory *cv = dynamic_cast(a); if (v && (v->isConstant() != constant)) { @@ -376,8 +361,7 @@ bool utils::checkModel(const RooStats::ModelConfig &model, bool throwOnFail) { if (model.GetParametersOfInterest() == 0) { ok = false; errors << "ERROR: model does not define parameters of interest.\n"; } else { - iter.reset(model.GetParametersOfInterest()->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *model.GetParametersOfInterest()) { RooRealVar *v = dynamic_cast(a); if (!v) { ok = false; errors << "ERROR: parameter of interest " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; } if (v->isConstant()) { ok = false; errors << "ERROR: parameter of interest " << a->GetName() << " is constant\n"; continue; } @@ -386,8 +370,7 @@ bool utils::checkModel(const RooStats::ModelConfig &model, bool throwOnFail) { } } if (model.GetNuisanceParameters() != 0) { - iter.reset(model.GetNuisanceParameters()->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *model.GetNuisanceParameters()) { RooRealVar *v = dynamic_cast(a); if (!v) { ok = false; errors << "ERROR: nuisance parameter " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; } if (v->isConstant()) { ok = false; errors << "ERROR: nuisance parameter " << a->GetName() << " is constant\n"; continue; } @@ -396,17 +379,15 @@ bool utils::checkModel(const RooStats::ModelConfig &model, bool throwOnFail) { } } if (model.GetGlobalObservables() != 0) { - iter.reset(model.GetGlobalObservables()->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *model.GetGlobalObservables()) { RooRealVar *v = dynamic_cast(a); if (!v) { ok = false; errors << "ERROR: global observable " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; } if (!v->isConstant()) { ok = false; errors << "ERROR: global observable " << a->GetName() << " is not constant\n"; continue; } if (!pdf->dependsOn(*v)) { errors << "WARNING: pdf does not depend on global observable " << a->GetName() << "\n"; continue; } } } - std::unique_ptr params(pdf->getParameters(*model.GetObservables())); - iter.reset(params->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + ; + for (RooAbsArg *a : *std::unique_ptr{pdf->getParameters(*model.GetObservables())}) { if (a->getAttribute("flatParam") && a->isConstant()) { ok = false; errors << "ERROR: parameter " << a->GetName() << " is declared as flatParam but is constant.\n"; } @@ -435,8 +416,7 @@ bool utils::checkModel(const RooStats::ModelConfig &model, bool throwOnFail) { ok = false; errors << "ERROR: have nuisance parameters, but can't factorize the pdf\n"; } std::unique_ptr obsParams(factorizedPdf->getParameters(*model.GetObservables())); - iter.reset(model.GetNuisanceParameters()->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *model.GetNuisanceParameters()) { if (!obsParams->contains(*a)) { errors << "WARNING: model pdf does not depend on nuisace parameter " << a->GetName() << "\n"; } @@ -611,14 +591,7 @@ utils::makePlots(const RooAbsPdf &pdf, const RooAbsData &data, const char *signa RooAbsPdf *pdfi = sim->getPdf(ds->GetName()); std::unique_ptr obs(pdfi->getObservables(ds)); if (obs->getSize() == 0) break; - TIterator *obs_iter = obs->createIterator(); - //std::cout << " PDF CHECKING " << std::endl; - //pdfi->Print("v"); - //ds->Print("v"); - //std::cout << " ------------ " << std::endl; - - //for (int iobs=0;iobsgetSize();iobs++){ - for (RooAbsArg *a = 0; (a = (RooAbsArg *)obs_iter->Next()) != 0; ) { + for (RooAbsArg *a : *obs) { RooRealVar *x = dynamic_cast(a); if (x == 0) continue; int nbins = x->numBins(); if (nbins == 0) nbins = 100; @@ -642,9 +615,7 @@ utils::makePlots(const RooAbsPdf &pdf, const RooAbsData &data, const char *signa } else if (pdf.canBeExtended()) { std::unique_ptr obs(pdf.getObservables(&data)); - //for (int iobs=0;iobsgetSize();iobs++){ - TIterator *obs_iter = obs->createIterator(); - for (RooAbsArg *a = 0; (a = (RooAbsArg *)obs_iter->Next()) != 0; ) { + for (RooAbsArg *a : *obs) { RooRealVar *x = dynamic_cast(a); if (x != 0) { ret.push_back(x->frame()); @@ -669,8 +640,8 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) { src_ = &src; values_.resize(src.getSize()); } - RooLinkedListIter iter = src.iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src.getSize(); ++i) { + RooAbsArg *a = src[i]; RooRealVar *rrv = dynamic_cast(a); if (rrv == 0) { RooCategory *rc = dynamic_cast(a); @@ -686,8 +657,8 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) { void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const { if (&src == src_) { - RooLinkedListIter iter = src.iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src.getSize(); ++i) { + RooAbsArg *a = src[i]; RooRealVar *rrv = dynamic_cast(a); if (rrv!=0) rrv->setVal(values_[i]); else { @@ -696,8 +667,8 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const { } } } else { - RooLinkedListIter iter = src_->iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src_->getSize(); ++i) { + RooAbsArg *a = (*src_)[i]; RooAbsArg *a2 = src.find(a->GetName()); if (a2 == 0) continue; RooRealVar *rrv = dynamic_cast(a2); if (rrv!=0) rrv->setVal(values_[i]); @@ -712,8 +683,8 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const { void utils::CheapValueSnapshot::Print(const char *fmt) const { if (src_ == 0) { printf("\n"); return; } if (fmt[0] == 'V') { - RooLinkedListIter iter = src_->iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src_->getSize(); ++i) { + RooAbsArg *a = (*src_)[i]; printf(" %3d) %-30s = %9.6g\n", i, a->GetName(), values_[i]); } printf("\n"); @@ -764,8 +735,7 @@ void utils::setModelParameters( const std::string & setPhysicsModelParameterExpr std::cout<<"interpreting "< iter(params.createIterator()); - for (RooAbsArg *tmp = (RooAbsArg*) iter->Next(); tmp != 0; tmp = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *tmp : params) { bool isrvar = tmp->IsA()->InheritsFrom(RooRealVar::Class()); // check its type @@ -886,8 +856,7 @@ void utils::setModelParameterRanges( const std::string & setPhysicsModelParamete std::cout<<"interpreting "< iter(params.createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : params) { RooRealVar *tmpParameter = dynamic_cast(a); const std::string &target = tmpParameter->GetName(); std::smatch match; @@ -1035,8 +1004,8 @@ bool utils::anyParameterAtBoundaries( const RooArgSet ¶ms, int verbosity ){ static std::unordered_map timesFoundAtBoundary; bool isAnyBad = false; - RooLinkedListIter iter = params.iterator(); int i = 0; - for (RooRealVar *a = (RooRealVar *) iter.Next(); a != 0; a = (RooRealVar *) iter.Next(), ++i) { + for (RooAbsArg *aAbsArg : params) { + RooRealVar *a = static_cast(aAbsArg); bool isBad = isParameterAtBoundary(*a); @@ -1062,8 +1031,7 @@ bool utils::anyParameterAtBoundaries( const RooArgSet ¶ms, int verbosity ){ int utils::countFloating(const RooArgSet ¶ms){ int count=0; - RooLinkedListIter iter = params.iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (RooAbsArg *a : params) { if (!a->isConstant()) count++; } return count; @@ -1084,8 +1052,7 @@ bool utils::freezeAllDisassociatedRooMultiPdfParameters(const RooArgSet & multiP // For each multiPdf, get the active pdf and remove its parameters // from this list of params and then freeze the remaining ones - RooLinkedListIter iter = multiPdfs.iterator(); - for (RooAbsArg *P = (RooAbsArg *) iter.Next(); P != 0; P = (RooAbsArg *) iter.Next()) { + for (RooAbsArg *P : multiPdfs) { RooMultiPdf *mpdf = dynamic_cast(P); RooAbsPdf *pdf = (RooAbsPdf*)mpdf->getCurrentPdf(); if (freezeDisassParams_verb) std::cout << " Current active PDF - " << pdf->GetName() <