Retrieve TPad ranges after DrawFrame

I am adding a vertical line to a ratio plot TPad and want it to go from bottom all the way up to the top of the pad. I successfully achieved this either by getting the y range via pad->GetUymin() / max() or by pad->GetRangeAxis(xmin, ymin, xmax, ymax). However, in our framework we can switch from ratio plot to signal significance plot in which case, I have some difficulties getting the range correctly. The only difference I see in the code, is that in the significance case, a TH1 is plotted to the pad via TH1 *frame = pad->DrawFrame(...) and then, its range is set as frame->GetYaxis()->SetRangeUser(0, maxValue). In this case, with my settings, the vertical line is always drawn only in (0, 1) range for both of my approaches. Is this the desired behaviour or should GetUymin() / max() and GetRangeAxis() return the true y limits?
How can I retrieve the right y range from the TH1 embedded to my pad then?

ROOT Version: v6.24.00
Platform: centos7
Compiler: gcc10


It seems ok for me but may be that’s not the problem you encounter:

void lineonpad() {
   auto C = new TCanvas();
   gPad->DrawFrame(4.,0., 10.,5.);
   auto l = new TLine();
   l->DrawLine(7.,gPad->GetUymin(),7., gPad->GetUymax());
}

Hi, thank you for your prompt reply. This also works for me, but in the code, the DrawFrame() is assigned to a TH1 and new range is then set to this TH1. If I add this to your code, it breaks the ranges:

void lineonpad() {
   auto C = new TCanvas();
   TH1 *frame = gPad->DrawFrame(4.,0., 10.,1.);
   frame->GetYaxis()->SetRangeUser(0,10);
   auto l = new TLine();
   l->DrawLine(7.,gPad->GetUymin(),7., gPad->GetUymax());
}

Is this the wrong approach?

Do:

void lineonpad() {
   auto C = new TCanvas();
   TH1 *frame = gPad->DrawFrame(4.,0., 10.,1.);
   frame->GetYaxis()->SetRangeUser(0,10);
   gPad->Modified(); gPad->Update();
   auto l = new TLine();
   l->DrawLine(7.,gPad->GetUymin(),7., gPad->GetUymax());
}

And I will be fine.

1 Like

Ehh, actually we have this cruical part in our code, but was unfortunately applied just before the Range change. Many thanks for help, it works now!

1 Like