Fiting the sum of three (gaus+landau) functions

Hello everyone,

First time here, so excuse me any mistakes in advance.

I’m trying to fit the sum of three (gaus+landau) functions to a spectrum with three main alpha-peaks. The landau function I’m fitting actually has it’s long tail to the left to make for the energy loss of the alphas in the rarefied air. I seem to be able to individually fit the peaks very well in a decent range around each one of them but when I fit the sum of the functions the result makes no sense - I’m sure it does make sense, but I can’t figure out what 's the issue.

I’ve been searching and searching for a solution and I’ve read the multifit tutorial and several others but I still haven’t found a way to make it work.

Can you help me?

The result’s:
dropbox.com/s/5xgsp58cj6hds53/ajuste.png

My code, where lg1, lg2 and lg3 are the individual fitting functions.

[code]void landau()
{
// Fill Histogram
Int_t data[1024] = {0,0,0,0,0,0,0,0,0,1,0,4,1,4,4,4,5,5,2,6,5,8,8,5,3,8,6,5,8,4,2,3,6,5,2,6,1,6,3,8,12,4,6,8,3,7,3,8,3,4,10,6,6,7,4,5,6,8,7,14,10,4,5,5,11,5,6,4,6,8,8,2,4,9,4,3,4,3,2,0,2,6,3,3,6,6,8,7,4,1,4,9,5,6,5,8,8,7,10,9,7,4,6,10,7,6,9,7,5,5,11,14,6,3,10,12,7,10,7,13,8,10,4,9,6,10,9,10,9,9,7,7,7,9,6,10,13,9,15,9,6,6,5,8,9,11,8,7,10,8,16,10,10,13,6,12,13,12,10,13,9,8,8,11,9,7,11,14,8,8,7,6,7,11,8,13,8,10,9,10,14,10,4,9,11,17,11,10,10,12,11,14,9,16,9,18,8,13,18,8,6,15,18,11,15,11,16,9,10,13,10,22,11,14,14,12,11,13,22,18,22,11,13,18,17,14,8,16,7,10,15,14,14,7,15,21,20,14,18,19,13,16,12,14,24,24,13,10,17,24,14,21,15,20,15,17,22,20,12,18,25,25,16,21,18,18,32,24,19,25,28,19,14,14,16,13,20,24,21,16,28,22,22,32,24,19,28,31,24,14,20,31,18,28,24,29,33,35,30,34,36,23,32,41,40,28,35,25,35,31,38,33,43,44,38,27,36,36,33,57,48,38,40,39,42,50,47,43,35,51,43,38,43,46,59,41,43,44,69,48,50,42,51,63,47,57,60,51,58,60,65,58,52,62,58,58,47,78,66,60,57,72,80,68,66,71,73,78,89,77,70,94,76,86,80,111,96,95,80,109,86,117,94,139,123,114,121,124,117,135,134,139,126,140,139,123,125,129,123,142,155,155,165,154,170,182,173,190,218,219,256,269,296,351,398,443,525,634,748,888,959,1043,1166,1190,1177,1141,1113,917,862,709,564,513,514,515,559,541,584,616,751,796,847,1073,1172,1399,1737,2122,2680,3266,4048,4891,5674,6701,7382,8119,8491,8574,8073,7032,6328,5163,4211,3546,3232,3438,3795,4408,5215,6670,8400,10875,13881,17610,21997,27228,33232,38940,44470,49122,51102,49910,46833,42015,33976,25696,17958,11612,6834,3983,2217,1298,820,660,584,549,510,471,477,471,413,388,405,325,320,281,273,259,261,268,257,263,309,305,280,245,229,177,126,114,61,27,15,11,0,1,0,0,0,2,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

TCanvas *c1 = new TCanvas(“c1”);
c1->SetLogy();

TH1F *hSNR = new TH1F(“0”,“0”,1024,0,1024);

for (Int_t i=0; i<1024; i++) hSNR->Fill(i,data[i]);

Double_t par[18];

TF1 *lg1 = new TF1(“lg1”,"[0]*TMath::Gaus(x,[1],[2])+[3]*TMath::Landau(-x+[4],[5],[6])", 415, 429);
TF1 *lg2 = new TF1(“lg2”,"[0]*TMath::Gaus(x,[1],[2])+[3]*TMath::Landau(-x+[4],[5],[6])", 444, 460);
TF1 *lg3 = new TF1(“lg3”,"[0]*TMath::Gaus(x,[1],[2])+[3]*TMath::Landau(-x+[4],[5],[6])", 466, 489);
TF1 *total = new TF1(“total”,“lg1+lg2+lg3”,415,489);

lg1->SetParameters(2000, 420, 5, 800, 2000, 420, 5);
lg2->SetParameters(16000, 900, 452, 3, 16000, 452, 3);

lg1->SetParameters( 1000, 425, 4.6, 1000, 850, 425, 5);
lg2->SetParameters( 8600, 454.5, 5.5, 8600, 910, 455, 5);
lg3->SetParameters(50000, 479, 9.3, 50000, 958, 479, 37.2);

total->SetLineColor(1);

hSNR->Fit(“lg1”,“R”);
lg1->GetParameters(&par[0]);
hSNR->Fit(“lg2”,“R+”);
lg2->GetParameters(&par[6]);
hSNR->Fit(“lg3”,“R+”);
lg3->GetParameters(&par[12]);

total->SetParameters(par);
hSNR->Fit(“total”,“R+”);

gStyle->SetOptFit(1111);

hSNR->GetXaxis()->SetRange(200,600);
hSNR->Draw();
}
[/code]

[code] void landau()
{
// Fill Histogram
Int_t data[1024] = {0,0,0,0,0,0,0,0,0,1,0,4,1,4,4,4,5,5,2,6,5,8,8,5,3,8,6,5,8,4,2,3,6,5,2,6,1,6,3,8,12,4,6,8,3,7,3,8,3,4,10,6,6,7,4,5,6,8,7,14,10,4,5,5,11,5,6,4,6,8,8,2,4,9,4,3,4,3,2,0,2,6,3,3,6,6,8,7,4,1,4,9,5,6,5,8,8,7,10,9,7,4,6,10,7,6,9,7,5,5,11,14,6,3,10,12,7,10,7,13,8,10,4,9,6,10,9,10,9,9,7,7,7,9,6,10,13,9,15,9,6,6,5,8,9,11,8,7,10,8,16,10,10,13,6,12,13,12,10,13,9,8,8,11,9,7,11,14,8,8,7,6,7,11,8,13,8,10,9,10,14,10,4,9,11,17,11,10,10,12,11,14,9,16,9,18,8,13,18,8,6,15,18,11,15,11,16,9,10,13,10,22,11,14,14,12,11,13,22,18,22,11,13,18,17,14,8,16,7,10,15,14,14,7,15,21,20,14,18,19,13,16,12,14,24,24,13,10,17,24,14,21,15,20,15,17,22,20,12,18,25,25,16,21,18,18,32,24,19,25,28,19,14,14,16,13,20,24,21,16,28,22,22,32,24,19,28,31,24,14,20,31,18,28,24,29,33,35,30,34,36,23,32,41,40,28,35,25,35,31,38,33,43,44,38,27,36,36,33,57,48,38,40,39,42,50,47,43,35,51,43,38,43,46,59,41,43,44,69,48,50,42,51,63,47,57,60,51,58,60,65,58,52,62,58,58,47,78,66,60,57,72,80,68,66,71,73,78,89,77,70,94,76,86,80,111,96,95,80,109,86,117,94,139,123,114,121,124,117,135,134,139,126,140,139,123,125,129,123,142,155,155,165,154,170,182,173,190,218,219,256,269,296,351,398,443,525,634,748,888,959,1043,1166,1190,1177,1141,1113,917,862,709,564,513,514,515,559,541,584,616,751,796,847,1073,1172,1399,1737,2122,2680,3266,4048,4891,5674,6701,7382,8119,8491,8574,8073,7032,6328,5163,4211,3546,3232,3438,3795,4408,5215,6670,8400,10875,13881,17610,21997,27228,33232,38940,44470,49122,51102,49910,46833,42015,33976,25696,17958,11612,6834,3983,2217,1298,820,660,584,549,510,471,477,471,413,388,405,325,320,281,273,259,261,268,257,263,309,305,280,245,229,177,126,114,61,27,15,11,0,1,0,0,0,2,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  TCanvas *c1 = new TCanvas("c1");
  c1->SetLogy();

  TH1F *hSNR = new TH1F("0","0",1024,0,1024);

  for (Int_t i=0; i<1024; i++) hSNR->Fill(i,data[i]);
 
 [color=#FF0040] Double_t par[21];[/color]

  TF1 *lg1 = new TF1("lg1","[0]*TMath::Gaus(x,[1],[2])+[3]*TMath::Landau(-x+[4],[5],[6])", 415, 429);
  TF1 *lg2 = new TF1("lg2","[0]*TMath::Gaus(x,[1],[2])+[3]*TMath::Landau(-x+[4],[5],[6])", 444, 460);
  TF1 *lg3 = new TF1("lg3","[0]*TMath::Gaus(x,[1],[2])+[3]*TMath::Landau(-x+[4],[5],[6])", 466, 489);
  TF1 *total = new TF1("total","lg1+lg2+lg3",415,489);

  lg1->SetParameters(2000,  420,   5, 800,  2000, 420, 5);
  lg2->SetParameters(16000, 900, 452,   3, 16000, 452, 3);
 
  lg1->SetParameters( 1000,   425, 4.6, 1000,  850,  425, 5);
  lg2->SetParameters( 8600, 454.5, 5.5, 8600,  910,  455, 5);
  lg3->SetParameters(50000,   479, 9.3, 50000, 958, 479, 37.2);

  total->SetLineColor(1);

  hSNR->Fit("lg1","R");
  lg1->GetParameters(&par[0]);
  hSNR->Fit("lg2","R+");
  [color=#FF0000]lg2->GetParameters(&par[7]);[/color]
  hSNR->Fit("lg3","R+");
  [color=#FF0000]lg3->GetParameters(&par[14]);[/color]

  total->SetParameters(par);
  hSNR->Fit("total","R+");
 
  gStyle->SetOptFit(1111);

  hSNR->GetXaxis()->SetRange(200,600);
  hSNR->Draw();
}

[/code]

Thank you a lot! Such a mistake… Really, thank you.