# RooAddPdf negative component fraction values

Hi,

I have a RooAddPdf object which is made up of three RooGaussian objects, the fractions of gaussian1 and 2 are in the range [0-1]. The value of the third is then 1 - fraction_{gaussian1} - fraction_{gaussian2} in order for normalisation. When I try and fit this pdf to data there are cases where fraction_{gaussian1} + fraction_{gaussian} is greater than 1 such that the corresponding value of fraction_{gaussian3} is negative. This is an undesirable feature for me. My question is whether there is a flag or veto mechanism which enforces that fraction_{gaussian1} + fraction_{gaussian2} is <= 1 such that fraction_{gaussian3} >= 0.

Thanks

example code (using PyROOT)

``````from ROOT import *

x = RooRealVar('x', 'x', -10, 10)

mean1 = RooRealVar('mean1', 'mean1', 2, 0, 5)
mean2 = RooRealVar('mean2', 'mean2', -2, -5, 0)
mean3 = RooRealVar('mean3', 'mean3', 9, 5, 10)

sigma1 = RooRealVar('sigma1', 'sigma1', 1, 1, 2)
sigma2 = RooRealVar('sigma2', 'sigma2', 3, 3, 5)
sigma3 = RooRealVar('sigma3', 'sigma3', 0.5, 0.5, 1)

gaus1 = RooGaussian('gaus1', 'gaus1', x, mean1, sigma1)
gaus2 = RooGaussian('gaus2', 'gaus2', x, mean2, sigma2)
gaus3 = RooGaussian('gaus3', 'gaus3', x, mean3, sigma3)

fraction1 = RooRealVar('frac1', 'frac1', 0.5, 1)
fraction2 = RooRealVar('frac2', 'frac2', 0.49, 1)
pdf = RooAddPdf('sum', 'sum', RooArgList(gaus1, gaus2, gaus3), RooArgList(fraction1, fraction2))

ds = pdf.generate(RooArgSet(x), 10000)
frame = x.frame()
ds.plotOn(frame)
pdf.fitTo(ds)
pdf.plotOn(frame)
pdf.paramOn(frame)
frame.Draw()``````

Hi,

You are generating with too large values of f1 and f2 and then by construction f3 is negative, since f1+f2+f3=1.
Define the fraction as following

``````fraction1 = RooRealVar('frac1', 'frac1', 0.5,0,  1)
fraction2 = RooRealVar('frac2', 'frac2', 0.49,0, 1)``````

and it should work fine, although you can have some cases during the minimization where the pdf is negative, but normally the program recovers by itself and goes away from those regions

Regards

Lorenzo