# Explicitly set error for TRatio plot

**URL:** <https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173>\
**Category:** Newbie\
**Created:** [March 14, 2022, 12:12pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173 "2022-03-14T12:12:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/junkai/32/27450_2.png) [@JunKai](https://root-forum.cern.ch/u/JunKai)\
**Post date:** [March 14, 2022, 12:12pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/1 "2022-03-14T12:12:54Z")

</div>

Hi all, I am trying TRatioPlot recently, where I followed steps from [ROOT: TRatioPlot Class Reference](https://root.cern/doc/master/classTRatioPlot.html).  
However it seems error bars is plotted for h1. What if I want to plot h2/h1 (reverse the arguments to `TRatioPlot(h2,h1)`), with the error bars for h1. Is there any method to explicitly set the plot style ? (something like `HIST C` options, but for individual histogram in the TRatioPlot)

```auto
void ratioplot1() {
   gStyle->SetOptStat(0);
   auto c1 = new TCanvas("c1", "A ratio example");
   auto h1 = new TH1D("h1", "h1", 50, 0, 10);
   auto h2 = new TH1D("h2", "h2", 50, 0, 10);
   auto f1 = new TF1("f1", "exp(- x/[0] )");
   f1->SetParameter(0, 3);
   h1->FillRandom("f1", 1900);
   h2->FillRandom("f1", 2000);
   h1->Sumw2();
   h2->Scale(1.9 / 2.);
   h1->GetXaxis()->SetTitle("x");
   h1->GetYaxis()->SetTitle("y");
   auto rp = new TRatioPlot(h1, h2);
   c1->SetTicks(0, 1);
   rp->Draw();
   rp->GetLowYaxis()->SetNdivisions(505);
}

```

Thanks in advance

* * *

\_ROOT Version: 6.24 (PyROOT via conda)  
\_Platform:Centos7  
\_Compiler: gcc9

* * *

---

<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 14, 2022, 12:28pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/2 "2022-03-14T12:28:58Z")

</div>

```cpp
auto rp = new TRatioPlot(h2, h1);
rp->SetH1DrawOpt("E");
rp->SetH2DrawOpt("HIST C");

```

---

<div class="post-metadata">

**Author:** ![JunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/junkai/32/27450_2.png) [@JunKai](https://root-forum.cern.ch/u/JunKai)\
**Post date:** [March 14, 2022, 2:41pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/3 "2022-03-14T14:41:21Z")

</div>

Thanks for your quick reply.  
I have another question for you:  
How to set auto scale on Y-axis for this TRatio (It can be done automatically with THStack, but how about for the TRatio) ?

---

<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:** [March 14, 2022, 2:52pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/4 "2022-03-14T14:52:27Z")

</div>

I would suggest you put the histogram with the largest maximum in:

```auto
auto rp = new TRatioPlot(h1, h2);

```

---

<div class="post-metadata">

**Author:** ![JunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/junkai/32/27450_2.png) [@JunKai](https://root-forum.cern.ch/u/JunKai)\
**Post date:** [March 14, 2022, 3:06pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/6 "2022-03-14T15:06:53Z")

</div>

That’s exactly my workaround before the post, and it produced an truncated plot like this:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/3/e/3ee6328981ca0bb91996e15ea941cd6f51643b4a.png)

However, what I want to achieve is a plot (lower peak histo) / (higher peak histo) that without being cut at the highest peak (on the upper panel) so I could get a ratio that is in [0,1].

---

<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 14, 2022, 3:43pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/7 "2022-03-14T15:43:22Z")

</div>

If it is just about the plot, try:

```cpp
rp->Draw(); // c1->Modified(); c1->Update();
rp->GetUpperRefYaxis()->SetRangeUser(0., 2500.);

```

---

<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:** [March 14, 2022, 4:15pm UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/8 "2022-03-14T16:15:35Z")

</div>

Or change the maximum of the 1st histogram

---

<div class="post-metadata">

**Author:** ![JunKai](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/junkai/32/27450_2.png) [@JunKai](https://root-forum.cern.ch/u/JunKai)\
**Post date:** [March 15, 2022, 3:40am UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/9 "2022-03-15T03:40:46Z")

</div>

Did you mean `h1->SetMaximum(3000);` ?

---

<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:** [March 15, 2022, 7:23am UTC](https://root-forum.cern.ch/t/explicitly-set-error-for-tratio-plot/49173/10 "2022-03-15T07:23:36Z")

</div>

Yes for instance.
