Draw TF1 with fitting errors


I want to Draw TF1 object with fitting errors.
What I want to do is
Fit the TH1 histogram by TF1 function, and then draw the fit function with fitting errors like TGraphPainter.

I tried Draw->(“e”) but this option draws with statistical error.

Is there a good draw option or cool function ?


For me it works:

root [0] hpx->Fit("gaus");
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
 FCN=116.145 FROM MIGRAD    STATUS=CONVERGED      52 CALLS          53 TOTAL
                     EDM=6.90265e-09    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     7.95916e+02   6.15041e+00   2.66657e-02   2.24892e-05
   2  Mean        -1.08164e-02   6.33665e-03   3.34812e-05  -1.86751e-03
   3  Sigma        9.97964e-01   4.42145e-03   6.38273e-06   7.29629e-02
root [1] hpx->Draw("E")
root [2] 

May be you mean something else ?

As far as I understand it, he wants to draw the FITTED FUNCTION WITH ITS UNCERTAINTIES / “ERRORS” (estimated from the fit errors), not the histogram -> i.e. something like the “best fit” plus the “± 1 sigma band”.

Yes, reading his question again you are right I think.
I let Lorenzo reply.

Hi couet and Pepe Le Pew

Yes I want to draw the function with best fit parameters with its error band.

Well, before Lorenzo replies … maybe this new thread would be of any help: [url]Plot error bands on fit

Thank you !!
I found a good example code in tutorials.

Sorry, I tried like ConfidenceIntervals.C or ErrorIntegral.C

TEfficiency *TEff = new TEff();
TVirtualFitter * fitter = TVirtualFitter::GetFitter();
assert(fitter != 0);
TH1D *test = new TH1D("test","test",50,0,250);
double * covMatrix = fitter->GetCovarianceMatrix(); 
Double_t Integral = f1->Integral(160,250)
Double_t Integral_err = f1->IntegralError(160,250)
cout<<Integral<<" "<<Integral_err<<endl;

but I got an error
Error in TBackCompFitter::GetConfidenceIntervals: Cannot compute confidence intervals with an invalide fit result
Warning in TBackCompFitter::GetCovarianceMatrix: Invalid fit result
Error in TF1Helper::IntegralError: Last used fitter is not compatible with the current TF1

I checked fit result but it is valid and its status is converged.
TBinomialEfficiencyFitter doesn’t support GetCovarianceMatrix and GetConfidenceIntervals ?