# TFitResultPtr/TGraph & Eval

**URL:** <https://root-forum.cern.ch/t/tfitresultptr-tgraph-eval/19384>\
**Category:** Roofit and RooStats\
**Created:** [June 16, 2015, 5:36pm UTC](https://root-forum.cern.ch/t/tfitresultptr-tgraph-eval/19384 "2015-06-16T17:36:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![franciuska](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b9e5f3/32.png) [@franciuska](https://root-forum.cern.ch/u/franciuska)\
**Post date:** [June 16, 2015, 5:36pm UTC](https://root-forum.cern.ch/t/tfitresultptr-tgraph-eval/19384/1 "2015-06-16T17:36:54Z")

</div>

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]aaa_a + par[5]/x[0]_a_a_a_a_a +par[6]/x[0]aa_a_a_a_a + par[7]/x[0]aa_a_a_a_a_a;  
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;

```

}

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [June 17, 2015, 10:44am UTC](https://root-forum.cern.ch/t/tfitresultptr-tgraph-eval/19384/2 "2015-06-17T10:44:28Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/2X/5/5ffa537405d4bfc3ad48cf06fa0c61c28564c4a9.C) (1.46 KB)
