# Getting details of a gaussian fit

**URL:** <https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580>\
**Category:** ROOT\
**Created:** [June 28, 2021, 1:04pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580 "2021-06-28T13:04:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 28, 2021, 1:04pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/1 "2021-06-28T13:04:35Z")

</div>

Hello, I need details of a gaussian fit:

> Least squares, Maximum Likelihood, fit goodness, residual plot. etc…

For the fit goodness, by default, ROOT print the X^2 in the stat box, …but, how to get the other needed information?

@moneta , surely you can help me  
Thank you

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<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 28, 2021, 2:11pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/2 "2021-06-28T14:11:26Z")

</div>

Hi,

You can get the majority of information from the FitResult class, that is returned from `TH1::Fit` when using the option `S`. See [ROOT: ROOT::Fit::FitResult Class Reference](https://root.cern.ch/doc/master/classROOT_1_1Fit_1_1FitResult.html)

Lorenzo

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 28, 2021, 4:22pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/3 "2021-06-28T16:22:10Z")

</div>

Thank you @moneta.  
I looked the page but I could only find

```auto
Chi2();
Ndf();

```

I can’t find functions for the other parameters that I need (Least squares, Maximum Likelihood, residual plot. etc…)

you see…there aren’t hit searching these parameters

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/b/8/b8df3c486cdda9a41df4cd29ad7c955b31feccac.png)

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/d/7d5689b21d05691cac3b74c412f2856539d52ae5.png)

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/d/9/d938546a8489dd8baf6c9f39c3d954b7fc541ad2.png)

---

<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 28, 2021, 4:34pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/4 "2021-06-28T16:34:53Z")

</div>

Hi,  
Are you doing a binned maximum likelihood fit or a least square fit of an histogram ?  
If doing a maximum likelihood fit, [MinFcnValue()](https://root.cern.ch/doc/master/classROOT_1_1Fit_1_1FitResult.html#aa3c2936cf4ff867548f0c482762a7dbf) will return the maximum likelihood value, while [Chi2()](https://root.cern.ch/doc/master/classROOT_1_1Fit_1_1FitResult.html#a7c9f32548341b056c97dbcc767dcd5e2) will return the corresponding chi2 (least-square value)… If doing a least square fit the two function will return the same value.

For the residual plot, look at TRatioPlot, [ROOT: TRatioPlot Class Reference](https://root.cern.ch/doc/master/classTRatioPlot.html)

Lorenzo

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 28, 2021, 4:54pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/5 "2021-06-28T16:54:42Z")

</div>

Hello @moneta…I will explain…

This is the fit

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/f/1f66108404fbf2f6d8bf8c5b1e4775093396d204.png)

we used this image for the submission of an article and the referee asked us these parameters…he wrotes:

> _ **It would be useful to include the details of the fit: Least squares, Maximum Likelihood, fit goodness, residual plot. etc…** _

Therefore, being the request of a referee, I’ve to get all these details (least squares, maximum likelihood, fit goodness and residual plot)

