Skip to content

Commit

Permalink
Avoid using deprecated RooDataSet constructor
Browse files Browse the repository at this point in the history
The RooDataSet constructor that takes a weight variable name was
deprecated in ROOT 6.32:
root-project/root#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.
  • Loading branch information
guitargeek committed Apr 17, 2024
1 parent 81e8c76 commit b0724c0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/CachingNLL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,9 @@ void cacheutils::CachingSimNLL::splitWithWeights(const RooAbsData &data, const R
std::unique_ptr<RooArgSet> 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();
Expand Down
2 changes: 1 addition & 1 deletion src/CombDataSetFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/MultiDimFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/TH1Keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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_),
Expand Down
12 changes: 6 additions & 6 deletions src/ToyMCSamplerOpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ toymcoptutils::SinglePdfGenInfo::generatePseudoAsimov(RooRealVar *&weightVar, in
std::unique_ptr<RooDataSet> 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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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());
Expand All @@ -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<std::string,RooAbsData*>::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) {
cat_->setLabel(it->first.c_str());
Expand Down Expand Up @@ -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<std::string,RooAbsData*>::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) {
cat_->setLabel(it->first.c_str());
Expand Down Expand Up @@ -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<std::string,RooAbsData*>::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) {
Expand Down

0 comments on commit b0724c0

Please sign in to comment.