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)