# Restrict the fit range on x-axis

**URL:** <https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843>\
**Category:** Newbie\
**Created:** [March 2, 2023, 5:27am UTC](https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843 "2023-03-02T05:27:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex14](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@alex14](https://root-forum.cern.ch/u/alex14)\
**Post date:** [March 2, 2023, 5:27am UTC](https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843/1 "2023-03-02T05:27:35Z")

</div>

Hi all,

I have a question about fitting TH1D histograms to the user-defined function “gaus”  
As I mentioned, I fit the histogram hist\_am[k]-\>Fit(“gaus”); but now I want to restrict the fit range on the right side to 2.  
Could someone please give me some advice on how to do this? Thanks.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 2, 2023, 5:52am UTC](https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843/2 "2023-03-02T05:52:46Z")

</div>

Check out the use of the “R” option:  
[https://root.cern/doc/master/multifit\_8C.html](https://root.cern/doc/master/multifit_8C.html)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 2, 2023, 7:35am UTC](https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843/3 "2023-03-02T07:35:22Z")

</div>

[`hist_am[k]->Fit("gaus", "", "", some_xmin, some_xmax);`](https://root.cern/doc/master/classTH1.html#a7e7d34c91d5ebab4fc9bba3ca47dabdd)

---

<div class="post-metadata">

**Author:** ![alex14](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@alex14](https://root-forum.cern.ch/u/alex14)\
**Post date:** [March 4, 2023, 4:41pm UTC](https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843/4 "2023-03-04T16:41:14Z")

</div>

Thanks very much for your help!  
I says however that there is no matching member function for call to 'Fit’, and I also get these mistakes :

/usr/local/Cellar/root/6.26.06\_1/include/root/TH1.h:232:29: note: candidate function not viable: no known conversion from ‘Double\_t’  
(aka ‘double’) to ‘Option\_t \*’ (aka ‘const char \*’) for 3rd argument  
virtual TFitResultPtr Fit(const char \*formula ,Option\_t \*option=“…  
^  
/usr/local/Cellar/root/6.26.06\_1/include/root/TH1.h:233:29: note: candidate function not viable: no known conversion from ‘const char [5]’ to  
‘TF1 \*’ for 1st argument  
virtual TFitResultPtr Fit(TF1 \*f1 ,Option\_t \*option=”" ,Option\_t \*…

---

<div class="post-metadata">

**Author:** ![alex14](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@alex14](https://root-forum.cern.ch/u/alex14)\
**Post date:** [March 5, 2023, 5:17am UTC](https://root-forum.cern.ch/t/restrict-the-fit-range-on-x-axis/53843/6 "2023-03-05T05:17:18Z")

</div>

Thanks again. It all works now.