> [@moneta](#):
>
> Hi,  
> Are you doing a binned maximum likelihood fit or a least square fit of an histogram ?

I don’t know…I will show you the macro…I fitted in this way

```auto
TF1 *fitgaus = new TF1("fitgaus", "gaus", 0,4000);
			auto result= hene4subsum->Fit("fitgaus","S");

```

and this is the full code for the graph

```
TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1280);
		t->SetLineColor(kBlue);
		TCut cutsubdet = TString::Format("subdet==%d ", subdetnumb).Data();
		TCut cutxhmin = TString::Format("xh>%d ", xhmin).Data();
		TCut cutxhmax = TString::Format("xh<%d ", xhmax).Data();
		TString hene4substringsum = TString::Format("Calo_EnDep[%d] >> htemp(200., 0., 4000.)", c);
		t->Draw(hene4substringsum, cut && cut3sub && cut4sub && cutsubdet && cutxhmin && cutxhmax);
	 	gPad->Modified();
		gPad->Update(); // make sure it's really (re)drawn
		//t->GetHistogram()->SetTitle(cdenenamesum);
		t->GetHistogram()->SetTitle("");
		TH1F *hene4subsum = (TH1F*)gPad->GetPrimitive("htemp"); 
		hene4subsum ->GetXaxis()->SetTitle(cdeneXnameab); 
		hene4subsum ->GetYaxis()->SetTitle(cdeneYnameab);
		hene4subsum ->GetYaxis()->SetTitleSize(c_YTitleSize);
		hene4subsum ->GetYaxis()->SetTitleFont(c_YTitleFont);
		hene4subsum ->GetYaxis()->SetTitleOffset(c_YTitleOffset);
		hene4subsum ->GetYaxis()->SetLabelFont(c_YLabelFont); 
		hene4subsum ->GetYaxis()->SetLabelSize(c_YLabelSize);
		hene4subsum ->GetXaxis()->SetTitleSize(c_XTitleSize);
		hene4subsum ->GetXaxis()->SetTitleFont(c_XTitleFont);
		hene4subsum ->GetXaxis()->SetTitleOffset(c_XTitleOffset);
		hene4subsum ->GetXaxis()->SetLabelFont(c_XLabelFont); 
		hene4subsum ->GetXaxis()->SetLabelSize(c_XLabelSize);
		hene4subsum ->SetFillColorAlpha(kBlue, heneabfillcolor);
		hene4subsum ->Draw("E");
		TF1 *fitgaus = new TF1("fitgaus", "gaus", 0,4000);
		auto result= hene4subsum->Fit("fitgaus","S");
		double chi2 = result->Chi2(); 
		double ndf = result->Ndf(); 
		hene4subsum ->SetName(heneabname);
		gPad->Modified();
		gPad->Update(); // make sure it's really (re)drawn
		TLegend* legene4subsum = new TLegend(0.15, 0.85, .30, .75);
		legene4subsum ->SetHeader("Legend");
		legene4subsum ->SetNColumns(1);
		legene4subsum ->AddEntry(hene4subsum , "Data", "l");
		legene4subsum->AddEntry(fitgaus, "Fit", "l"); 
		legene4subsum ->Draw(); 
		gPad->Update();
		gPad->Update();
		c19->Print(myploteneout4subsum);
		std::cout << "Chi2 : " << chi2 << std::endl;
		std::cout << "Ndf " << ndf << std::endl;
		results << "Chi2 : " << chi2 << endl;
		results << "Nfd " << ndf<<endl;
		delete c19;	

```

here the macro…it makes several plots, but this fit is the last one (lines 1356-1402)  
[calocal.cpp](https://root-forum.cern.ch/uploads/short-url/g3HsT8GTkH4RK5vLNxV4TCw1HJD.cpp) (68.4 KB)

---

<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 29, 2021, 8:20am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/6 "2021-06-29T08:20:51Z")

</div>

Hi,

Thank you , I understand it now.  
You are doing a default fit of an histogram. Then the fit is a `Least squares fit` using as error for the data point the square root of the observed events.  
The fit goodness (chi2 and ndf) you obtain from the fit result, as you are doing in the macro.  
The problem with the least square fits are the bins with very small or zero entries. The fit method of ROOT exclude bins with zero entries, but this creates a small bias.  
A more correct approach for fitting histogram with counts is to use the binned maximum likelihood method (option `L`). When doing this you can compute for goodness of fit a chi2 from 2 \* maximum likelihood value at the minimum. Since the empty bins are used in the fit, the number of degree of freedom will include now also the empty bins. However, be aware that if you have a large number of empty bins the obtained chi2 value will deviate from following a chi2 distribution.  
I attach an example on fitting with the two methods and on how to make a residual plot

Cheers

Lorenzo

[exampleFitHistogram.C](https://root-forum.cern.ch/uploads/short-url/9NmeIz5Zj1WLz1NHgpXmZuQ66zv.C) (1.1 KB)

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 29, 2021, 9:58am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/7 "2021-06-29T09:58:51Z")

</div>

Dear @moneta thank you.

1. I tried to fit by Maximum likelihood,

```auto
	TF1 *fitgaus = new TF1("fitgaus", "gaus", 0,4000);
			auto result= hene4subsum->Fit("fitgaus","S L");

```

but  
a. you see, the function doesnt’ fit well data in this way

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/0/e/0e6c162952a1ccb20ac9ce0cb0ae84154ab4c984.png)

