# Erf fitting to ratio histogram

**URL:** <https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870>\
**Category:** Newbie\
**Created:** [June 11, 2020, 3:08am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870 "2020-06-11T03:08:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 11, 2020, 3:08am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/1 "2020-06-11T03:08:14Z")

</div>

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:

 ![fit_erf](https://root-forum.cern.ch/uploads/default/original/3X/d/6/d67b8ab7ddb55571db60f7340bd6d410672c53a2.png)

Thank you for kind assistance.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 11, 2020, 6:51am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/2 "2020-06-11T06:51:07Z")

</div>

@moneta can probably give some advice

---

<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 11, 2020, 8:37am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/3 "2020-06-11T08:37:19Z")

</div>

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.

See [https://root.cern.ch/doc/master/classTEfficiency.html](https://root.cern.ch/doc/master/classTEfficiency.html)

Lorenzo

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 11, 2020, 10:25am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/4 "2020-06-11T10:25:56Z")

</div>

thank you.

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 11, 2020, 10:30am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/5 "2020-06-11T10:30:30Z")

</div>

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?

---

<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 11, 2020, 10:43am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/6 "2020-06-11T10:43:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 11, 2020, 6:26pm UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/7 "2020-06-11T18:26:57Z")

</div>

Thank you for your response.

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

```auto
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");

```

 ![TEfficiency_efort](https://root-forum.cern.ch/uploads/default/original/3X/4/0/4064076eba8e4fd04131832383d46b38e5846c90.png)

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

---

<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 12, 2020, 7:18am UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/8 "2020-06-12T07:18:45Z")

</div>

Hi,  
have you tried doing

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

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 12, 2020, 3:11pm UTC](https://root-forum.cern.ch/t/erf-fitting-to-ratio-histogram/39870/9 "2020-06-12T15:11:05Z")

</div>

Hey,

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