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] Consistently do bin width correction when creating a RooHist from a TH1 #10070

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

guitargeek
Copy link
Contributor

@guitargeek guitargeek commented Mar 8, 2022

[RF] Consistently do bin width correction when making RooHist from TH1

The RooPlot constructor from TH1 had an option to disable the bin width
correction, but this argument was not even used when the RooHist was
created with Poisson errors, which is the default case. The Bin width
correction was always done in this case, no matter what was the value of
correctForBinWith.

However, when SumW2 errors are used, the correctForBinWith parameter
was actually considered! This caused inconsitent behavior, because when
plotting a RooDataHist the correctForBinWith parameter is hardcoded
to `false, meaning the bin width correction is done for Poisson errors
but not for SumW2 errors.

This commit fixes this behavior by following the precedent set by the
more common Poisson error: the correctForBinWith parameter is
consistently ignored, and an exception is thrown when it's false.

Consequently, the correctForBinWith parameter is also not hardcoded to
false in RooDataHist::plotOn anymore.

The correct way to disable the bin width correction is to enable the
interpretation as a density when importing a TH1 to a RooDataHist.

This commit fixes a bug reported on the forum.

@phsft-bot
Copy link
Collaborator

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

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/soversion.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

Build failed on mac1015/python3.
Running on macitois22.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@guitargeek guitargeek force-pushed the roodatahist_issue_1 branch from e2cfff9 to 6e636bb Compare March 8, 2022 10:26
@phsft-bot
Copy link
Collaborator

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

@@ -87,6 +87,11 @@ RooHist::RooHist(const TH1 &data, Double_t nominalBinWidth, Double_t nSigma, Roo
Bool_t correctForBinWidth, Double_t scaleFactor) :
TGraphAsymmErrors(), _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
{
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we don't support this.
I think one can have both case, and being able to create a RooHist also without any bin width correction, depending on the passed option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point was to not change code behavior. So far, the bin width correction parameter was ignored for Poisson errors, and it might surprise users if it's now considered correctly. Since we don't need Poisson errors with no bin width correction anyway, it's safer to disable that possibility than to fix it.

The RooPlot constructor from TH1 had an option to disable the bin width
correction, but this argument was not even used when the RooHist was
created with Poisson errors, which is the default case. The Bin width
correction was always done in this case, no matter what was the value of
`correctForBinWith`.

However, when SumW2 errors are used, the `correctForBinWith` parameter
was actually considered! This caused inconsitent behavior, because when
plotting a `RooDataHist` the `correctForBinWith` parameter is hardcoded
to `false, meaning the bin width correction is done for Poisson errors
but not for SumW2 errors.

This commit fixes this behavior by following the precedent set by the
more common Poisson error: the `correctForBinWith` parameter is
consistently ignored, and an exception is thrown when it's false.

Consequently, the `correctForBinWith` parameter is also not hardcoded to
`false` in `RooDataHist::plotOn` anymore.

The correct way to disable the bin width correction is to enable the
interpretation as a density when importing a TH1 to a RooDataHist.

This commit fixes a bug reported on the forum.
@guitargeek guitargeek force-pushed the roodatahist_issue_1 branch from 6e636bb to 0a9a36d Compare March 8, 2022 14:23
@phsft-bot
Copy link
Collaborator

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

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft11.dyndns.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

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

Failing tests:

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.

3 participants