Hello,
I am fitting a 1D histogram with a TF1, using the TH1 method “Fit”. In the fit options, I specify a likelihood fit with Minos error estimation. What I would like is the 90% confidence limit for the returned parameter (as opposed to the 1-sigma error that is returned by default).
I am steering the fit using the TVirtualFitter class (ie. I set the default minimizer, tolerance, etc this way). Here, I use TVirtualFitter::SetErrorDef(double err) to try and change the value my minimizer uses when supplying the error in the fit parameter. However, what I find is that regardless of the value of err I supply, the returned error of my parameter never changes (I obtain it using the TVirtualFitter method GetErrors).
Looking at a scan of the likelihood space, I should certainly be seeing a different error for err=1 versus err=3, say.
Either I am doing something wrong, or misunderstand what is being represented by GetErrors (I assume this method returns the upper and lower errors supplied by the Minos routine, and that these values should be affected by the value I set err to be).
A simple version of my code follows that shows the problem. Should I be doing this in a different way completely (keeping in mind the problem I am solving is more complicated)? Any help would be great.
Thanks,
Logan
double func(double *x, double *par){
double f = 0.;
f = par[0]*pow(x[0],2);
return f;
}
void test_fit(double errdef = 0.5){
TVirtualFitter::SetDefaultFitter("Minuit2");
TVirtualFitter::SetMaxIterations(7000);
TVirtualFitter::SetPrecision(1.e-8);
TVirtualFitter::SetErrorDef(errdef);
double d[21] = {102.1,79.3,64.9,50.6,37.2,23.8,13.5,9.0,4.1,0.8,0.1,1.2,3.8,9.9,
15.3,24.9,35.7,50.2,63.8,82.5,99.6};
TH1D *data = new TH1D("data","data",21,-10.,10.);
for(int i=1; i<=data->GetNbinsX(); i++){
data->SetBinContent(i,d[i-1]);
}
data->Sumw2();
TF1 *fdata = new TF1("fdata",func,-10.,10.,1);
fdata->SetParameter(0,1.);
TFitResultPtr ptr = data->Fit(fdata,"WLVES","",-10.,10.);
int status = ptr;
if(status != 0) return;
TVirtualFitter *fit = TVirtualFitter::GetFitter();
double eup, elow, epar, globcc;
fit->GetErrors(0,eup,elow,epar,globcc);
double p = fit->GetParameter(0);
TGraph *g = new TGraph(1000);
TBackCompFitter *bfit = (TBackCompFitter*)fit;
bfit->Scan(0,g,p+10.*elow,p+10.*eup);
TCanvas *c1 = new TCanvas("c1","c1");
TCanvas *c2 = new TCanvas("c2","c2");
c1->cd(); data->Draw();
c2->cd(); g->Draw("a*");
return;
}