Problem with THStack "pads" saving as pdf

Hi, I am having problems when trying to save a large TCanvas as a pdf. On the TCanvas I have drawn a THStack using the “pads” option. When I do it interactively (in PyROOT), the canvas on the X11 window draws properly, and I can re-draw the thing when I save the canvas as a .C or .root file.

When I save it as a pdf however, I get weird results: only some of the pads are visible, and it’s different when I re-run the script. Likely somewhere the subpads are being deleted before the file is saved?

I have attached the .pdf, .C, and .root files with the canvas.

The PyROOT code that does the drawing looks like this:

    c2 = ROOT.TCanvas("c2", "c2", 1600, 1200)
    c2.cd()
    hs.Draw("pads")
    ROOT.gPad.Modified()
    ROOT.gPad.Update()
    outname = "FitSlicesOfX_%dth_run%05d.pdf" % (corr_order, run)
    c2.SaveAs(os.path.join(outdir, outname))

Do experts think this is a PyROOT issue (e.g. hs goes out of scope while the file is still saving or something?), or a problem with pdf output?

I am using ROOT 5.34/18 in OSX 10.9.5.

Jean-François
FitSlicesOfX_0th_run00500.pdf (522 KB)
FitSlicesOfX_0th_run00500.root (265 KB)
FitSlicesOfX_0th_run00500.C (811 KB)

I decided to also try saving as .eps and .png and those turn out fine, so I don’t think it’s a PyROOT issue.

Any ideas as to why the pdf format in particular would fail here? In a different part of the code I make an equivalently-heavy THStack “pads” canvas and it turns out fine.

Jean-François

I see the failure on my mac too. No idea why… yet … I will check.

I tried to reproduce your problem using the following macro. It also produces a 14x14 stack.

{
   THStack *hs = new THStack("hs","Stacked 1D histograms");

   const int n = 196;

   TH1F *h[n];

   for (int i=0; i<n;i++) {
      h[i]  = new TH1F(Form("h%d",i), Form("h%d",i), 100, -4, 4);
      h[i]->FillRandom("gaus",20000);
      hs->Add(h[i]);
   }

   TCanvas *cst = new TCanvas("cst","stacked hists",0,0,900,900);
   hs->Draw("pads");
}

With this macro the pdf file is fine. So I suspect the problem does not come from the stack. Your .C file comes from a Save As… therefore it is a bit hard to read. By Chance would be the original macro a bit easier to debug ?
If it is too complex to extract from your analysis framework I will debug the .C you sent me… It may just take a bit of time …

The problem comes from these huge histogram titles you have in that macro…
I now have to find what is wrong there.
No need to provide the original macro. I was able to strip down your big macro to something more manageable.

Attached is the minimal macro reproducing the problem.
long_title.C (1.06 KB)

This problem is now fixed in: Root5.34/24 , Root6.02/02 and Root6.03/01 (head)
Thanks for reporting.

Sorry for not answering your questions, all that happened while I was sleeping!

Thanks for the fix. My huge histogram titles probably arose because they were created from a TH2::ProjectionY, and the TH2 was produced with a TTree::Draw command with some non-trivial cuts.

Jean-François

Yes surely. It was good it arose because it exhibit a bug in TPDF :slight_smile: