Fit Gauss twice and get both results

Hi,

I have a spectrum with two peaks, which I want to fit both. In the drawing of the resulting histogram, I want to see both fit-results drawn, but I also want to store the fit-results in a file (i.e. “mean” and “mean2”). However, with the following code, even though in the drawing two different peaks are correctly fitted and drawn, the calls to GetParameter (both to “fitGauss” and “fitGauss2”) return the same values (the value for the first fit). How can I obtain the results of the second fit?

	h1->Fit("gaus", "Q", "", xmin, xmax);
	TF1* fitGauss = h1->GetFunction("gaus");
	double mean = fitGauss->GetParameter(1);
	double sigma = fitGauss->GetParameter(2);
				
            h1->Fit("gaus", "Q+", "", xmin2, xmax2);
	TF1* fitGauss2 = h1->GetFunction("gaus");
	double mean2 = fitGauss2->GetParameter(1);
	double sigma2 = fitGauss2->GetParameter(2);

Cheers,
Machiel

Try: TF1 *gaus = ((TF1 *)(gROOT->GetFunction("gaus"))); h1->Fit(gaus, "Q", "", xmin, xmax); double mean = gaus->GetParameter(1); double sigma = gaus->GetParameter(2); h1->Fit(gaus, "Q+", "", xmin2, xmax2); double mean2 = gaus->GetParameter(1); double sigma2 = gaus->GetParameter(2);

Yes, thank you. That worked perfectly!

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