# SumW2Error gives unexpected results with unweighted datasets, BatchMode

**URL:** <https://root-forum.cern.ch/t/sumw2error-gives-unexpected-results-with-unweighted-datasets-batchmode/47206>\
**Category:** Roofit and RooStats\
**Tags:** bug, roofit\
**Created:** [October 12, 2021, 4:57pm UTC](https://root-forum.cern.ch/t/sumw2error-gives-unexpected-results-with-unweighted-datasets-batchmode/47206 "2021-10-12T16:57:10Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [October 13, 2021, 4:21pm UTC](https://root-forum.cern.ch/t/sumw2error-gives-unexpected-results-with-unweighted-datasets-batchmode/47206/5 "2021-10-13T16:21:19Z")

</div>

Hi, @moneta,

I am surprised to hear you don’t observe a large difference in a binned fit using `SumW2Errors` and `BatchMode`. Here is a more concise reproducer:

```python
import ROOT as r

ws = r.RooWorkspace("workspace")
x = ws.factory("x[-10, 10]")
sig = ws.factory("Gaussian::sig(x, mu[-1, 1], s[0.1, 5])")
bkg = ws.factory("Chebychev::bkg(x, {c1[0.1, -1, 1]})")
shp = ws.factory("SUM::shp(Nsig[0, 200] * sig, Nbkg[0, 200] * bkg)")
data = shp.generate(r.RooArgSet(x))
datahist = r.RooDataHist("datahist", "datahist", data.get(), data)
print("with BatchMode:")
resWith = shp.fitTo(
    datahist,
    r.RooFit.Extended(),
    r.RooFit.Save(),
    r.RooFit.SumW2Error(True),
    r.RooFit.Strategy(1),
    r.RooFit.BatchMode(True),
)
print("without BatchMode:")
resWithout = shp.fitTo(
    datahist,
    r.RooFit.Extended(),
    r.RooFit.Save(),
    r.RooFit.SumW2Error(True),
    r.RooFit.Strategy(1),
    r.RooFit.BatchMode(False),
)
resWith.Print()
resWithout.Print()

```

With `BatchMode`:

```auto
  RooFitResult: minimized FCN value: 1171.58, estimated distance to minimum: 267.825
                covariance matrix quality: Full, accurate covariance matrix
                Status : MINIMIZE=0 HESSE=0 HESSE=0 

    Floating Parameter FinalValue +/- Error   
  -------------------- --------------------------
                  Nbkg 5.4048e+01 +/- 6.78e+01
                  Nsig 1.4599e+02 +/- 7.73e+01
                    c1 2.0586e-01 +/- 5.90e-01
                    mu 4.6270e-01 +/- 1.06e+00
                     s 3.1733e+00 +/- 1.40e+00

```

Without `BatchMode`:

```auto
  RooFitResult: minimized FCN value: -303.384, estimated distance to minimum: 2.03636e-05
                covariance matrix quality: Full, accurate covariance matrix
                Status : MINIMIZE=0 HESSE=0 HESSE=0 

    Floating Parameter FinalValue +/- Error   
  -------------------- --------------------------
                  Nbkg 5.4053e+01 +/- 2.23e+01
                  Nsig 1.4595e+02 +/- 2.43e+01
                    c1 2.0472e-01 +/- 3.44e-01
                    mu 4.6150e-01 +/- 4.05e-01
                     s 3.1738e+00 +/- 4.88e-01

```

The central values are quite similar, but the errors are very different (more than a factor of 2 greater with `BatchMode` than without). Is this not the output you get with this reproducer?

---

_[View the full topic](https://root-forum.cern.ch/t/sumw2error-gives-unexpected-results-with-unweighted-datasets-batchmode/47206)._
