# Fast and robust S-curve "fitter"

Calculate the S-cure mean and sigma without fitting. Use bin-by-bin derivative of s-curve, which is a Gaussian, Mean is

mean = sum{x.p(x)} = 0.5 + sum{i.(B(i+1)-B(i))}i=0,N-1 / sum{B(i+1)-B(i)}i=0,N-1,

where i is bin number, B(i) bin contents, N is number of bins, and I assume x = bin number + 0.5

mean = 0.5 + [ N.B(N) - sum{B(i)}i=1,N-1 ] / sum{B(i)}i=1,N-1

Noting that sum{B(i)}i=1,N-1 is total histogram contents, C, minus B(N),

mean = 0.5 + [ (N+1)B(N) - C ] / ( C - B(N) )

Similarly, sigma = RMS = sqrt[ sum(x^2.p(x)) - mean^2 ]