# Handling square root function

How do you fit function f(x) = sqrt(x - x0)? How can you handle values x < x0? (In my example x0 = -4)
The simplest solution I found is to just exclude problematic region in the beggining like `x = RooRealVar("x", "x", x0, 5)`. But what should you do if you want to plot (or fit) also the x < x0 part?

I tried using `x.setRange("window", x0, 5)`, which works when plotting, but it doesn’t work for fitting. I noticed an info message which says that besides the “window” range also the default range is used as specified when defining `x = RooRealVar("x", "x", -5, 5)`.
`[INFO]:Eval -- RooRealVar::setRange(x) new range named 'NormalizationRangeForsignal' created with bounds [-5,5]`
But this includes also x < x0 and it gives errors.

The only solution I found is to clip the function as in this topic here Set PDF normalization range in RooFit:

At first I used clipping method like this:
`bkg_sqrt = RooGenericPdf("bkg_sqrt", "bkg_sqrt", "(x >= x0)*sqrt(x - x0)", RooArgList(x, x0))`
which still produced weird plot for x < x0.

Almost solution
But then I figured it out that clipping method should be done already on the argument of the square root function:

`bkg_sqrt_arg = RooGenericPdf("bkg_sqrt_arg", "argument for sqrt", "(x >= x0)*(x - x0)", RooArgList(x, x0))`
`bkg_sqrt = RooGenericPdf("bkg_sqrt", "bkg_sqrt", "sqrt(bkg_sqrt_arg)", RooArgList(bkg_sqrt_arg))`

This solution works fine for plotting, but the fit is still not working ok.

I appended a working example in python together with the data. I am using ROOT v6.24.06 in Windows 10
5.4_sqrt_example.py (4.4 KB)
data_gaus_sqrt.root (3.9 KB)

Hi @AndrejL ,
sorry for the late reply, it looks like we missed this!
Let’s ping @moneta and @jonas , they should be able to help.

Cheers,
Enrico

Hi,

If you have a fit model function `f(x) = sqrt(x-x0)` you need to use a range where x is larger than x0. Otherwise, as you propose, you can use a solution as above to extend the function to values x <x0, by defining to be 0.
But if your pdf is 0 in that range you should not have data there. If you have it, then there is a problem in your model, you should probably use a slightly different function that is not zero in that range.

Best regards

Lorenzo

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