diff --git a/interface/AsymQuad.h b/interface/AsymQuad.h index 56dee3d63cd..6c4de6d860e 100644 --- a/interface/AsymQuad.h +++ b/interface/AsymQuad.h @@ -38,8 +38,6 @@ class AsymQuad : public RooAbsReal { RooListProxy _coefList; // List of coefficients Double_t smoothRegion_; Int_t smoothAlgo_; - TIterator* _funcIter; //! Iterator over FUNC list - TIterator* _coefIter; //! Iterator over coefficient list private: Double_t interpolate(Double_t theta_, Double_t valueCenter_, Double_t valueHigh_, Double_t valueLow_) const; 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/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/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 51e3ee857d7..3e3a9db1036 100644 --- a/src/AsimovUtils.cc +++ b/src/AsimovUtils.cc @@ -21,8 +21,7 @@ RooAbsData *asimovutils::asimovDatasetNominal(RooStats::ModelConfig *mc, double if (verbose>2) { Logger::instance().log(std::string(Form("AsimovUtils.cc: %d -- Parameters after fit for asimov dataset",__LINE__)),Logger::kLogLevelInfo,__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); Logger::instance().log(std::string(Form("AsimovUtils.cc: %d -- %s",__LINE__,varstring.Data())),Logger::kLogLevelInfo,__func__); } @@ -45,8 +44,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 +65,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD if (verbose>2) { Logger::instance().log(std::string(Form("AsimovUtils.cc: %d -- Parameters after fit for asimov dataset",__LINE__)),Logger::kLogLevelInfo,__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); Logger::instance().log(std::string(Form("AsimovUtils.cc: %d -- %s",__LINE__,varstring.Data())),Logger::kLogLevelInfo,__func__); } diff --git a/src/AsymQuad.cc b/src/AsymQuad.cc index e9886929c44..82297a22614 100644 --- a/src/AsymQuad.cc +++ b/src/AsymQuad.cc @@ -11,8 +11,6 @@ _coefList("coefList", "List of coefficients", this), smoothRegion_(0), smoothAlgo_(0) { - _funcIter = _funcList.createIterator(); - _coefIter = _coefList.createIterator(); } AsymQuad::AsymQuad(const char *name, const char *title, const RooArgList& inFuncList, const RooArgList& inCoefList, Double_t smoothRegion, Int_t smoothAlgo) : @@ -28,30 +26,21 @@ smoothAlgo_(smoothAlgo) assert(0); } - TIterator* funcIter = inFuncList.createIterator(); - RooAbsArg* func; - while ((func = (RooAbsArg*)funcIter->Next())) { + for (RooAbsArg* func : inFuncList) { if (!dynamic_cast(func)) { coutE(InputArguments) << "ERROR: AsymQuad::AsymQuad(" << 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: AsymQuad::AsymQuad(" << GetName() << ") coefficient " << coef->GetName() << " is not of type RooAbsReal" << std::endl; assert(0); } _coefList.add(*coef); } - delete coefIter; - - _funcIter = _funcList.createIterator(); - _coefIter = _coefList.createIterator(); } AsymQuad::AsymQuad(const AsymQuad& other, const char* name): @@ -61,30 +50,21 @@ _coefList("!coefList", this, other._coefList), smoothRegion_(other.smoothRegion_), smoothAlgo_(other.smoothAlgo_) { - _funcIter = _funcList.createIterator(); - _coefIter = _coefList.createIterator(); } -AsymQuad::~AsymQuad() { - delete _funcIter; - delete _coefIter; -} +AsymQuad::~AsymQuad() = default; Double_t AsymQuad::evaluate() const { - Double_t result(0); - _funcIter->Reset(); - _coefIter->Reset(); - RooAbsReal* coef; - RooAbsReal* func = (RooAbsReal*)_funcIter->Next(); + RooAbsReal* func = &(RooAbsReal&)_funcList[0]; Double_t central = func->getVal(); - result = central; + Double_t result = central; - 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]; result += interpolate(coefVal, central, funcUp->getVal(), funcDn->getVal()); } diff --git a/src/AsymptoticLimits.cc b/src/AsymptoticLimits.cc index f056dd577d3..00971c9af09 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; } } 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 55b550d04bc..f699a3ec5bc 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 { @@ -1305,8 +1301,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 928e46b2534..9b938a60f1d 100644 --- a/src/CascadeMinimizer.cc +++ b/src/CascadeMinimizer.cc @@ -913,8 +913,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 b2281c7928f..3d80b7b6944 100644 --- a/src/Combine.cc +++ b/src/Combine.cc @@ -227,8 +227,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 +250,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 +538,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 +613,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 +635,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 +666,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do if (verbose > 0) { std::cout << "Floating the following parameters: "; toFloat.Print(""); Logger::instance().log(std::string(Form("Combine.cc: %d -- Floating the following parameters: ",__LINE__)),Logger::kLogLevelInfo,__func__); - std::unique_ptr iter(toFloat.createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : toFloat) { Logger::instance().log(std::string(Form("Combine.cc: %d %s ",__LINE__,a->GetName())),Logger::kLogLevelInfo,__func__); } } @@ -706,8 +700,7 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do if (verbose > 0) { std::cout << "Freezing the following parameters: "; toFreeze.Print(""); Logger::instance().log(std::string(Form("Combine.cc: %d -- Freezing the following parameters: ",__LINE__)),Logger::kLogLevelInfo,__func__); - std::unique_ptr iter(toFreeze.createIterator()); - for (RooAbsArg *a = (RooAbsArg*) iter->Next(); a != 0; a = (RooAbsArg*) iter->Next()) { + for (RooAbsArg *a : toFreeze) { Logger::instance().log(std::string(Form("Combine.cc: %d %s ",__LINE__,a->GetName())),Logger::kLogLevelInfo,__func__); } } @@ -764,9 +757,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(""); } @@ -1200,8 +1191,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); } } @@ -1210,20 +1200,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){ @@ -1233,8 +1218,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){ @@ -1248,8 +1232,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()*/) { @@ -1264,14 +1247,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) ; @@ -1291,8 +1271,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 b8f9adabc87..eefa05b0c20 100644 --- a/src/FitDiagnostics.cc +++ b/src/FitDiagnostics.cc @@ -1212,16 +1212,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; } @@ -1260,17 +1258,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; } @@ -1347,8 +1343,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; @@ -1358,8 +1353,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; @@ -1372,8 +1366,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 c68b2c3acec..6823d8f18a1 100644 --- a/src/FitterAlgoBase.cc +++ b/src/FitterAlgoBase.cc @@ -705,8 +705,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/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..8c421a6bf60 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() ; } 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 18e41b65777..e7ac6dbc470 100644 --- a/src/HybridNew.cc +++ b/src/HybridNew.cc @@ -1150,9 +1150,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); 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/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/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/RooNCSplineCore.cc b/src/RooNCSplineCore.cc index 68df9d9e025..e75dda0a264 100644 --- a/src/RooNCSplineCore.cc +++ b/src/RooNCSplineCore.cc @@ -277,8 +277,7 @@ void RooNCSplineCore::getLeafDependents(RooRealProxy& proxy, RooArgSet& set){ set.add(deps); } void RooNCSplineCore::addLeafDependents(RooArgSet& set){ - TIterator* iter = set.createIterator(); - RooAbsArg* absarg; - while ((absarg = (RooAbsArg*)iter->Next())){ if (dynamic_cast(absarg)) leafDepsList.add(*absarg); } - delete iter; + for (RooAbsArg * absarg : set) { + if (dynamic_cast(absarg)) leafDepsList.add(*absarg); + } } diff --git a/src/RooNCSpline_1D_fast.cc b/src/RooNCSpline_1D_fast.cc index fd0de69a443..62e7b337b63 100644 --- a/src/RooNCSpline_1D_fast.cc +++ b/src/RooNCSpline_1D_fast.cc @@ -175,12 +175,9 @@ Double_t RooNCSpline_1D_fast::evaluate() const{ if (verbosity==RooNCSplineCore::kVerbose){ cout << "RooNCSpline_1D_fast(" << GetName() << ")::evaluate = " << value << " at x = " << theXVar << endl; RooArgSet Xdeps; theXVar.absArg()->leafNodeServerList(&Xdeps, 0, true); - TIterator* iter = Xdeps.createIterator(); - RooAbsArg* var; - while ((var = (RooAbsArg*)iter->Next())){ + for (RooAbsArg * var : Xdeps) { cout << var->GetName() << " value = " << dynamic_cast(var)->getVal() << endl; } - delete iter; cout << endl; } return value; diff --git a/src/RooParametricHist.cxx b/src/RooParametricHist.cxx index 59a825d5392..aba709360b2 100644 --- a/src/RooParametricHist.cxx +++ b/src/RooParametricHist.cxx @@ -34,11 +34,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 +56,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]); diff --git a/src/RooSplineND.cc b/src/RooSplineND.cc index 56381ba7873..ec417b04dcb 100644 --- a/src/RooSplineND.cc +++ b/src/RooSplineND.cc @@ -75,11 +75,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 +109,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/VerticalInterpPdf.cc b/src/VerticalInterpPdf.cc index aeaa3572bea..a8abd9ee918 100644 --- a/src/VerticalInterpPdf.cc +++ b/src/VerticalInterpPdf.cc @@ -25,8 +25,6 @@ VerticalInterpPdf::VerticalInterpPdf() { // Default constructor // coverity[UNINIT_CTOR] - _funcIter = _funcList.createIterator() ; - _coefIter = _coefList.createIterator() ; _quadraticRegion = 0; _pdfFloorVal = 1e-15; _integralFloorVal = 1e-10; @@ -51,30 +49,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 +89,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 +142,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 +150,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 +194,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 +281,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 df4a53c2d04..243a5764487 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -51,11 +51,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; } }; @@ -64,15 +60,13 @@ namespace { 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()); } @@ -238,10 +232,9 @@ void utils::factorizeFunc(const RooArgSet &observables, RooAbsReal &func, RooArg RooProduct *prod = dynamic_cast(&func); RooArgList components(utils::factors(*prod)); //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); @@ -319,8 +312,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)) { @@ -363,8 +355,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; } @@ -373,8 +364,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; } @@ -383,17 +373,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"; }