Integral of fitted function

I have fitted a Gaussian to a histogram, and now want to find the integral of the fitted function.

I’m using version 3.03/09

I think it should be quite simple, but when I run the macro shown below I get a wrong anwser.
The integral is returned as as 15.27, at least an order of magnitude out just from looking at the curve - which peaks at 70 and has a sigma of 0.09.

my macro:



FILE *fp = fopen(“Data/sampled107.txt”,“r”);

Double_t x;
Int_t ncols;
Int_t nlines = 0;
Double_t limit_plot=100;

plot7 = new TCanvas(“plot7”,“plot7”);

TH1F *h1 = new TH1F(“h1”,“Pulse height spectrum Sampled 107”,231,0.006,1.862);

// read in data from file
while (1) {
ncols = fscanf(fp,"%lf",&x); // scan in long float = double
if (ncols < 0) break;
// read in only above noise threshold for test
if (x>0.520)
cout << " found " << nlines << " points" << endl;

/// make calculations for pedestal subtracted histogram

// fit gaussian to signal and noise
g2 = new TF1(“g2”,“gaus”,0.0,1.862); // and for SIGNAL


Double_t sumundercurve;

sumundercurve = g2->Integral(0,1.862);
cout << "sumundercurve = " << sumundercurve << endl;



I must have made some sort of stupid error - hope you can help
thank you,
Laura Somerville

Could you send me your data file sampled107.txt?


Hi Laura,

You should be getting amplitudesigmasqrt(2*pi), which is
~ 15.8 if amplitude = 70 and sigma = 0.09, right?

If this does not work, maybe you are off by the bin size = (1.862-0.006)/231 (or the reverse)?


sorry to have wasted your time :frowning:
you are correct, I made a mistake in the bin size and completely overestimated the number.
thanks for your prompt help