b.   
`double chi2 = 2* result->MinFcnValue();`  
gives chi2=1620.75  
instead, you see…in the stat box chi2=1932

![image](https://root-forum.cern.ch/uploads/default/original/3X/9/7/97d2a55bf1e6ead6427658d709d3d48f0db79ce3.png)

1. 

Adding these lines

```auto
	auto rp2 = new TRatioPlot(hene4subsum);
   			rp2->Draw();

```

to make the residual plot I get this error, but in this case, the main plot loses the “E” option

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/5/c56851bb19aa651716f36f3dd15dc6c56e5f8c66.png)

even if I write  
`	rp2->Draw("E");`

```auto
TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1280);
 			t->SetLineColor(kBlue);
 			TCut cutsubdet = TString::Format("subdet==%d ", subdetnumb).Data();
 			TCut cutxhmin = TString::Format("xh>%d ", xhmin).Data();
 			TCut cutxhmax = TString::Format("xh<%d ", xhmax).Data();
 			TString hene4substringsum = TString::Format("Calo_EnDep[%d] >> htemp(200., 0., 4000.)", c);
			t->Draw(hene4substringsum, cut && cut3sub && cut4sub && cutsubdet && cutxhmin && cutxhmax);
		 	gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			//t->GetHistogram()->SetTitle(cdenenamesum);
			t->GetHistogram()->SetTitle("");
			TH1F *hene4subsum = (TH1F*)gPad->GetPrimitive("htemp"); 
			hene4subsum ->GetXaxis()->SetTitle(cdeneXnameab); 
			hene4subsum ->GetYaxis()->SetTitle(cdeneYnameab);
			hene4subsum ->GetYaxis()->SetTitleSize(c_YTitleSize);
			hene4subsum ->GetYaxis()->SetTitleFont(c_YTitleFont);
			hene4subsum ->GetYaxis()->SetTitleOffset(c_YTitleOffset);
			hene4subsum ->GetYaxis()->SetLabelFont(c_YLabelFont); 
			hene4subsum ->GetYaxis()->SetLabelSize(c_YLabelSize);
			hene4subsum ->GetXaxis()->SetTitleSize(c_XTitleSize);
			hene4subsum ->GetXaxis()->SetTitleFont(c_XTitleFont);
			hene4subsum ->GetXaxis()->SetTitleOffset(c_XTitleOffset);
			hene4subsum ->GetXaxis()->SetLabelFont(c_XLabelFont); 
			hene4subsum ->GetXaxis()->SetLabelSize(c_XLabelSize);
			hene4subsum ->SetFillColorAlpha(kBlue, heneabfillcolor);
			hene4subsum ->SetStats(0);
			hene4subsum ->Draw("E");
			TF1 *fitgaus = new TF1("fitgaus", "gaus", 0,4000);
			auto result= hene4subsum->Fit("fitgaus","S L");
			double chi2 = 2* result->MinFcnValue(); //
			double ndf = result->Ndf(); 
   		//	double chi2 = result->Chi2(); // Least squares fit (i.e. without L option)
			hene4subsum ->SetName(heneabname);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
   			TLegend* legene4subsum = new TLegend(0.15, 0.85, .30, .75);
   			legene4subsum ->SetHeader("Legend");
			legene4subsum ->SetNColumns(1);
			legene4subsum ->AddEntry(hene4subsum , "Data", "l");
			legene4subsum->AddEntry(fitgaus, "Fit", "l");  
			legene4subsum ->Draw(); 
			gPad->Update();
			gPad->Update();
			auto rp2 = new TRatioPlot(hene4subsum);
   			rp2->Draw("E");
   			gPad->Update();
			gPad->Update();
			c19->Print(myploteneout4subsum);
			std::cout << "Chi2 : " << chi2 << std::endl;
  			std::cout << "Ndf " << ndf << std::endl;
   			results << "Chi2 : " << chi2 << endl;
   			results << "Nfd " << ndf<<endl;
			delete c19;

```

