Re: [ROOT] Fit troubles

From: Colin Bernet (bernet@kph.uni-mainz.de)
Date: Mon May 07 2001 - 21:00:09 MEST


Hi Gregory,

Actually, the problem comes from the fact that you don't specify the range on which the fit
should be done :
just replace
theFunc = new TF1("theFunc", func);
TGraph *tg=new TGraphErrors(nPoints,x,y,xErr,yErr);
tg->Fit("theFunc");

by:
theFunc = new TF1("theFunc", func,0.01,2000);
TGraph *tg=new TGraphErrors(nPoints,x,y,xErr,yErr);
tg->Fit("theFunc","R");

and you get it !
cheers,
Colin

Gregory Novak wrote:

> Thanks for your quick response.  However, I still claim it's a fitting
> problem.  As I add higher order terms to the fitting function, the
> chi-squared reported by Minuit gets extremely small, and my fit is
> exquisite -- except for the points at either end, which the function
> mises completely.
>
> For example, in the eps file I included, my function misses the leftmost
> point by about 10*sigma, but the chi squared reported by Minuit is only
> 0.3. The leftmost point is buried in the graph axis, between six and seven
> on the y axis, so it's a little hard to see.
>
> Further, no amount of tinkering will get Root's fit to hit this point.  So
> I think it's really not included.
> Cheers,
> Greg
>
> On Mon, 7 May 2001, Pavol Strizenec wrote:
>
> >
> >  Hi,
> >
> >  actually this is only drawing question, not fitting. By default
> > the function is draw by connecting 100 points over whole range.
> > If you include the statement:
> > theFunc->SetNpx(1000);
> > just after theFunc definition, you will get the function drawing
> > more closely to boundary points.
> >
> >               Pavol
> >
> >
> > On Mon, 7 May 2001, Gregory Novak wrote:
> >
> > > I'm running Root 2.25, and I'm trying to fit a function to a graph.
> > > However, it the fit doesn't seem to include the points on the boundary.  I
> > > played a lot with my fitting function to try to hit the point on the
> > > boundary, but finally concluded that nothing would work b/c the point
> > > wasn't included.  :-)
> > >
> > > So, how do I get Root to include all points?
> > >
> > > I've attached an eps file of the canvas showing the graph and the fitted
> > > function, and here (basically) is the code I'm using.
> > >
> > > Thanks,
> > > Greg
> > >
> > >
> > > Int_t nPoints=16;
> > > Float_t x[] = {0.195490003, 0.341758013, 0.626088023, 1.09469998, 1.92990005,
> > >   3.40200996, 5.99965, 10.5876999, 18.6718006, 32.9463005, 58.1189003,
> > >   102.549004, 180.925995, 319.307007, 563.236023, 993.775024};
> > > Float_t y[] = {6.47185993, 4.18911982, 2.12453008, 1.10843003, 0.803915024, 0.73110801,
> > >   0.749179006, 0.831418991, 0.876044989, 0.87609899, 0.91761899, 0.954747021,
> > >   0.983271003, 1.00406003, 1.02154005, 1.03620994};
> > > Float_t xErr[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
> > > Float_t yErr[] = {0.281376004, 0.189824, 0.112899996, 0.0736455023, 0.0586442016,
> > >   0.0549372993, 0.0546161011, 0.059711501, 0.0590298995, 0.0593684018,
> > >   0.0610054992, 0.0623256005, 0.0655059963, 0.0628056973, 0.0657007024,
> > >   0.0688278973};
> > >
> > >   const Char_t *func = "([0]+[1]/x**2+[2]/x**3+[3]/x**4)*log(x**2)+"
> > >     "[4]+[5]/x**2+[6]/x**3+[7]/x**4";
> > >   theFunc = new TF1("theFunc", func);
> > >   TGraph *tg=new TGraphErrors(nPoints,x,y,xErr,yErr);
> > >   tg->Fit("theFunc");
> > >   TCanvas *c1 = new TCanvas("c1","c1");
> > >   c1->SetLogx();
> > >   tg->Draw("AP");
> > >
> > >
> >
> >

--
Colin Bernet
Tel. +49-6131/39-23192
Fax  +49-6131/39-22964



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:44 MET