Wrong calculation of confidence level

Hi,

I have found a discrepancy between the value returned by method TF1::GetProb() and the “Prob” (probability) value printed on the canvas after a fit. The problem shows up when at least one function parameter has been fixed in the fit.

I’m attaching a small macro that reproduces the problem.

Cheers,

–Christos

PS % which root
/d0usr/products/root/Linux-2-4/v4_00_03a_rh71_locked-GCC_3_1–exception–opt–thread/bin/root

#include <TROOT.h>
#include <TH1F.h>
#include <TF1.h>
#include <TRandom.h>
#include <TCanvas.h>
#include <TPostScript.h>
#include <TLatex.h>
#include <TStyle.h>

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>

inline Double_t my_gauss(Double_t * x, Double_t * par)
{
  // par[0]: # of events, par[1]: mean, par[2]: sigma
  Double_t arg = 0;
  if (par[2]<0) par[2]=-par[2]; // make sure sigma > 0
  if (par[2] != 0) arg = (x[0] - par[1])/par[2]; 
  return par[0]*TMath::Exp(-0.5*arg*arg)/
    (TMath::Sqrt(2*TMath::Pi())*par[2]);
}

using namespace std;

int run_test(void)
{
  gStyle->SetOptFit(1111);
  // mean of gaussian
  float mean = 10;
  // upper, lower limits of distribution
  float LOW_LIMIT = -5 + mean;
  float HI_LIMIT = 5 + mean;
  // This function will be used for "sampling" values into a histogram
  TF1 * fgen = new TF1("gauss1", my_gauss, LOW_LIMIT, HI_LIMIT, 3);
  fgen->SetParameters(1, mean, 1); // # of events, mean, sigma

  // this histogram is the "data"
  TH1F * my_hist = new TH1F("my_hist", "Gauss distribution", 100, 
			    LOW_LIMIT, HI_LIMIT);
  
  int NEVENT = 15000;
  for(int i = 0; i != NEVENT; ++i)
    my_hist->Fill(fgen->GetRandom());
    
  // this function will be used to fit the histogram
  TF1 * fhist = new TF1("gauss2", my_gauss, LOW_LIMIT, HI_LIMIT, 3);
  fhist->SetParNames("Evt count", "Mean", "Sigma");
  // initial "guess" for the parameters
  fhist->SetParameters(100, mean, 0.8); // # of events, mean, sigma

  TCanvas * c1 = new TCanvas();

  fhist->SetParLimits(1, mean, mean);
  my_hist->Fit(fhist, "RIVL");

  cout << " chi2/Ndof = " << fhist->GetChisquare() << "/" << 
    fhist->GetNDF() << endl;
  cout << " Fit probability = " << fhist->GetProb() << endl;

  c1->Print("my_fit.ps");

  return 0;
}

Hi Christos,

Thanks for this remark with TF1::GetProb.
The function was not taking into account the number of fixed parameters.
Fix now in CVS.

Rene