Skip to content

Commit

Permalink
Replace deprecated legacy iterators
Browse files Browse the repository at this point in the history
The legacy iterators are deprecated since ROOT 6.18 and they will be
removed at some point.

This commit also fixes a few memory leaks, and it might also benefit the
performance a bit because the legacy iterators had quite some overhead.
  • Loading branch information
guitargeek committed Dec 3, 2023
1 parent be488af commit 8e065b2
Show file tree
Hide file tree
Showing 67 changed files with 274 additions and 786 deletions.
3 changes: 0 additions & 3 deletions interface/AsymQuad.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "RooFit.h"
#include "Riostream.h"
#include "TIterator.h"
#include "TList.h"
#include <RooAbsReal.h>
#include "RooRealVar.h"
Expand Down Expand Up @@ -38,8 +37,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;
Expand Down
3 changes: 0 additions & 3 deletions interface/AtlasPdfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ class RooStarMomentMorph : public RooAbsPdf {
mutable std::vector<int> _nnuis;
mutable std::vector<double> _nref;

TIterator* _parItr ; //! do not persist
TIterator* _obsItr ; //! do not persist
TIterator* _pdfItr ; //!
mutable TMatrixD* _M; //!

Setting _setting;
Expand Down
5 changes: 1 addition & 4 deletions interface/FastTemplateFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ template <typename T> class FastTemplateFunc_t : public RooAbsReal{
virtual inline ~FastTemplateFunc_t(){}

void setProxyList(RooListProxy& proxyList, RooArgList& varList){
TIterator* varIter = varList.createIterator();
RooAbsArg* var;
while ((var = (RooAbsArg*)varIter->Next())) {
for (RooAbsArg *var : varList) {
if (!dynamic_cast<RooAbsReal*>(var)) {
assert(0);
}
proxyList.add(*var);
}
delete varIter;
}

virtual TObject* clone(const char* newname) const = 0;
Expand Down
1 change: 0 additions & 1 deletion interface/HZZ4L_RooSpinZeroPdf_1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {} ;
Expand Down
1 change: 0 additions & 1 deletion interface/ProcessNormalization.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef HiggsAnalysis_CombinedLimit_ProcessNormalization_h
#define HiggsAnalysis_CombinedLimit_ProcessNormalization_h

#include <TIterator.h>
#include <RooAbsReal.h>
#include "RooListProxy.h"

Expand Down
1 change: 0 additions & 1 deletion interface/RooMultiPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "RooConstVar.h"


#include "TIterator.h"
#include "RooListProxy.h"

#include <iostream>
Expand Down
2 changes: 0 additions & 2 deletions interface/RooRealFlooredSumPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class RooRealFlooredSumPdf : public RooAbsPdf {

RooListProxy _funcList; // List of component FUNCs
RooListProxy _coefList; // List of coefficients
TIterator* _funcIter; //! Iterator over FUNC list
TIterator* _coefIter; //! Iterator over coefficient list
Bool_t _extended; // Allow use as extended p.d.f.
Bool_t _doFloor;
Double_t _floorVal;
Expand Down
1 change: 0 additions & 1 deletion interface/SimpleCacheSentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "RooRealVar.h"
#include "RooSetProxy.h"
#include "TIterator.h"

class SimpleCacheSentry : public RooAbsArg {
public:
Expand Down
4 changes: 0 additions & 4 deletions interface/VerticalInterpHistPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class VerticalInterpHistPdf : public RooAbsPdf {
RooListProxy _coefList ; // List of coefficients
Double_t _smoothRegion;
Int_t _smoothAlgo;
TIterator* _funcIter ; //! Iterator over FUNC list
TIterator* _coefIter ; //! Iterator over coefficient list

// TH1 containing the histogram of this pdf
mutable SimpleCacheSentry _sentry; // !not to be serialized
Expand Down Expand Up @@ -93,8 +91,6 @@ class FastVerticalInterpHistPdfBase : public RooAbsPdf {
RooListProxy _coefList ; // List of coefficients
Double_t _smoothRegion;
Int_t _smoothAlgo;
TIterator* _funcIter ; //! Iterator over FUNC list
TIterator* _coefIter ; //! Iterator over coefficient list

// TH1 containing the histogram of this pdf
mutable bool _init; //! not to be serialized
Expand Down
2 changes: 0 additions & 2 deletions interface/VerticalInterpPdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 8 additions & 14 deletions src/AsimovUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <memory>
#include <stdexcept>
#include <TIterator.h>
#include <RooAbsData.h>
#include <RooArgSet.h>
#include <RooProdPdf.h>
Expand All @@ -21,8 +20,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<TIterator> 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<RooArgSet>{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__);
}
Expand All @@ -45,8 +43,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD
} else {
// Do we have free parameters anyway that need fitting?
std::unique_ptr<RooArgSet> params(mc->GetPdf()->getParameters(realdata));
std::unique_ptr<TIterator> iter(params->createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : *params) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if ( rrv != 0 && rrv->isConstant() == false ) { needsFit &= true; break; }
}
Expand All @@ -67,8 +64,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<TIterator> iter(mc->GetPdf()->getParameters(realdata)->createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{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__);
}
Expand All @@ -92,8 +88,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD
std::unique_ptr<RooAbsPdf> nuispdf(utils::makeNuisancePdf(*mc));
RooProdPdf *prod = dynamic_cast<RooProdPdf *>(nuispdf.get());
if (prod == 0) throw std::runtime_error("AsimovUtils: the nuisance pdf is not a RooProdPdf!");
std::unique_ptr<TIterator> iter(prod->pdfList().createIterator());
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
for (RooAbsArg *a : prod->pdfList()) {
RooAbsPdf *cterm = dynamic_cast<RooAbsPdf *>(a);
if (!cterm) throw std::logic_error("AsimovUtils: a factor of the nuisance pdf is not a Pdf!");
if (!cterm->dependsOn(nuis)) continue; // dummy constraints
Expand All @@ -109,8 +104,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD
if (cpars->getSize() == 1) {
match = dynamic_cast<RooAbsReal *>(cpars->first());
} else {
std::unique_ptr<TIterator> iter2(cpars->createIterator());
for (RooAbsArg *a2 = (RooAbsArg *) iter2->Next(); a2 != 0; a2 = (RooAbsArg *) iter2->Next()) {
for (RooAbsArg *a2 : *cpars) {
RooRealVar *rrv2 = dynamic_cast<RooRealVar *>(a2);
if (rrv2 != 0 && !rrv2->isConstant()) {
if (match != 0) throw std::runtime_error(Form("AsimovUtils: constraint term %s has multiple floating params", cterm->GetName()));
Expand Down Expand Up @@ -138,10 +132,10 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD
// we want to set the global obs to a value for which the current value
// of the nuisance is the best fit one.
// best fit x = (k-1)*theta ----> k = x/theta + 1
RooArgList leaves; cterm->leafNodeServerList(&leaves);
std::unique_ptr<TIterator> iter2(leaves.createIterator());
RooArgList leaves;
cterm->leafNodeServerList(&leaves);
RooAbsReal *match2 = 0;
for (RooAbsArg *a2 = (RooAbsArg *) iter2->Next(); a2 != 0; a2 = (RooAbsArg *) iter2->Next()) {
for (RooAbsArg *a2 : leaves) {
RooAbsReal *rar = dynamic_cast<RooAbsReal *>(a2);
if (rar == 0 || rar == match || rar == &rrv) continue;
if (!rar->isConstant()) throw std::runtime_error(Form("AsimovUtils: extra floating parameter %s of RooGamma %s.", rar->GetName(), cterm->GetName()));
Expand Down
38 changes: 9 additions & 29 deletions src/AsymQuad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand All @@ -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<RooAbsReal*>(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<RooAbsReal*>(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):
Expand All @@ -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<RooAbsReal&>(_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());
}

Expand Down
6 changes: 2 additions & 4 deletions src/AsymptoticLimits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TIterator> 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; }
}

Expand Down Expand Up @@ -164,8 +163,7 @@ bool AsymptoticLimits::runLimit(RooWorkspace *w, RooStats::ModelConfig *mc_s, Ro
if (params_.get() == 0) params_.reset(mc_s->GetPdf()->getParameters(data));

hasFloatParams_ = false;
std::unique_ptr<TIterator> itparam(params_->createIterator());
for (RooAbsArg *a = (RooAbsArg *) itparam->Next(); a != 0; a = (RooAbsArg *) itparam->Next()) {
for (RooAbsArg *a : *params_) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if ( rrv != 0 && rrv != r && rrv->isConstant() == false ) { hasFloatParams_ = true; break; }
}
Expand Down
Loading

0 comments on commit 8e065b2

Please sign in to comment.