(Fwd) Re: Fit x,y [2]

From: Valery Fine (fine@mail.cern.ch)
Date: Mon Aug 11 1997 - 11:02:06 MEST


------- Forwarded Message Follows -------

On 11 Aug 97 at 12:03, Voropaev S.G. wrote:

  Hello,
 Thank you very much
> 
> I think the problem is in the invalid range of fit:
> 
> float x[20],y[20];
> for(int i=0; i<20; i++) {x[i]=gRandom->Rndm(1);
> y[i]=0.5*x[i]*x[i]+0.2;}; c1 = new TCanvas("c1","Fit"); TGraph *tg =
> new TGraph(20,x,y); TF1 *f1 = new TF1("f1","pol2"); tg->Draw("AP");
> tg->Fit("f1","","AP");			// Fit range 0.1 - 0.2 !
> f1->SetRange(0.2,1.0); tg->Fit("f1","R","AP");			// All  is OK
> f1->SetRange(0.0,1.0); tg->Fit("f1","R","AP");			// All is OK
> 
> Now, you can see that TGraph::Fit set invalid default fit range in
> case of unsorted x,y data.
> 
>    With best regards	Voropaev S.G.


 You are right. It does it as follows:

   xmin    = fX[0];
   xmax    = fX[fNpoints-1];
   ymin    = fY[0];
   ymax    = fY[fNpoints-1];

    ....


//*-*- Is a Fit range specified?
   if (Foption.Range) {
      gF1->GetRange(xmin, xmax);
      xfirst = 1;
      xlast  = fNpoints;
   } else {
      gF1->SetRange(xmin, xmax);
      xfirst = 1;
      xlast  = fNpoints;
   }

  This means the last point of the array supplied is treated as the 
"LAST" point on the axis as well.

  What about TMinuit, it calculates the chi2 function and doesn't 
sense the order of the points supplied.

  Thank you very much. It was a good bug too. It is a pity you didn't 
find a way to fix it as well. This might help us a lot.

                                 Valera
Dr. Valeri Faine (Valery Fine)
    ------------ -------------   Phone: +41 22 767 6468
CERN                             FAX  : +41 22 767 7910
CH-1211 Geneva, 23               mailto:fine@mail.cern.ch 
Switzerland                      http://nicewww.cern.ch/~fine
                                 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:20 MET