TRatioPlot with TimeDisplay

Dear all,

I’d like to draw the ratio plot with time units.
As attached file below, I created a simple example modified from ‘$ROOTSYS/tutorials/graphs/timeonaxis2.C.’
Actually, only 4 lines add to the original as below,

TH1F h2 =(TH1F)h1->Clone();
h2->Draw(“same”);
//auto rp =new TRatioPlot(h1,h2);
//rp->Draw();

In the case without the ratio plot, the time units draw well.
@couet In the other case, when I activate lines for the ratio plot,
the time units don’t draw.

Would you tell me how to do it?

Best regards,
Hide

_ROOT Version: 6.20/04
_Platform: CentOS Linux release 7.8.2003 (Core)
_Compiler: GCC 4.9.3

timeonaxis2.C (1.0 KB)

Hello Hide,

@couet is indeed the right person to ask, but this week, he’s on vacation. Can you ping us here in this thread on Monday?

If you are ready to endure some pain, you can try to play with (it will display “time units”):
${ROOTSYS}/tutorials/hist/ratioplotOld.C

Thanks for your quick reply!

I merged two examples (ratioplotOld.C and timeonaxis2.C).
Actually as attached file below, I realize the ratio plot with time units.

But this method is complicated (there are many steps to draw the plot),
so I’d like to use TRatioPlot class.

Is there any other way with TRatioPlot class.

Best regards,
Hide

ratioplotOld.C (3.9 KB)

Why don’t you use GetLowerRefXaxis from TRatioplot and change it into a time axis ?

Have you tried it?

No. just an idea.

I did and I then advised to try the old tutorial. :wink:

Thanks for your suggestion!

But your mentioned method does not work as attached file below. Is there any other way?

Best regards,
Hide
timeonaxis2.C (1.2 KB)

Yes @Wile_E_Coyote tried and it doesn’t not work. Try what he suggested with the old ratio plot command.

Thanks for your quick reply!
I got it. I will use the old ratio plot command.

Best regards,
Hide

@couet Reusing the ${ROOTSYS}/tutorials/hist/ratioplotOld.C with different histograms is a bit painful. I would like to propose the following improvement:

#if ROOT_VERSION_CODE >= ROOT_VERSION(6,8,0)
   // Avoid the first label (0) to be clipped.
   TAxis *axis = h1->GetYaxis();
   axis->ChangeLabel(1, -1, -1, -1, -1, -1, " ");
   axis->SetLabelFont(43); // Absolute font size in pixel (precision 3)
   axis->SetLabelSize(15);
#else
   // Do not draw the Y axis label on the upper plot and redraw a small
   // axis instead, in order to avoid the first label (0) to be clipped.
   h1->GetYaxis()->SetLabelSize(0.);
   TGaxis *axis = new TGaxis( -5, 20, -5, 220, 20,220,510,"");
   axis->SetLabelFont(43); // Absolute font size in pixel (precision 3)
   axis->SetLabelSize(15);
   axis->Draw();
#endif

ratioplotOld.C (3.5 KB)

In ratioplotOld.C ? may be you can create a PR with that ?

Your macro does not work on Mac:

root [0] 
Processing ratioplotOld.C...
In file included from input_line_12:1:
/Users/couet/git/couet-root/tutorials/hist/ratioplotOld.C:33:42: error: invalid digit '8' in octal constant
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,08,00)
                                         ^
root [1] 

On the way:

Dear all,

I’m sorry for reviving this topic, but could you explain the reason why 0 is clipped in that example?

The comment in ratioplotOld.C says Avoid the first label (0) to be clipped., however the solution results in removing 0 and not avoiding it to be clipped (i.e. it disappears in my macro).

I indeed tried to use TRatioPlot, but it messes up with the style of my plots using CMS tdrstyle.C, so I went with the good old TPad solution. In my particular case I’m leaving a gap between the upper and ratio histograms and the gap indeed clips both 0 and top label of the ratio plot. I noticed that when I do:

canv->GetFrame()->Draw()

a border is drawn around that gap, which gave me a hint to fixed it, however I couldn’t manage to remove it or remove the fill color.

Cheers, Gustavo

Yes that’s the point the “0” is removed because in that example if it is not removed it appears as clipped.

Thanks for confirming.

In a hope to use TRatioPlot, is there a way to use it without affecting the margins? I’m trying to find a way to avoid resetting margins by hand because part of my plots won’t have a ratio.

Cheers, Gustavo

The plot you are trying to achieve doesn’t seem to be a standard TRatioPlot. If only part of your plot has a ratio some special tuning might be necessary. That should be seen…

I shall reveal the unseen…

For plots with ratio plot, I split the canvas like:

  // Split canvas if dualPlot
  if (dualPlot) {
      canv->Divide(1,2);
      // top pad
      TPad *canv_1 = (TPad*)(canv->GetPad(1));
      canv_1->SetPad(0.,.31,1.,1.);
      canv_1->SetTopMargin( 1.5*T/H );
      canv_1->SetRightMargin( R/W );
      canv_1->SetBottomMargin(0.);
      canv_1->SetLeftMargin( L/W );
      canv_1->SetFillColor(0);
      // bottom pad
      TPad *canv_2 = (TPad*)(canv->GetPad(2));
      canv_2->SetPad(0.,0.,1.,.29);
      canv_2->SetBottomMargin(0.4);
      canv_2->SetRightMargin( R/W );
      canv_2->SetLeftMargin( L/W );
      canv_2->SetTopMargin(0.);
      canv_2->SetFillColor(0);
      gStyle->SetPadTickX(1);
      gStyle->SetPadTickY(1);
      canv->cd(1);
  }

and after drawing the histograms in the upper pad, I then draw the ratio plot in the lower pad as:

  // Draw ratio plot
  if (dualPlot) {
      canv->cd(2);
      TH1D *ratio = (TH1D*)(full->Clone());
      ratio->Divide(direct);
      ratio->Draw("HIST");
      ratio->SetStats(false);
      ratio->SetLineColor(1);
      ratio->SetLineWidth(2);
      ratio->SetMarkerStyle(20);
      ratio->SetMaximum(1.2*ratio->GetMaximum());
      ratio->SetMinimum(0.8*ratio->GetMinimum());
      // X
      ratio->GetXaxis()->SetLabelSize(0.15);
      ratio->GetXaxis()->SetTitleSize(0.175);
      ratio->GetXaxis()->SetTitleOffset(1.);
      ratio->GetXaxis()->SetNdivisions(6,5,0);
      // Y
      ratio->GetYaxis()->SetLabelSize(0.1);
      ratio->GetYaxis()->CenterTitle(true);
      ratio->GetYaxis()->SetTitleSize(0.125);
      ratio->GetYaxis()->SetTitleOffset(0.3);
      ratio->GetYaxis()->SetNdivisions(5,1,0);
  }

I send attached an example where the TFrame (?) is filling the gap between the pads. I mention a TFrame because I see the left-right borders if I use:

canv->GetFrame()->Draw();

Cheers, Gustavo