Re: [ROOT] Problems with fiting

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Sep 30 2002 - 15:45:27 MEST


Hi Alexander,

Your errors along X seem to be far too large compared to your errors
along Y. If I reduce the errors by a factor 5 or 10, I obtain a good fit.
See below

Rene Brun

void prog(void) {
  float x[10];
  float y[10];
  float ex[10];
  float ey[10];

  Double_t alpha = .1;
  x[0]= 7508.84 ;ex[0]=alpha*0.037;
  x[1]= 1680.41 ;ex[1]=alpha*0.022 ;
  x[2]= 2093.11 ;ex[2]=alpha*0.05 ;
  x[3]= 2259.89 ;ex[3]=alpha*0.157;
  x[4]= 2474.87 ;ex[4]=alpha*0.065;
  x[5]= 2569.45 ;ex[5]=alpha*0.473;
  x[6]= 3100.43 ;ex[6]=alpha*0.272;
  x[7]= 4574.82 ;ex[7]=alpha*0.147;
  x[8]= 6041.46 ;ex[8]=alpha*0.15 ;

  y[0]=2614.53 ;ey[0]=0.013;
  y[1]=583.191 ;ey[1]=0.002;
  y[2]=727.33  ;ey[2]=0.009;
  y[3]=785.37  ;ey[3]=0.08;
  y[4]=860.564 ;ey[4]=0.005;
  y[5]=893.40  ;ey[5]=0.005;
  y[6]=1078.62 ;ey[6]=0.1;
  y[7]=1592.54 ;ey[7]=0.013;
  y[8]=2103.53 ;ey[8]=0.013;


  TCanvas* c1=new TCanvas("c1","c1",10,10, 400,300);
  TGraphErrors* graph=new TGraphErrors(9,x,y,ex,ey);

  graph->Draw("A*");
  graph->Fit("pol2","");
  graph->Draw("");
}
 FCN=819.438 FROM MIGRAD    STATUS=CONVERGED     147 CALLS         148
TOTAL
                     EDM=2.63628e-13    STRATEGY= 1  ERROR MATRIX
UNCERTAINTY   6.4 per cent
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0          -3.67015e+00   1.67026e-02   1.19699e-08  -4.33296e-05
   2  p1           3.49409e-01   1.13286e-05  -6.75892e-12   5.63994e-03
   3  p2          -9.86409e-08   1.29352e-09   5.42316e-16  -3.08442e+02


On Mon, 30 Sep 2002, Alexander Dietz wrote:

> Hello Rooters,
> 
> I have a problem with doing a fit with a TGraphErrors. In the program
> source (at the end of this mail) I want to perform a quadratic fit with
> 'TGraphErrors", using the errors as specified.
> When I use the fitting option 'W' (all errors set to 1) then the fit works
> very good, giving a sensefull result.
> But without the option 'W' the result of the fit is very, very bad and
> wrong.
> The correct result is, that parameter 1 is about 0.35.
> But with the option 'W' this parameter is around 10^7 !!!
> 
> So what can I do to get a correct fit which is using the errors I have
> specified?
> 
> 
> Regards
> 
> 	Alexander Dietz
> 
> 
> void prog(void)
> {
>   float x[10];
>   float y[10];
>   float ex[10];
>   float ey[10];
> 
>   x[0]= 7508.84 ;ex[0]=0.037;
>   x[1]= 1680.41 ;ex[1]=0.022 ;
>   x[2]= 2093.11 ;ex[2]=0.05 ;
>   x[3]= 2259.89 ;ex[3]=0.157;
>   x[4]= 2474.87 ;ex[4]=0.065;
>   x[5]= 2569.45 ;ex[5]=0.473;
>   x[6]= 3100.43 ;ex[6]=0.272;
>   x[7]= 4574.82 ;ex[7]=0.147;
>   x[8]= 6041.46 ;ex[8]=0.15 ;
> 
>   y[0]=2614.53 ;ey[0]=0.013;
>   y[1]=583.191 ;ey[1]=0.002;
>   y[2]=727.33  ;ey[2]=0.009;
>   y[3]=785.37  ;ey[3]=0.08;
>   y[4]=860.564 ;ey[4]=0.005;
>   y[5]=893.40  ;ey[5]=0.005;
>   y[6]=1078.62 ;ey[6]=0.1;
>   y[7]=1592.54 ;ey[7]=0.013;
>   y[8]=2103.53 ;ey[8]=0.013;
> 
> 
>   TCanvas* c1=new TCanvas("c1","c1",10,10, 400,300);
>   TGraphErrors* graph=new TGraphErrors(9,x,y,ex,ey);
> 
>   graph->Draw("A*");
>   graph->Fit("pol2","LEM");
>   graph->Draw("");
> 
>   double p0=graph->GetFunction("pol2")->GetParameter(0);
>   double p1=graph->GetFunction("pol2")->GetParameter(1);
>   double p2=graph->GetFunction("pol2")->GetParameter(2);
> }
> 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:12 MET