Skip to content

[RF] Fix weights in SumW2Error() fits to RooDataHist with batch mode#9161

Merged
guitargeek merged 3 commits intoroot-project:masterfrom
guitargeek:issue-9118
Oct 22, 2021
Merged

[RF] Fix weights in SumW2Error() fits to RooDataHist with batch mode#9161
guitargeek merged 3 commits intoroot-project:masterfrom
guitargeek:issue-9118

Conversation

@guitargeek
Copy link
Copy Markdown
Contributor

If the SumW2Error correction is requested on fits with the batch mode,
the weights of each entry are currently determined to be the square of
the original weight for each entry.

In the binned fit case, this is wrong. One should not square the entry
weight (or more precisely bin weight in the binned case), but take the
sum of squares of event weights when they were added to the histrogram.
The RooDataHist class keeps track of these sum of squared weights, and
this commit changes the code in RooNLLVar and the RooFit dataset
classes such that these sums of squared weights are used in the batch
mode fits.

This fixes issue #9118.

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@guitargeek guitargeek linked an issue Oct 21, 2021 that may be closed by this pull request
Copy link
Copy Markdown
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just a comment on the new FItResult function

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

If one compares RooFitResults that were produced with external
covariance matrices (e.g. from fits with the `SumW2Error()` option),
there will be segfaults in the covariance matrix comparison part of
`RooFitResult::isIdentical`.

Since it's often not important to compare the covariance matrices, a new
function `RooFitResult::isIdenticalNoCov` is introduced to compare only
the parameters and their uncertainties. The uncertainties are inferred
from the covariance matrix after all, so if there is something wrong
with the covariance matrix one will still catch it indirectly via the
parameter uncertainties.
If the `SumW2Error` correction is requested on fits with the batch mode,
the weights of each entry are currently determined to be the square of
the original weight for each entry.

In the binned fit case, this is wrong. One should not square the entry
weight (or more precisely bin weight in the binned case), but take the
sum of squares of event weights when they were added to the histrogram.
The RooDataHist class keeps track of these sum of squared weights, and
this commit changes the code in `RooNLLVar` and the RooFit dataset
classes such that these sums of squared weights are used in the batch
mode fits.

This fixes issue root-project#9118.
This unit test was based on the code that was used to reproduce GitHub
issue root-project#9118.
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@guitargeek
Copy link
Copy Markdown
Contributor Author

Fixed the documentation of RooFitResult::isIdenticalNoCov (it explained a parameter before that didn't exist in the function signature).

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

const RooArgList& randomizePars() const;

Bool_t isIdentical(const RooFitResult& other, Double_t tol=1e-6, Double_t tolCorr=1e-4, Bool_t verbose=kTRUE) const ;
bool isIdenticalNoCov(const RooFitResult& other, double tol=1e-6, bool verbose=true) const ;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if adding this function in FitResult is really needed there. It could be maybe added in some utility class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you would put this into RooHelpers.h? In my opinion, it is justified here to have isIdenticalNoCov as a class member, because isIdentical is also a class member and isIdentical uses isIdenticalNoCov because it's the first part of the check. Like this, both the parameter and the covariance matrix checking code are in RooFitResult.cxx. If isIdenticalNoCov would be in RooHelpers, the parameter and covariance matrix checking code would be in two different files, causing further complications: they both use a isIdenticalErrMsg helper function, and if the code is not in the same source file anymore I can't put this helper function in the anonymous namespace anymore.

@guitargeek guitargeek merged commit 25c791e into root-project:master Oct 22, 2021
@guitargeek guitargeek deleted the issue-9118 branch October 22, 2021 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RF] Problem running weighted binned fit in batch mode

3 participants