[ROOT] Problems with ChiSquare

From: Johannes (jopuna@yahoo.com)
Date: Sat Feb 16 2002 - 10:17:07 MET


Hi Rooters,

I have some problems with the calculation of the
chisquare of a signal+background histogram fit.
Although the fit both of the signal and the combined
signal+background looks quite good, the chisquare is
by far too high.
I already tried to set the fit limits close by the
signal gauss, but it doesn't help.


Here's my code:

TF1* gaussian = new TF1 ("gaussian",
"2*[0]*(1/(sqrt(2*pi)*[2]))*exp(-.5*((x-[1])/[2])^2)",0.,75000.);

TF1* ceby = new TF1("ceby",     
"[0]*cheby_0+[1]*cheby_1+[2]*cheby_2+[3]*cheby_3+[4]*cheby_4");

TF1* fit_func = new TF1("fit_func",
"(2*[0]*(1/(sqrt(2*pi)*[2]))*exp(-.5*((x-[1])/[2])^2))+[3]*cheby_0+[4]*cheby_1+[5]
  *cheby_2+[6]*cheby_3+[7]*cheby_4",10000.,75000.);


[...]
gaussian->SetParameter(0,start_parameter[0]);
gaussian->SetParameter(1,start_parameter[1]);
gaussian->SetParameter(2,start_parameter[2]);
ceby->SetParameter(3,start_parameter[3]);
ceby->SetParameter(4,start_parameter[4]);
ceby->SetParameter(5,start_parameter[5]);
ceby->SetParameter(6,start_parameter[6]);
ceby->SetParameter(7,start_parameter[7]);
  
      calibration_histos[i]->Fit("ceby","0+","");
                  // 0(zero)=Store, do not draw
TH1F* htemp=(TH1F*)calibration_histos[i]->Clone();
htemp->SetName("htemp");
htemp->Reset();
background=calibration_histos[i]->GetFunction("ceby");
for (int bin=min_bin;bin<max_bin;bin++)
{
   float x;
   x=calibration_histos[i]->GetBinCenter(bin);
   double value, difference;
   value=ceby->Eval(x);
  
difference=fabs(value-calibration_histos[i]->GetBinContent(bin));
   htemp->Fill(x,difference);
}
htemp->Fit("gaussian","0+","");
signal=htemp->GetFunction("gaussian");

signal->GetParameters(&parameters[0]);
background->GetParameters(&parameters[3]);
fit_func->SetParameters(parameters);
      calibration_histos[i]->Fit("fit_func","0+","");
      for (int grumpf=0; grumpf<8;grumpf++)
      {
         cerr << endl << parameters[grumpf] << endl;
         cerr << fit_func->GetParameter(grumpf);
      }

calibration_histos[i]->Draw("");
htemp->Draw("same");
gaussian->Draw("same");
fit_func->Draw("same");
c1->Update();
fit_parameters_act.chisqr=fit_func->GetChisquare();
cerr<<endl<<"CHISQUAREGAUSS:"<<gaussian->GetChisquare()
<< endl;
cerr<<endl<<"CHISQUAREFIT_FUNC"<<fit_parameters_act.chisqr
<< endl;

[...]

Hope i didn't overlook something completely trivial...


Regards


Johannes 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com



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