Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RF] Improve sum-of-weight-squares handling with RooDataSet and bugfix for asymptotic error correction #11282

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooAbsPdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ int RooAbsPdf::calcAsymptoticCorrectedCovariance(RooMinimizer &minimizer, RooAbs
double prob = getVal(&obs);
for (int k = 0; k < floated.getSize(); k++) {
for (int l = 0; l < floated.getSize(); l++) {
num(k, l) += data.weight() * data.weight() * diffs[k] * diffs[l] / (prob * prob);
num(k, l) += data.weightSquared() * diffs[k] * diffs[l] / (prob * prob);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions roofit/roofitcore/src/RooDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -934,11 +934,17 @@ double RooDataSet::weight() const


////////////////////////////////////////////////////////////////////////////////
/// Return squared event weight of current event
/// Return squared event weight of the current event. If this RooDataSet has no
/// weight errors set, this will be the same as `weight() * weight()`, like
/// expected for an unbinned dataset. When weight errors are set, it is assumed
/// that the RooDataSet represents a weighted binned dataset and
/// weightSquared() is the corresponding sum of weight squares for the bin.

double RooDataSet::weightSquared() const
{
return store()->weight()*store()->weight() ;
const double w = store()->weight();
const double e = weightError();
return e > 0.0 ? e * e : w * w;
}


Expand Down Expand Up @@ -966,9 +972,8 @@ RooSpan<const double> RooDataSet::getWeightBatch(std::size_t first, std::size_t
_sumW2Buffer->reserve(nEntries);

for (std::size_t i = 0; i < nEntries; ++i) {
// Unlike in the RooDataHist case, the sum of weights squared for each
// entry is simply the square of the weight.
_sumW2Buffer->push_back(allWeights[i] * allWeights[i]);
get(i);
_sumW2Buffer->push_back(weightSquared());
}
}

Expand Down