# Error fitting Histo from a Canvas

**URL:** <https://root-forum.cern.ch/t/error-fitting-histo-from-a-canvas/15097>\
**Category:** ROOT\
**Created:** [October 17, 2012, 7:50am UTC](https://root-forum.cern.ch/t/error-fitting-histo-from-a-canvas/15097 "2012-10-17T07:50:02Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [October 17, 2012, 10:51am UTC](https://root-forum.cern.ch/t/error-fitting-histo-from-a-canvas/15097/4 "2012-10-17T10:51:50Z")

</div>

TFile miofile(“test.root”);  
TCanvas _can = (TCanvas_)miofile.Get(“c1”);  
TH1D _his = ((TH1D_)(can-\>FindObject(“MCA”)));  
Double\_t xmin = his-\>GetBinCenter(1);  
Double\_t xmax = his-\>GetBinCenter(his-\>GetNbinsX());  
his-\>Fit(“gaus”, “”, “”, xmin, xmax);  
can-\>Draw();

TFile miofile(“test.root”);  
TCanvas _can = (TCanvas_)miofile.Get(“c1”);  
((TPad \*)can-\>FindObject(“pad1”))-\>GetListOfPrimitives()-\>ls();  
((TPad \*)can-\>FindObject(“pad1”))-\>GetListOfPrimitives()-\>Print();  
TH1D _his = ((TH1D_)(((TPad \*)can-\>FindObject(“pad1”))-\>GetPrimitive(“MCA”)));  
Double\_t xmin = his-\>GetBinCenter(1);  
Double\_t xmax = his-\>GetBinCenter(his-\>GetNbinsX());  
his-\>Fit(“gaus”, “”, “”, xmin, xmax);  
can-\>Draw();

---

_[View the full topic](https://root-forum.cern.ch/t/error-fitting-histo-from-a-canvas/15097)._
