TFitResultPtr/TGraph & Eval

Dear all,

 i calculated the efficiency of a detector for certain energies.

Since I need the efficiency at a different energy, I had decided to fit the points with the curve theoretically describing the behaviourr of the detector and use Eval to get the value of the fitting curve at the desired point.
At that moment I realized I had no idea of the error bar of the evaluated uncertainty and looking around found out I can use TFitResultPtr.
But the value of the efficiency at the desired energy results different if I use Eval before or after calling
TFitResultPtr.
Could anyone explain me why?

Here is the routine:

// CPP includes
#include
#include
#include
#include
#include
#include
#include
#include

// C includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// ROOT includes
// ROOT includes
#include <TSystem.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TRint.h>
#include <TDirectory.h>
#include <TFile.h>
#include <TChain.h>
#include <TTree.h>
#include <TNtuple.h>
#include <TBranch.h>
#include <TH1.h>
#include <TAxis.h>
#include <TCanvas.h>
#include <TColor.h>
#include <TPad.h>
#include <TStyle.h>
#include <TKey.h>
#include <TLegend.h>
#include <TText.h>
#include <TPaveText.h>
#include <TLine.h>
#include <TMarker.h>
#include <TLatex.h>
#include <TMath.h>
#include <TH1.h>
#include <TH2.h>
#include <TF1.h>
#include <TF2.h>
#include “TObjString.h”
#include “TGraphErrors.h”
#include “TGraph.h”
#include "TFitResult.h"
using namespace std;

#define VERSION “v1.2_26092014”;

double fitf2(Double_t x, Double_t par)
{
Double_t a=1/TMath::Log10(x[0]);
Double_t fitval = par[0]/x[0] + par[1]/x[0]a + par[2]/x[0]aa + par[3]/x[0]aaa + par[4]/x[0]aa
a
a + par[5]/x[0]aaaaa +par[6]/x[0]aaaaaa + par[7]/x[0]aaaaaaa;
return fitval;
}

void cm0(){

 double *x=new double[5]{88.0336, 165.8575,  661.657, 834.848, 1115.9};
 double *y=new double[5]{15.133731,13.721544, 5.089457,4.727570,3.847336};
 double *erry=new double[5]{1.024484,1.219857,1.530440,0.814344,0.963188};
 TGraphErrors*g = new TGraphErrors(5, x,y,0,erry);
 g->GetYaxis()->SetRangeUser(0.1,20);
 g->SetMarkerSize(2);
 g->SetMarkerStyle(20);
 g->SetMarkerColor(4);	 
 g->Draw("AP");


 TF1*func= new TF1("fit", fitf2, 80,3400,8);
 func->SetParameters(0.0041,0.2,1,1,1,1,1,1);
 g->Fit("fit","R");
 cout << " ========== FROM FIT ================" << endl;
 cout <<func->Eval(909.15) <<endl;


 
 TFitResultPtr r = g->Fit(func,"S");
 double point[1] = {909.15};
 double err[1];  
 r->GetConfidenceIntervals(1, 1, 1, point, err, 0.683, false); // 1 sigma
 cout << " ========== AFTER FitResultPtr ================" << endl;
cout << " function value at " << point[0] << " = " << func->Eval(point[0]) << " +/- " << err[0] << endl;
cout << " function value at " << point[0] << " = " << func->Eval(909.15) << " +/- " << err[0] << endl;

}

Hi,
There is no reason that using the TFitResult will change the function value.
You are re-doing a fit on the function the second time and this might explain the small difference you observe in the function value, due to a slightly different parameter values found.
If you do as in the attached macro, (i.e. doing a second fit with a copy of the function) you will get the same
results

Lorenzo
rootForum_19842.C (1.46 KB)