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:
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.
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.
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.