Fitting the amplitude of a function

I pose a simple question but so far I can’t find anyone who knows the answer:

In root, is it possible to fit a peak (from real data) and extract the amplitude of the function fitted?

Please, can anyone answer this?

Andrew

Search for “GetFunction” and “GetParameter” strings in the TH1 and the TGraph class descriptions.

Hi Wile,

Thanks for your reply. Unfortunately, I don’t think the solution is so simple.

As an example:

say I want to fit a gaussian to a peak in my data (counts vs channel). I can define the gaussian:

par[0]TMath::Exp( -1((x[0] - par[1])(x[0] - par[1])) / (2par[2]*par[2]) );

so, par[0] = amplitude, par[1] = mean and par[2] = width.

If I try to fit this function with all parameters free, the resulting value of par[0] does not equal the amplitude of my peak. I think this is because the function is internally normalised in some way.

Is there any way to extract the actual amplitude value?

Thanks

Try different TH1::Fit options: [code]{
gRandom->SetSeed(0);

TH1F *MyH1F = new TH1F(“MyH1F”,“a trial histogram”, 100, -5, 5);
MyH1F->Sumw2();
// sigma = 1, integral = 251, amplitude = 10.013 (at “bin width” = 0.1)
for (Int_t i = 0; i < 251; i++) MyH1F->Fill(gRandom->Gaus(0, 1));
// MyH1F->Scale(1.0, “width”); // then amplitude = 100.13

TF1 *MyF1 = new TF1(“MyF1”, “[0]TMath::Exp(-0.5((x-[1])/[2])**2)”, -1, 1);

Double_t GuessedAmplitude = 1, GuessedMean = 0, GuessedSigma = 1;

// must set initial (“guessed”) values of parameters
MyF1->SetParameters(GuessedAmplitude, GuessedMean, GuessedSigma);

std::cout << “MyH1F->Fit with … default flags …” << std::endl;
MyH1F->Fit(MyF1);

std::cout << “MyH1F->Fit with … W …” << std::endl;
MyH1F->Fit(MyF1, “W”);

std::cout << “MyH1F->Fit with … WW …” << std::endl;
MyH1F->Fit(MyF1, “WW”);

std::cout << “MyH1F->Fit with … L …” << std::endl;
MyH1F->Fit(MyF1, “L”);

std::cout << “MyH1F->Fit with … WL …” << std::endl;
MyH1F->Fit(MyF1, “WL”); // if MyH1F is weighted, i.e. must have Sumw2() set
}[/code]

Peak find&fit tutorial may also help: http://root.cern.ch/root/html534/tutorials/spectrum/peaks.C.html