Hi, You should not use the log likelihood method in your example. The log likelihood is good when fitting an histogram with low statistics as indicated by Jacek M. Holeczek. This is not your case. You are filling an histogram with weights. See your example with several simplifications below: Rene Brun Double_t fitf(Double_t *x, Double_t *par) { Double_t arg=(x[0]-par[2])/par[3]; Double_t gauss1=par[1]*exp(-0.5*arg*arg)/(2.5066283*par[3]); // function=gauss+constant background return gauss1+par[0]; } void start(void) { TH1F* h1=new TH1F("h1","test histogram",100,1,100); double sigma=5.0; double lineSize=10; // HERE THE SIZE CAN BE CHANGED for (int i=1;i<=100;i++) { double arg=(double(i)-50.0)/sigma; double content=4.0+lineSize*exp(-arg*arg/2)/(sigma*2.5066); h1->Fill(i,content); } h1->SetFillColor(2); h1->SetLineColor(2); h1->SetMinimum(0.0); // specifying function and set fit parameters TF1* func=new TF1("fitf",fitf,10,90,4); func->SetLineWidth(2); func->SetParameters(5.0, 10, 50, 5.0); // do the fit h1->Fit("fitf","em"); } On Wed, 2 Oct 2002, Alexander Dietz wrote: > Hello Rooters, > > I have a problem in fitting some data. > > The code below creates a histogram with 100 bins, in it a contstant > background and a Gaussian line with variable size. > When executing the fit with a size of 1000 for the line all works fine. > When I use 100 counts for the line the fit-result is only 84 counts > (instead of 100). > And when I use 10 counts for the line the fit is done very bad. > > So what can I do to obtain a correct fit to the data WITHOUT using the > Chi-square method (because the Chi-square method is limited at low > statistics, see http://root.cern.ch/root/roottalk/roottalk02/1395.html). > > > Cheers, > > Alexander > > > > > > Double_t fitf(Double_t *x, Double_t *par) > { > Double_t arg=(x[0]-par[2])/par[3]; > Double_t gauss1=par[1]*exp(-0.5*arg*arg)/(2.5066283*par[3]); > // function=gauss+constant background > return gauss1+par[0]; > } > > void start(void) > { > TH1F* h1=new TH1F("h1","test histogram",100,1,100); > double sigma=5.0; > double lineSize=1000; // HERE THE SIZE CAN BE CHANGED > for (int i=1;i<=100;i++) { > double arg=(double(i)-50.0)/sigma; > double content=4.0+lineSize*exp(-arg*arg/2)/(sigma*2.5066); > h1->Fill(i,content); > } > > h1->SetFillColor(2); > h1->SetLineColor(2); > h1->SetMinimum(0.0); > > // specifying function and set fit parameters > TF1* func=new TF1("fitf",fitf,10,90,4); > func->SetLineWidth(2); > func->SetParameters(5.0, 10, 45, 6.0); > func->SetParLimits(0, 0.0, 10.0); > func->SetParLimits(1, 0.0, 1000.0); > func->SetParLimits(2, 47.0,53.0); > func->SetParLimits(3, 2.0, 10.0); > > // do the fit > h1->Fit("fitf","LME"); > > } > > >
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:12 MET