# Weighted MC and constraint

**URL:** <https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340>\
**Category:** Roofit and RooStats\
**Created:** [October 21, 2025, 8:23am UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340 "2025-10-21T08:23:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![de\_Vivie](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@de\_Vivie](https://root-forum.cern.ch/u/de_Vivie)\
**Post date:** [October 21, 2025, 8:23am UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/1 "2025-10-21T08:23:42Z")

</div>

Hello.

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

root.exe miniFsupersimple.C

within root 6.36.04.

What am I doing wrong ?

Best,

Jean-Baptiste

[miniFsupersimple.C](https://root-forum.cern.ch/uploads/short-url/8AIlGyqHdNsa7wil6Sca81Q7Uc9.C) (4.8 KB)

[aDS.root](https://root-forum.cern.ch/uploads/short-url/trVOWcfuUilCTuJAmUJ2qYSXA7g.root) (29.5 KB)

---

<div class="post-metadata">

**Author:** ![mczurylo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mczurylo/32/33269_2.png) [@mczurylo](https://root-forum.cern.ch/u/mczurylo)\
**Post date:** [October 21, 2025, 12:19pm UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/2 "2025-10-21T12:19:58Z")

</div>

Hi @de_Vivie,

I will add @jonas into the chat so that he can give you some hints.

Cheers,

Marta

---

<div class="post-metadata">

**Author:** ![de\_Vivie](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@de\_Vivie](https://root-forum.cern.ch/u/de_Vivie)\
**Post date:** [November 4, 2025, 10:48am UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/3 "2025-11-04T10:48:53Z")

</div>

Hello.

Any hints ?

Best,

Jean-Baptiste

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 4, 2025, 11:25am UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/4 "2025-11-04T11:25:05Z")

</div>

Let’s ping @jonas again…

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 4, 2025, 12:17pm UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/5 "2025-11-04T12:17:19Z")

</div>

I tried your macro with the master version of ROOT. It gives me:

```auto
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] 

```

Is it what you also get ?

---

<div class="post-metadata">

**Author:** ![de\_Vivie](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@de\_Vivie](https://root-forum.cern.ch/u/de_Vivie)\
**Post date:** [November 4, 2025, 12:38pm UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/6 "2025-11-04T12:38:39Z")

</div>

Thank you for having a look.

Yes, this is what I get.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [November 18, 2025, 12:39pm UTC](https://root-forum.cern.ch/t/weighted-mc-and-constraint/64340/7 "2025-11-18T12:39:22Z")

</div>

Closed on November 18, 2025, 12:39pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
