Skip to content

Commit

Permalink
[RF] Deprecate RooDataSet constructors other than universal constructor
Browse files Browse the repository at this point in the history
The `RooDataSet` constructors to construct a dataset from a part of an
existing dataset are deprecated and will be removed in ROOT 6.38. This
is to avoid interface duplication. One should use `RooAbsData::reduce()`
instead, or to change the weight column, the universal constructor with
the `Import()`, `Cut()`, and `WeightVar()` arguments.

The tutorials and tests were adjusted accordingly.

Also, fix a wrong comment in the `rf403` tutorials: they said that the
existing dataset is changed to interpret a different column as the
weight, but actually a new dataset was created. The comment is fixed in
this commit.
  • Loading branch information
guitargeek committed Dec 3, 2024
1 parent dee39b4 commit cc99d62
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions README/ReleaseNotes/v636/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following people have contributed to this new version:

* The RooFit legacy interfaces that were deprecated in ROOT 6.34 and scheduled for removal in ROOT 6.36 are removed. See the RooFit section in the 6.34 release notes for a full list.
* The `TPython::Eval()` function that was deprecated in ROOT 6.34 and scheduled for removal in ROOT 6.36 is removed.
* The `RooDataSet` constructors to construct a dataset from a part of an existing dataset are deprecated and will be removed in ROOT 6.38. This is to avoid interface duplication. Please use `RooAbsData::reduce()` instead, or if you need to change the weight column, use the universal constructor with the `Import()`, `Cut()`, and `WeightVar()` arguments.

## Python Interface

Expand Down
8 changes: 8 additions & 0 deletions core/foundation/inc/ROOT/RConfig.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@
# define _R__DEPRECATED_636(REASON) _R_DEPRECATED_REMOVE_NOW(REASON)
#endif

/* USE AS `R__DEPRECATED(6,38, "Not threadsafe; use TFoo::Bar().")`
To be removed by 6.38 */
#if ROOT_VERSION_CODE <= ROOT_VERSION(6,37,0)
# define _R__DEPRECATED_638(REASON) _R__DEPRECATED_LATER(REASON)
#else
# define _R__DEPRECATED_638(REASON) _R_DEPRECATED_REMOVE_NOW(REASON)
#endif

/* USE AS `R__DEPRECATED(7,00, "Not threadsafe; use TFoo::Bar().")`
To be removed by 7.00 */
#if ROOT_VERSION_CODE < ROOT_VERSION(6,99,0)
Expand Down
9 changes: 6 additions & 3 deletions roofit/roofitcore/inc/RooDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class TDirectory;
#include "RooAbsData.h"
#include "RooDirItem.h"

#include <string_view>
#include <ROOT/RConfig.hxx> // for R__DEPRECATED

#include <list>
#include <string_view>

class RooDataSet : public RooAbsData, public RooDirItem {
public:
Expand All @@ -43,9 +44,11 @@ class RooDataSet : public RooAbsData, public RooDirItem {

// Constructor for subset of existing dataset
RooDataSet(RooStringView name, RooStringView title, RooDataSet *data, const RooArgSet& vars,
const char *cuts=nullptr, const char* wgtVarName=nullptr);
const char *cuts=nullptr, const char* wgtVarName=nullptr)
R__DEPRECATED(6,38, "Use RooAbsData::reduce(), or if you need to change the weight column, the universal constructor with the Import(), Cut(), and WeightVar() arguments.");
RooDataSet(RooStringView name, RooStringView title, RooDataSet *data, const RooArgSet& vars,
const RooFormulaVar& cutVar, const char* wgtVarName=nullptr) ;
const RooFormulaVar& cutVar, const char* wgtVarName=nullptr)
R__DEPRECATED(6,38, "Use RooAbsData::reduce(), or if you need to change the weight column, the universal constructor with the Import(), Cut(), and WeightVar() arguments.");

