From 654cde120a0483034e2a8af55fa412c3b6bfe708 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Wed, 17 Apr 2024 21:25:31 +0200 Subject: [PATCH] Avoid using deprecated RooDataSet constructor The RooDataSet constructor that takes a weight variable name was deprecated in ROOT 6.32: https://github.com/root-project/root/pull/14317 The general command argument constructor should be used, which doesn't change the functionality and is also backwards compatible with older ROOT versions. Also, avoid a unused variable warning. --- src/CachingNLL.cc | 4 ++-- src/CombDataSetFactory.cc | 2 +- src/MultiDimFit.cc | 3 ++- src/TH1Keys.cc | 8 ++++---- src/ToyMCSamplerOpt.cc | 12 ++++++------ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/CachingNLL.cc b/src/CachingNLL.cc index 04f2bedf2c3..62bc86d151c 100644 --- a/src/CachingNLL.cc +++ b/src/CachingNLL.cc @@ -1169,9 +1169,9 @@ void cacheutils::CachingSimNLL::splitWithWeights(const RooAbsData &data, const R std::unique_ptr myobs(pdf->getObservables(obs)); myobs->add(weight); //std::cout << "Observables for bin " << ib << ":"; myobs->Print(""); - datasets_[ib] = new RooDataSet("", "", *myobs, "_weight_"); + datasets_[ib] = new RooDataSet("", "", *myobs, RooFit::WeightVar("_weight_")); } else { - datasets_[ib] = new RooDataSet("", "", obsplus, "_weight_"); + datasets_[ib] = new RooDataSet("", "", obsplus, RooFit::WeightVar("_weight_")); } } else { datasets_[ib]->reset(); diff --git a/src/CombDataSetFactory.cc b/src/CombDataSetFactory.cc index 040d7e1ad28..33eb392572a 100644 --- a/src/CombDataSetFactory.cc +++ b/src/CombDataSetFactory.cc @@ -17,7 +17,7 @@ void CombDataSetFactory::addSetBin(const char *label, RooDataHist *set) { void CombDataSetFactory::addSetAny(const char *label, RooDataHist *set) { if (weight_ == 0) weight_ = new RooRealVar("_weight_","",1); - RooDataSet *data = new RooDataSet(TString(set->GetName())+"_unbin", "", RooArgSet(*set->get(), *weight_), "_weight_"); + RooDataSet *data = new RooDataSet(TString(set->GetName())+"_unbin", "", {*set->get(), *weight_}, RooFit::WeightVar("_weight_")); for (int i = 0, n = set->numEntries(); i < n; ++i) { const RooArgSet *entry = set->get(i); data->add(*entry, set->weight()); diff --git a/src/MultiDimFit.cc b/src/MultiDimFit.cc index fb4f10266f4..6789d2f69fb 100644 --- a/src/MultiDimFit.cc +++ b/src/MultiDimFit.cc @@ -779,7 +779,8 @@ void MultiDimFit::doGrid(RooWorkspace *w, RooAbsReal &nll) deltaY = (pmax[1] - pmin[1]) / nY; spacingOffsetY = 0.5; } - unsigned int ipoint = 0, nprint = ceil(0.005 * nTotal); + unsigned int ipoint = 0; + //unsigned int nprint = ceil(0.005 * nTotal); // loop through the grid for (unsigned int i = 0; i < nX; ++i) { diff --git a/src/TH1Keys.cc b/src/TH1Keys.cc index aee24040f61..cab019a6df0 100644 --- a/src/TH1Keys.cc +++ b/src/TH1Keys.cc @@ -21,7 +21,7 @@ TH1Keys::TH1Keys(const char *name,const char *title,Int_t nbinsx,Double_t xlow,D x_(new RooRealVar("x", "x", min_, max_)), w_(new RooRealVar("w", "w", 1.0)), point_(*x_), - dataset_(new RooDataSet(name, title, RooArgSet(*x_, *w_), "w")), + dataset_(new RooDataSet(name, title, {*x_, *w_}, RooFit::WeightVar("w"))), underflow_(0.0), overflow_(0.0), globalScale_(1.0), options_(options), @@ -40,7 +40,7 @@ TH1Keys::TH1Keys(const char *name,const char *title,Int_t nbinsx,const Float_t x_(new RooRealVar("x", "x", min_, max_)), w_(new RooRealVar("w", "w", 1.0)), point_(*x_), - dataset_(new RooDataSet(name, title, RooArgSet(*x_, *w_), "w")), + dataset_(new RooDataSet(name, title, {*x_, *w_}, RooFit::WeightVar("w"))), underflow_(0.0), overflow_(0.0), globalScale_(1.0), options_(options), @@ -61,7 +61,7 @@ TH1Keys::TH1Keys(const char *name,const char *title,Int_t nbinsx,const Double_t x_(new RooRealVar("x", "x", min_, max_)), w_(new RooRealVar("w", "w", 1.0)), point_(*x_), - dataset_(new RooDataSet(name, title, RooArgSet(*x_, *w_), "w")), + dataset_(new RooDataSet(name, title, {*x_, *w_}, RooFit::WeightVar("w"))), underflow_(0.0), overflow_(0.0), globalScale_(1.0), options_(options), @@ -81,7 +81,7 @@ TH1Keys::TH1Keys(const TH1Keys &other) : x_(new RooRealVar("x", "x", min_, max_)), w_(new RooRealVar("w", "w", 1.0)), point_(*x_), - dataset_(new RooDataSet(other.GetName(), other.GetTitle(), RooArgSet(*x_, *w_), "w")), + dataset_(new RooDataSet(other.GetName(), other.GetTitle(), {*x_, *w_}, RooFit::WeightVar("w"))), underflow_(other.underflow_), overflow_(other.overflow_), globalScale_(other.globalScale_), options_(other.options_), diff --git a/src/ToyMCSamplerOpt.cc b/src/ToyMCSamplerOpt.cc index eb1bc0b13b7..a027c88038c 100644 --- a/src/ToyMCSamplerOpt.cc +++ b/src/ToyMCSamplerOpt.cc @@ -176,7 +176,7 @@ toymcoptutils::SinglePdfGenInfo::generatePseudoAsimov(RooRealVar *&weightVar, in std::unique_ptr data(pdf_->generate(observables_, nPoints)); if (weightVar == 0) weightVar = new RooRealVar("_weight_","",1.0); RooArgSet obsPlusW(observables_); obsPlusW.add(*weightVar); - RooDataSet *rds = new RooDataSet(data->GetName(), "", obsPlusW, weightVar->GetName()); + RooDataSet *rds = new RooDataSet(data->GetName(), "", obsPlusW, RooFit::WeightVar(weightVar->GetName())); RooAbsArg::setDirtyInhibit(true); // don't propagate dirty flags while filling histograms for (int i = 0; i < nPoints; ++i) { observables_ = *data->get(i); @@ -219,7 +219,7 @@ toymcoptutils::SinglePdfGenInfo::generateWithHisto(RooRealVar *&weightVar, bool double expectedEvents = pdf_->expectedEvents(observables_); histoSpec_->Scale(expectedEvents/ histoSpec_->Integral("width")); RooArgSet obsPlusW(obs); obsPlusW.add(*weightVar); - RooDataSet *data = new RooDataSet(TString::Format("%sData", pdf_->GetName()), "", obsPlusW, weightVar->GetName()); + RooDataSet *data = new RooDataSet(TString::Format("%sData", pdf_->GetName()), "", obsPlusW, RooFit::WeightVar(weightVar->GetName())); RooAbsArg::setDirtyInhibit(true); // don't propagate dirty flags while filling histograms switch (obs.getSize()) { case 1: @@ -377,7 +377,7 @@ toymcoptutils::SimPdfGenInfo::generate(RooRealVar *&weightVar, const RooDataSet* if (weightVar == 0) weightVar = new RooRealVar("_weight_","",1.0); RooArgSet obs(*data->get()); obs.add(*weightVar); - RooDataSet *wdata = new RooDataSet(data->GetName(), "", obs, "_weight_"); + RooDataSet *wdata = new RooDataSet(data->GetName(), "", obs, RooFit::WeightVar("_weight_")); for (int i = 0, n = data->numEntries(); i < n; ++i) { obs = *data->get(i); wdata->add(obs, data->weight()); @@ -393,7 +393,7 @@ toymcoptutils::SimPdfGenInfo::generate(RooRealVar *&weightVar, const RooDataSet* //// slower but safer solution RooArgSet vars(observables_), varsPlusWeight(observables_); if (weightVar) varsPlusWeight.add(*weightVar); - ret = new RooDataSet(retName, "", varsPlusWeight, (weightVar ? weightVar->GetName() : 0)); + ret = new RooDataSet(retName, "", varsPlusWeight, RooFit::WeightVar(weightVar ? weightVar->GetName() : 0)); RooAbsArg::setDirtyInhibit(true); // don't propagate dirty flags while filling histograms for (std::map::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) { cat_->setLabel(it->first.c_str()); @@ -429,7 +429,7 @@ toymcoptutils::SimPdfGenInfo::generateAsimov(RooRealVar *&weightVar, int verbose } if (copyData_) { RooArgSet vars(observables_), varsPlusWeight(observables_); varsPlusWeight.add(*weightVar); - ret = new RooDataSet(retName, "", varsPlusWeight, (weightVar ? weightVar->GetName() : 0)); + ret = new RooDataSet(retName, "", varsPlusWeight, RooFit::WeightVar(weightVar ? weightVar->GetName() : 0)); RooAbsArg::setDirtyInhibit(true); // don't propagate dirty flags while filling histograms for (std::map::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) { cat_->setLabel(it->first.c_str()); @@ -467,7 +467,7 @@ toymcoptutils::SimPdfGenInfo::generateEpsilon(RooRealVar *&weightVar) } if (copyData_) { RooArgSet vars(observables_), varsPlusWeight(observables_); varsPlusWeight.add(*weightVar); - ret = new RooDataSet(retName, "", varsPlusWeight, (weightVar ? weightVar->GetName() : 0)); + ret = new RooDataSet(retName, "", varsPlusWeight, RooFit::WeightVar(weightVar ? weightVar->GetName() : 0)); for (std::map::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) { cat_->setLabel(it->first.c_str()); for (unsigned int i = 0, n = it->second->numEntries(); i < n; ++i) {