Integral of a graph

Hello, I need the integral of a tgrpah. Then I fitted the graph to calculate the integral in this way:

TF1 *g1    = new TF1("g1","[0]*exp(-0.5*((x-[1])/([2]+[3]*exp(-(x-[1])/[1])))^2)",x1,x2);
graph1->Fit(g1, "R");
Integral=g1->Integral(x1, x2);

I get, for example, this plot

I also want the error of the integral, I searched on Google and I found this example ROOT: tutorials/fit/ErrorIntegral.C File Reference and I followed it, but using R option instead of S option in the fit, but I got this error:

error.txt (6.0 KB)

then I tried using the S option for the fit (as in the example), instead of the R. Using the S option I don’t get error, but I get this plot

As you can see, the fit is worse (in the right part, the function doesn’t match the point) and it isn’t limited to the x1-x2 points but it start earlier.

scangraphfit.cpp (5.9 KB)

Here the data

ScanGeDDExpnonorm.txt (1.1 KB)

Thank you

Use: "S R"
See: TGraph::Fit

Thank you @Wile_E_Coyote , it works!

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