RooDataSet(RooDataSet const & other, const char* newname=nullptr) ;
TObject* Clone(const char* newname = "") const override {
Expand Down
5 changes: 2 additions & 3 deletions roofit/roofitcore/test/stressRooFit_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2530,11 +2530,10 @@ class TestBasic403 : public RooUnitTest {
RooFormulaVar wFunc("w", "event weight", "(x*x+10)", x);

// Add column with variable w to previously generated dataset
RooRealVar *w = (RooRealVar *)data->addColumn(wFunc);
data->addColumn(wFunc);

// Instruct dataset d in interpret w as event weight rather than as observable
RooDataSet dataw(data->GetName(), data->GetTitle(), data.get(), *data->get(), nullptr, w->GetName());
// data->setWeightVar(*w) ;
RooDataSet dataw{data->GetName(), data->GetTitle(), *data->get(), Import(*data), WeightVar("w")};

// U n b i n n e d M L f i t t o w e i g h t e d d a t a
// ---------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions roofit/roofitcore/test/testSumW2Error.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ TEST(SumW2Error, ExtendedFit)
auto *w = dataNoWeights->addColumn(*wFunc);
RooDataSet data{dataNoWeights->GetName(),
dataNoWeights->GetTitle(),
dataNoWeights.get(),
*dataNoWeights->get(),
"",
w->GetName()};
RooFit::Import(*dataNoWeights),
RooFit::WeightVar(w->GetName())};
RooDataHist datahist{"datahist", "datahist", *data.get(), data};

RooArgSet params;
Expand Down
9 changes: 5 additions & 4 deletions tutorials/roofit/rf403_weightedevts.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
#include "TAxis.h"
#include "RooPlot.h"
#include "RooFitResult.h"
using namespace RooFit;

void rf403_weightedevts()
{
using namespace RooFit;

// C r e a t e o b s e r v a b l e a n d u n w e i g h t e d d a t a s e t
// -------------------------------------------------------------------------------

Expand All @@ -46,13 +47,13 @@ void rf403_weightedevts()
RooFormulaVar wFunc("w", "event weight", "(x*x+10)", x);

// Add column with variable w to previously generated dataset
RooRealVar *w = (RooRealVar *)data->addColumn(wFunc);
data->addColumn(wFunc);

// Dataset d is now a dataset with two observable (x,w) with 1000 entries
data->Print();

// Instruct dataset wdata in interpret w as event weight rather than as observable
RooDataSet wdata(data->GetName(), data->GetTitle(), data.get(), *data->get(), 0, w->GetName());
// Create a new dataset wdata where w is interpreted as event weight rather than as observable
RooDataSet wdata(data->GetName(), data->GetTitle(), *data->get(), Import(*data), WeightVar("w"));

// Dataset d is now a dataset with one observable (x) with 1000 entries and a sum of weights of ~430K
wdata.Print();
Expand Down
14 changes: 7 additions & 7 deletions tutorials/roofit/rf403_weightedevts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
p0 = ROOT.RooPolynomial("px", "px", x)

# Sample 1000 events from pdf
data = p0.generate({x}, 1000)
data = p0.generate(x, 1000)

# Calculate weight and make dataset weighted
# --------------------------------------------------
Expand All @@ -35,14 +35,14 @@
wFunc = ROOT.RooFormulaVar("w", "event weight", "(x*x+10)", [x])

# Add column with variable w to previously generated dataset
w = data.addColumn(wFunc)
data.addColumn(wFunc)

# Dataset d is now a dataset with two observable (x,w) with 1000 entries
data.Print()

# Instruct dataset wdata in interpret w as event weight rather than as
# observable
wdata = ROOT.RooDataSet(data.GetName(), data.GetTitle(), data, data.get(), "", w.GetName())
# Create a new dataset wdata where w is interpreted as event weight rather than
# as observable
wdata = ROOT.RooDataSet(data.GetName(), data.GetTitle(), data.get(), Import=data, WeightVar="w")

# Dataset d is now a dataset with one observable (x) with 1000 entries and
# a sum of weights of ~430K
Expand Down Expand Up @@ -100,10 +100,10 @@
genPdf = ROOT.RooGenericPdf("genPdf", "x*x+10", [x])

# Sample a dataset with the same number of events as data
data2 = genPdf.generate({x}, 1000)
data2 = genPdf.generate(x, 1000)

# Sample a dataset with the same number of weights as data
data3 = genPdf.generate({x}, 43000)
data3 = genPdf.generate(x, 43000)

# Fit the 2nd order polynomial to both unweighted datasets and save the
# results for comparison
Expand Down

0 comments on commit cc99d62

Please sign in to comment.