# Background normalisation when doing a prefit in a limited range

**URL:** <https://root-forum.cern.ch/t/background-normalisation-when-doing-a-prefit-in-a-limited-range/64314>\
**Category:** Roofit and RooStats\
**Created:** [October 14, 2025, 12:30pm UTC](https://root-forum.cern.ch/t/background-normalisation-when-doing-a-prefit-in-a-limited-range/64314 "2025-10-14T12:30:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiorgioAlbertoLucia](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/giorgioalbertolucia/32/39461_2.png) [@GiorgioAlbertoLucia](https://root-forum.cern.ch/u/GiorgioAlbertoLucia)\
**Post date:** [October 14, 2025, 12:30pm UTC](https://root-forum.cern.ch/t/background-normalisation-when-doing-a-prefit-in-a-limited-range/64314/1 "2025-10-14T12:30:38Z")

</div>

Dear experts,

I am trying to fit my data in RooFit with a pdf that describes both a signal and a background component. Both components are modelled as RooHistPdf from a MC. The strategy for the fit is to prefit the background in a region away from the signal, then fix the background normalisation and extend the fit to the whole region, extracting the signal normalisation.

I am struggling with the background normalisation: after the prefit, I get the normalisation value and extend it to the full range. Here is the code I use for this step.

```auto
def prefit_background(self, h_data:TH1F,range_limits:tuple=None, range_name:str=None, use_chi2_method:bool=True, save_normalisation_value=True):

xvar = self._roo_workspace.obj(self._xvar_name)
old_limits = (xvar.getMin(), xvar.getMax())
range_limits = range_limits if range_limits is not None else old_limits

if range_limits is not None:
  xvar.setRange(range_limits[0], range_limits[1])
if range_name is not None and range_limits is not None:
  xvar.setRange(range_name, range_limits[0], range_limits[1])

fit_options = [RooFit.Save(), RooFit.Extended(True)]
if range_name is not None:
  fit_options.append(RooFit.Range(range_name))

for signal_name in self._signal_pdfs.keys():
  if signal_name in self.fractions.keys():
    self.fractions[signal_name].setVal(0)
    self.fractions[signal_name].setConstant(True)

datahist = RooDataHist(h_data.GetName()+'_datahist', h_data.GetName()+'_datahist', [xvar], Import=h_data)

```

```auto
if use_chi2_method:
  self._model_pdf.chi2FitTo(datahist, *fit_options)
else:
  self._model_pdf.fitTo(datahist, *fit_options)

frame = xvar.frame()
self.plot_model(frame, datahist, 'prefit_bkg')
xvar.setRange('full', old_limits[0], old_limits[1])
xvar.setRange('prefit', range_limits[0], range_limits[1])

for bkg_name in self._bkg_pdfs.keys():
  if bkg_name in self.fractions.keys():
    bkg_pdf = self._bkg_pdfs[bkg_name]
    I_full = bkg_pdf.createIntegral([xvar], Range='full').getVal()
    I_side = bkg_pdf.createIntegral([xvar], Range='prefit').getVal()
    bkg_full_correction = (I_full / I_side)
    norm = self.fractions[bkg_name].getVal()
    self.fractions[bkg_name].setVal(norm * bkg_full_correction)
    self.fractions[bkg_name].setConstant(True)

for signal_name in self._signal_pdfs.keys():
  if signal_name in self.fractions.keys():
    self.fractions[signal_name].setConstant(False)

xvar.setRange(old_limits[0], old_limits[1])
del datahist

```

However, even though the normalisation value for the background is fixed, the values of the background contribution in the prefit and in the full fit are significantly different, as reported in the screenshots. Am I missing something?

 ![Screenshot 2025-10-14 at 14.23.49](https://root-forum.cern.ch/uploads/default/original/3X/8/2/8231e7593454beec5ca5d70b4b422d4f8a21ac36.png)

 ![Screenshot 2025-10-14 at 14.24.02](https://root-forum.cern.ch/uploads/default/original/3X/4/9/49a6f8d275dc20dc8b31845486598d3d09af53b4.png)

I leave attached the relevant code. (edit: apparently, as a new user, I am not allowed to upload code)

Thanks in advance,  
Giorgio Alberto

---

<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:** [October 14, 2025, 12:34pm UTC](https://root-forum.cern.ch/t/background-normalisation-when-doing-a-prefit-in-a-limited-range/64314/2 "2025-10-14T12:34:24Z")

</div>

Welcome to the ROOT Forum!  
I’m sure @jonas can help

---

<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:** [October 28, 2025, 12:35pm UTC](https://root-forum.cern.ch/t/background-normalisation-when-doing-a-prefit-in-a-limited-range/64314/3 "2025-10-28T12:35:16Z")

</div>

Closed on October 28, 2025, 12:35pm UTC

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