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/src/AsimovUtils.cc b/src/AsimovUtils.cc index 51e3ee857d7..69e20e547fd 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__); } 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/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..26ff84a44f6 100644 --- a/src/CachingNLL.cc +++ b/src/CachingNLL.cc @@ -1305,8 +1305,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..3d48305840a 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; @@ -764,9 +762,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(""); } @@ -1269,9 +1265,8 @@ void Combine::addDiscreteNuisances(RooWorkspace *w){ while (RooAbsArg *arg = (RooAbsArg*)it->Next()) { (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 +1286,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..b3e72e45f06 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; } 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..11e53824595 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, diff --git a/src/HZGRooPdfs.cxx b/src/HZGRooPdfs.cxx index df8dede31a7..2c720c7d509 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[degree]).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[degree]; // 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_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..14943550c1a 100644 --- a/src/HZZ4L_RooSpinZeroPdf_1D.cc +++ b/src/HZZ4L_RooSpinZeroPdf_1D.cc @@ -27,16 +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() ; } 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_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/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/RooEFTScalingFunction.cc b/src/RooEFTScalingFunction.cc index 699cae17ac3..acb06e4413c 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) 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/utils.cc b/src/utils.cc index df4a53c2d04..682403f583e 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()); }