I’m a bit confused about TF1::Variance. I am trying to draw an error band around a fit function and found this function. Does this give me an estimate of the variance of the fit function (averaged over a certain range)?

The reason I’m confused is that I tried fitting ‘ax+b’ to a set of points, all 0.4 with an error of 0.1. Then the fit is (of course) a very good one, a nice horizontal line, but the variance is
-) big: something like 0.7
-) constant for all bins in which I evaluate (variance computed from bin’s lower to upper edge) while it should depend on x, right?

Am I doing something else wrong or do I just have the wrong function? (Or tell me to go look up error propagation )

I’m afraid this is not what TF1::Variance provides. Perhaps you are thinking of something more like TF1::GetChiSquare(), which returns information on the quality of a fitted function to some data points?

I’ll take this as an opportunity to explain TF1::Variance (and a few other member functions I helped write), but I expect this will not be of much help to you. TF1::Variance has nothing to do with any data points. The following member functions provide functionality as:

TF1::Moment(n,a,b)
The nth moment of a function about zero. When n=1, this is the common case of the mean of a function between x=a and x=b. So moment = [Int x^n*f(x)]/[Int f(x)] where Int means the integral from x=a to b.

TF1::CentralMoment(n,a,b)
The nth moment of a function about the mean. So if u is the mean between a and b, the central moment = [Int (x-u)^n*f(x)]/[Int f(x)].

TF1::Variance(a,b) = TF1::CentralMoment(2,a,b)
By definition.

Unfortunately, this code suffers from one major flaw: it uses TF1::Integral to calculate the integrals, but TF1::Integral does not like negative values (it takes the absolute value of a function for its integral). This becomes a problem not only when trying to get the integral of a TF1 function which has negative values, but also when simply trying to get the mean of a function when the range (a,b) spans any negative numbers because x*f(x) can go negative even if f(x) is positive. Maybe one day we can get a version of TF1::Integral which does not take the absolute value of the evaluated function.