root icon indicating copy to clipboard operation
root copied to clipboard

[RF] Fitting unweighted dataset with error corrections gives inconsistent result

Open guitargeek opened this issue 3 years ago • 0 comments

Describe the bug

The fit parameter uncertainties you get when using RooAbsPdf::fitTo() with the AsymptoticError() or SumW2Error() option for an unweighted dataset are not the same as without the AsymptoticError() option.

Expected behavior

For an unweighted dataset, both the SumW2Error() and AsymptoticError() options should have no effect on the fit result. This is not the case, which is alarming and probably hints to a problem in the implementation. For the AsymptoticError() option, the differences are even more striking.

To Reproduce

using namespace RooFit;
using FitResPtr = std::unique_ptr<RooFitResult>;

RooRealVar x("x", "x", 70.0, 70.0, 120.0);

RooRealVar x0("x0", "x0", 90, 70, 120.0);
RooRealVar sigma("sigma", "sigma", 5, 1, 100);
RooRealVar alphaL("alphaL", "alphaL", 1.05, 0.1, 10);
RooRealVar alphaR("alphaR", "alphaR", 1.3, 0.1, 10);
RooRealVar nL("nL", "nL", 5, 0.1, 10);
RooRealVar nR("nR", "nR", 2, 0.1, 10);


auto resetParameters = [&]() {
    x0.setVal(80.0);
    sigma.setVal(3.0);
    alphaL.setVal(1.0);
    alphaR.setVal(1.0);
    nL.setVal(3.0);
    nR.setVal(3.0);

    x0.setError(0.0);
    sigma.setError(0.0);
    alphaL.setError(0.0);
    alphaR.setError(0.0);
    nL.setError(0.0);
    nR.setError(0.0);
};


RooCrystalBall cb{"cb", "cb", x, x0, sigma, sigma, alphaL, nL, alphaR, nR};

std::size_t nEvents = 1000;

std::unique_ptr<RooDataSet> data{cb.generate(x, nEvents)};

resetParameters();
FitResPtr res0{cb.fitTo(*data, PrintLevel(-1), Save(1))};
res0->Print();

resetParameters();
FitResPtr res1{cb.fitTo(*data, PrintLevel(-1), Save(1), SumW2Error(true))};
res1->Print();

resetParameters();
FitResPtr res2{cb.fitTo(*data, PrintLevel(-1), Save(1), AsymptoticError(true))};
res2->Print();

The output will be as follows, with the current ROOT master:


No error correction:

    Floating Parameter    FinalValue +/-  Error   
  --------------------  --------------------------
                alphaL    1.7354e-01 +/-  2.47e-02
                alphaR    2.3792e-01 +/-  5.51e-02
                    nL    1.0000e+01 +/-  6.13e+00
                    nR    5.1244e+00 +/-  2.23e+00
                 sigma    1.0000e+00 +/-  1.95e-01
                    x0    9.0956e+01 +/-  2.93e-01

SumW2Error():

    Floating Parameter    FinalValue +/-  Error   
  --------------------  --------------------------
                alphaL    1.7354e-01 +/-  2.28e-02
                alphaR    2.3794e-01 +/-  5.85e-02
                    nL    1.0000e+01 +/-  1.47e-02
                    nR    5.1241e+00 +/-  2.48e+00
                 sigma    1.0000e+00 +/-  1.43e-03
                    x0    9.0957e+01 +/-  3.00e-01

Asymptotic error:

    Floating Parameter    FinalValue +/-  Error   
  --------------------  --------------------------
                alphaL    1.7354e-01 +/-  8.94e-02
                alphaR    2.3794e-01 +/-  3.91e-01
                    nL    1.0000e+01 +/-  1.10e-04
                    nR    5.1241e+00 +/-  1.72e+01
                 sigma    1.0000e+00 +/-  5.90e-03
                    x0    9.0957e+01 +/-  1.20e+00

Setup

ROOT master on Arch Linux.

Additional context

None.

guitargeek avatar Aug 04 '22 14:08 guitargeek