# Erf fitting to ratio histogram

Dear all,

I an trying to fit using erf function from TMath, and struggling very much not getting it quite right. Can I kindly have some help this fit?
Here is the sample fitting macro that I have used:
TF1 *myFit1T1 = new TF1(“myFit1T1”,“1 -TMath::Erf(-(x - [0]))”, 0. , 10);
myFit1T1->SetLineColor(kRed);
hratio_e_mb_sect0->Fit(“myFit1T1”,“QR+”);//fitting here
hratio_e_mb_sect0->SetMarkerColor(kBlue);
hratio_e_mb_sect0->Draw(“P”);

This is how the fit looks:

Thank you for kind assistance.

@moneta can probably give some advice

Hi,
I think the problem is in the error of your data. They look to me far too large for points with y value closer to 1 and too small for points closer to 0.
Is this an efficiency curve obtained from an histogram ratio ? In that case the correct way is to use the TEfficiency class and TEfficiency::Fit.

Lorenzo

thank you.

Hi,
Yes it is a histogram ratio. Can you kindly explain why taking the ratio using the Divide() method is incorrect?

Basically, you are saying no way to fit erf(x) function to the points?

When using TH1::Divide the uncertainty are propagated using standard error propagation, which is not correct in division of counts, which can be binomial or just Poisson ratio.
Then when fitting, you should use the correct ratio point distribution (eg .binomial), and this is done by performing a max. likelihood fit in TEfficiency::Fit.

Lorenzo

Sorry just from reading but I am not sure about TEfficiency in the macro:

``````TFile *tfile = TFile:: Open(hosto.root);
TH1F *hmbclus_e_sect0  = (TH1F*) tfile->Get("hminclus_e_sect0");
TH1F *hertclus_e_sect0  = (TH1F*) tfile->Get("hertclus_e_sect0");
TEfficiency * heff = 0;
heff = TEfficiency(*hertclus_e_sect0, *hmbclus_e_sect0);
heff->Draw("AP");
``````

Can you kindly help me with the TEfficiency and how to now fit?

Hi,
have you tried doing

``````heff->Fit(“myFit1T1”)
``````

Lorenzo

Hey,

No I did cause I removed that from my code. Thanks.