Segfault; after TPad* = TCanvas*->DrawClonePad(), adjusting TPad crashes code

Hello, first time poster here. Sorry if anything in my post goes against the guidelines, i’ve done my best to follow them :slight_smile:.

I have a macro that draws a bunch of histograms/legends/etc. onto single-pad canvases. It does this very well and i’m very happy with it.

Now i’m interested in seeing some of of the hists/ratios on a multi-pad canvas, basically like this. I’d like to use my already-drawn canvases to do this. The following code works and gets me started.

TCanvas* canv_test= new TCanvas("canv_test", "", 2100,1500);   
TPad* pad_spectra = new TPad("pad_spectra", "Overlay Pad", 0.0, 0.30, 1.0, 1.0);
TPad* pad_ratio   = new TPad("pad_ratio"  , "Ratio Pad", 0.0, 0.00, 1.0, 0.30);



So, i’d like the axis on the spectra plot covered by the ratio plot; like the example linked to above. Currently, the way canv_test looks, is there is space left between the bottom pad and the top pad; such that the title of already_drawn_ratio_canv and the axis title of already_drawn_spectra_canv are both clearly visible. I figure i can just adjust the contents of pad_spectra and pad_ratio to do what i need to do after DrawClonePad(), but my code instantly segfaults the second i try to adjust the margins on the pads. Forget calling pad->Update() or pad->Modified() after adjusting, pad->SetBottomMargin() is the line that crashes everything.

technical details;

ROOT Version: 6.02/13
Platform: Scientific Linux 6
Compiler: GCC 4.9.1

Your post follows the guidelines. Thanks for that ! :slight_smile:

Before going further with your code I would like to point you the class TRatioplot which may help you in that case.
Are you aware of it ?
If it doesn’t help you we will look closer at you code.

Hello! Thank you for the reply, i was not aware of TRatioPlot, and it seems like an elegant solution! There does exist a problem or two however.

  1. TRatioPlot seems to have been added to the library in August 2016; but my ROOT release was done in June 2015. Because this is on a university cluster, i can’t simply update the release. I can do a workaround where i copy the output from the cluster to my local CPU (6.08/00, Nov 2016) to use TRatioPlot, but this is a little clunky. Can I ask for a closer look? Even if just for my own understanding.

  2. an unrelated note/issue i noticed 6.02/13 is not in the list of releases. No typo on my end; entering root at the terminal shows 6.02/13.

Thank you for your time.

Yes, you need a version of ROOT having this class. If you are cannot have one easily on your university cluster you will have to make the ratio plot yourself. We kept an old macro making ratio plots without TRatioPlot class. It is here. It may help you.

Thanks! that macro put me in the right direction, i appreciate it.

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