I'm trying to use the sum of TF1 to do a fit with a piecewise function on ROOT Cern. Here is the important part of the code.
TCanvas *cvi = new TCanvas("V(i)","V(i)",200,10,600,400);
TGraphErrors *gvi = new TGraphErrors(27,i,V,si,sV);
TF1 *vi1 = new TF1("vi1","[0]*log(x*[1]+1)");
gvi->Fit(vi1,"MR+");
TF1 *vi2 = new TF1("vi2","[0]*x+[1]",0.005,0.012);
gvi->Fit(vi2,"MR+");
TF1 *vitot = new TF1("vi1+vi2","vi1+vi2");
gvi->Fit(vitot,"MR+");
The fitting with vi1 and vi2 are fine, but, as you see, vi2 has a range, therefore the fit with vtot should be the function
Nevertheless the programm does not respect the range I gave for vi2 when it does the fit vitot. That is, it does the fit vitot as if I gave no range at all.
How can I force ROOT to fit vtot taking into account the range I gave for vi2?
I cannot set a range directly on vitot because it would fit only that part of data, while I'm trying to fit all the data with different functions.
I already gave the option "R" in the fits, as you see, but that does not seem enough.
Looks like you want ROOT to assume some "default" value for the vi2
function outside of the initially provided range 0 < x < 0.05
. In your case, you want the "default" value to be 0 but, in general, I don't think ROOT should be assuming anything. Not sure if the ROOT developers used the same logic but it is unlikely that the sum of functions is implemented as you expect it. Nevertheless, it is straight forward to write a custom C-function for vitot
that would respect any range you want. Just take a look at the section "A general C function with parameters" of the TF1 documentation at https://root.cern.ch/doc/master/classTF1.html