I would like to do a simple fit of an exponential pdf to a distribution obtained from simulation with weighted events. Sometimes, I might want to constrain a bit the slope of the exponential with an external constraint. Without the constraint, the fit is working smoothly, whatever option I used for SumW2Error. In the constrained fit, if I do not try to use the MC statistical power (i.e. SumW2Error = false), then it seems to be fine. But if I try to use SumW2Error, the fit with the constraint does not seem to do what I expect : the uncertainty on the slope is larger than the smaller between the uncertainty without the constraint and the uncertainty built in the constraint, and the fitted slope is not where I expected it to be.
I attached a simple macro and a dataset to reproduce what I see. I am just doing
I tried your macro with the master version of ROOT. It gives me:
root [0]
Processing miniFsupersimple.C...
RooDataSet::AllRunsHM2[myy,weight:wei] = 2407 entries (13.5455 weighted)
sumw = 13.5455 +/- 0.410193 nEq = 1090.47 naive rescaling factor for the error to go from as data to as MC 0.111453
*********************************************
Fit as if MC power
Unconstrained fit, the fit parameter is n in slope = fixedSlope x (1 + s x n), s = 0.1 fixedSlope = -0.0272727
fitted nuisance = -2.04435 +/- 0.724166
Corresponding slope = -0.0216972 +/- 0.001975
Adding a measurement -0.0272727 +/- 0.00272727, expect a combined measurement of slope = -0.0236153 +/- 0.00159961
Constrained fit
fitted nuisance = -0.0455269 +/- 0.977848
Corresponding slope = -0.0271486 +/- 0.00266686
*********************************************
Fit as if Data stat
Unconstrained fit, the fit parameter is n in slope = fixedSlope x (1 + s x n), s = 0.1 fixedSlope = -0.0272727
fitted nuisance = -2.04435 +/- 6.49752
Corresponding slope = -0.0216972 +/- 0.0177205
Adding a measurement -0.0272727 +/- 0.00272727, expect a combined measurement of slope = -0.0271437 +/- 0.00269554
Constrained fit
fitted nuisance = -0.0455269 +/- 0.988792
Corresponding slope = -0.0271486 +/- 0.00269671
root [1]