Lastly, in your macro there is the statbox, but, if I plot with the statbox (i.e. I don’t add

`hene4subsum ->SetStats(0);`

I get this error

`Error in <TRatioPlot::BuildLowerPlot>: h1 does not have a fit function`

---

<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:** [June 29, 2021, 10:10am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/8 "2021-06-29T10:10:17Z")

</div>

@moneta In [your example macro](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/6), if you set “`gStyle->SetOptFit();`”, in the “statistics box” of the “Maximum Likelihood Fit” you will see “`chi2 / ndf`” which is completely different from “`2 * FCN`”. The value that is displayed is the same as returned by “`result2->Chi2()`”.

---

<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 29, 2021, 10:23am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/9 "2021-06-29T10:23:14Z")

</div>

Hi,  
@Wile_E_Coyote Good point! This should be fixed, since the displayed chi2 is the Least Square value and not the 2 \* likelihood ratio value, called sometimes Baker-Cousins chi2 (see their [paper](https://www.sciencedirect.com/science/article/abs/pii/0167508784900164) ).

I will make a PR fixing this

Lorenzo

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 29, 2021, 10:27am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/10 "2021-06-29T10:27:17Z")

</div>

Hi @moneta

> [@moneta](#):
>
> Hi,  
> @Wile_E_Coyote Good point! This should be fixed, since the displayed chi2 is the Least Square value and not the 2 \* likelihood ratio value, called sometimes Baker-Cousins chi2 (see their [paper](https://www.sciencedirect.com/science/article/abs/pii/0167508784900164) ).
> 
> I will make a PR fixing this
> 
> Lorenzo

This replies also to my problem 1b in my previous message.  
Instead, is there a way to solve:

The problem 1a (i.e. the maximum likelihood doesn’t fit well) as you can see here

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/0/e/0e6c162952a1ccb20ac9ce0cb0ae84154ab4c984.png)

1. Adding the residual plot it loses the “E” drawing and the legend option as you can see here

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/5/c56851bb19aa651716f36f3dd15dc6c56e5f8c66.png)

---

<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 29, 2021, 10:47am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/11 "2021-06-29T10:47:45Z")

</div>

1 ) The fit is bad because you are having a large non gaussian tail. You should consider modifying your fit function to include the tails, or you can fit in a restricted range, but it will be a biased fit.  
When using the Least squares fit (default case in ROOT) the tails are under-estimated because bins with zero entries are not considered.

1. For fixing legend you should draw the legend in the upper pad using `gPad=ratioPlot->GetUpperPad()` before drawing the legend.  
For fixing the histogram drawing option use `ratioPlot->SetH1DrawOpt("E")`

Lorenzo

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [June 29, 2021, 12:22pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/12 "2021-06-29T12:22:56Z")

</div>

HEllo @moneta thank you.  
I restricted the range and now the fit looks like good

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/0/c0e8c49c3cd18775996b682be69c9d3a72064c2b.png)

The fit results are  
_ **Chi2 = 220.492** _  
_ **Nfd =57** _

it doesn’t look like a high value…then I think it’s a good result

Just two last questions please,

1. if I want the statbox, the macro crashes with this error

`Error in <TRatioPlot::BuildLowerPlot>: h1 does not have a fit function`

1. Is there a way to define the y-axis range of the residual plot? (now it’s [-0.8;0.8], but I would enlarge it  
I wrote

```auto
rp-SetMinimum(-1);
			rp->SetMaximum(1);

```

but it doewn’t works

```auto
TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1280);
 			t->SetLineColor(kBlue);
 			TCut cutsubdet = TString::Format("subdet==%d ", subdetnumb).Data();
 			TCut cutxhmin = TString::Format("xh>%d ", xhmin).Data();
 			TCut cutxhmax = TString::Format("xh<%d ", xhmax).Data();
 			TString hene4substringsum = TString::Format("Calo_EnDep[%d] >> htemp(60., 2800., 4000.)", c);
			t->Draw(hene4substringsum, cut && cut3sub && cut4sub && cutsubdet && cutxhmin && cutxhmax);
		 	gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			//t->GetHistogram()->SetTitle(cdenenamesum);
			t->GetHistogram()->SetTitle("");
			TH1F *hene4subsum = (TH1F*)gPad->GetPrimitive("htemp"); 
			hene4subsum ->GetXaxis()->SetTitle(cdeneXnameab); 
			hene4subsum ->GetYaxis()->SetTitle(cdeneYnameab);
			hene4subsum ->GetYaxis()->SetTitleSize(c_YTitleSize);
			hene4subsum ->GetYaxis()->SetTitleFont(c_YTitleFont);
			hene4subsum ->GetYaxis()->SetTitleOffset(c_YTitleOffset);
			hene4subsum ->GetYaxis()->SetLabelFont(c_YLabelFont); 
			hene4subsum ->GetYaxis()->SetLabelSize(c_YLabelSize);
			hene4subsum ->GetXaxis()->SetTitleSize(c_XTitleSize);
			hene4subsum ->GetXaxis()->SetTitleFont(c_XTitleFont);
			hene4subsum ->GetXaxis()->SetTitleOffset(c_XTitleOffset);
			hene4subsum ->GetXaxis()->SetLabelFont(c_XLabelFont); 
			hene4subsum ->GetXaxis()->SetLabelSize(c_XLabelSize);
			hene4subsum ->SetFillColorAlpha(kBlue, heneabfillcolor);
			//hene4subsum ->SetStats(0);
			hene4subsum ->Draw("E");
			TF1 *fitgaus = new TF1("fitgaus", "gaus", 2800,4000);
			auto result= hene4subsum->Fit("fitgaus","S L");
			//auto result= hene4subsum->Fit("fitgaus","S");
			double chi2 = 2* result->MinFcnValue(); //
			double ndf = result->Ndf(); 
   		//	double chi2 = result->Chi2(); // Least squares fit (i.e. without L option)
			hene4subsum ->SetName(heneabname);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
		//	gPad=ratioPlot->GetUpperPad();
			gPad->Update();
			auto rp = new TRatioPlot(hene4subsum);
			rp->SetH1DrawOpt("E");
   			rp->Draw();
   			gPad->Update();
   			gPad=rp->GetUpperPad();
   			gPad->Update(); // make sure it's really (re)drawn
   			TLegend* legene4subsum = new TLegend(0.15, 0.85, .30, .75);
   			legene4subsum ->SetHeader("Legend");
			legene4subsum ->SetNColumns(1);
			legene4subsum ->AddEntry(hene4subsum , "Data", "l");
			legene4subsum->AddEntry(fitgaus, "Fit", "l");  
			legene4subsum ->Draw(); 
			gPad->Update();
			gPad->Update();
			c19->Print(myploteneout4subsum);
			std::cout << "Chi2 : " << chi2 << std::endl;
  			std::cout << "Ndf " << ndf << std::endl;
   			results << "Chi2 : " << chi2 << endl;
   			results << "Nfd " << ndf<<endl;
			delete c19;

```

---

<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 29, 2021, 5:23pm UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/13 "2021-06-29T17:23:49Z")

</div>

Hi,

You can do `rp->GetLowerRefYaxis()->SetRange(...)` , there might be examples in the `TRatioPlot` reference documentation.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [July 2, 2021, 5:59am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/14 "2021-07-02T05:59:30Z")

</div>

> [@moneta](#):
>
> `rp->GetLowerRefYaxis()->SetRange(...)`

Hello @moneta, I tried

```auto
auto rp = new TRatioPlot(hene4subsum);
			rp->GetLowerRefYaxis()->SetRange(-1.,1.);
			rp->SetH1DrawOpt("E");
   			rp->Draw();

```

but I get this error

`Error in <TRatioPlot::GetLowerRefGraph>: Lower pad does not have primitives`

and I get the same error using

`rp->GetLowerRefYaxis()->SetTitle("Ratio");`

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 2, 2021, 6:49am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/15 "2021-07-02T06:49:50Z")

</div>

As shown in [this example](https://root.cern/doc/master/ratioplot2_8C.html) `GetLowerRefYaxis` needs the lower plot. The lower plot is produce bye `Draw` . So call `GetLowerRefYaxis` after `Draw`.

---

<div class="post-metadata">

**Author:** ![faca87](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/b19c9b/32.png) [@faca87](https://root-forum.cern.ch/u/faca87)\
**Post date:** [July 2, 2021, 9:09am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/16 "2021-07-02T09:09:09Z")

</div>

Thank you @couet it worked

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 16, 2021, 9:09am UTC](https://root-forum.cern.ch/t/getting-details-of-a-gaussian-fit/45580/17 "2021-07-16T09:09:16Z")

</div>

Closed on July 16, 2021, 9:09am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
