Should several TCanvas::SaveAs depend on the order in which they are called

Hi,

I was playing around with roofit tutorial 108 and added at the bottom these lines:

  // Draw plots on canvas
  TCanvas* c = new TCanvas("rf108_plotbinning","rf108_plotbinning",800,400) ;
  c->Divide(2) ;
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; dtframe->GetYaxis()->SetTitleOffset(1.6) ; dtframe->Draw() ;
  c->cd(2) ; gPad->SetLeftMargin(0.15) ; aframe->GetYaxis()->SetTitleOffset(1.6) ; aframe->Draw() ;
  c->SaveAs("blub.C");
  c->SaveAs("blub2.C");
  c->SaveAs("blub2.pdf");
  c->SaveAs("blub3.C");

(using root 6.07/04, self built from git)

And compared the macros.
Observations:
[ul][li]when just calling the macros the first canvas is larger than the others[/li]
[li]the title font looks larger in the third[/li][/ul]
variable names aside, the actual macros differ in the following places. blub.C and blub2.C

-     TCanvas *rf108_plotbinning = new TCanvas("rf108_plotbinning", "rf108_plotbinning",0,0,800,400);
+    TCanvas *rf108_plotbinning = new TCanvas("rf108_plotbinning", "rf108_plotbinning",1,1,800,376);            

(afterwards, blub2.C and blub3.C have the same TCanvas constructor)

comparing blub2.C to blub3.C, blub3.C has a lot more code

    rf108_plotbinning_1->SetFrameBorderMode(0);

gets called twice in blub3.C

   TH1F *Graph_bmix_AsymoBmixStatecB6 = new TH1F("Graph_bmix_AsymoBmixStatecB6","mixState Asymmetry of dec
   Graph_bmix_AsymoBmixStatecB6->SetMinimum(-0.9585547);
   Graph_bmix_AsymoBmixStatecB6->SetMaximum(0.9589456);
   Graph_bmix_AsymoBmixStatecB6->SetDirectory(0);
   Graph_bmix_AsymoBmixStatecB6->SetStats(0);

   ci = TColor::GetColor("#000099");
   Graph_bmix_AsymoBmixStatecB6->SetLineColor(ci);
   Graph_bmix_AsymoBmixStatecB6->GetXaxis()->SetLabelFont(42);
   Graph_bmix_AsymoBmixStatecB6->GetXaxis()->SetLabelSize(0.035);
   Graph_bmix_AsymoBmixStatecB6->GetXaxis()->SetTitleSize(0.035);
   Graph_bmix_AsymoBmixStatecB6->GetXaxis()->SetTitleFont(42);
   Graph_bmix_AsymoBmixStatecB6->GetYaxis()->SetLabelFont(42);
   Graph_bmix_AsymoBmixStatecB6->GetYaxis()->SetLabelSize(0.035);
   Graph_bmix_AsymoBmixStatecB6->GetYaxis()->SetTitleSize(0.035);
   Graph_bmix_AsymoBmixStatecB6->GetYaxis()->SetTitleFont(42);
   Graph_bmix_AsymoBmixStatecB6->GetZaxis()->SetLabelFont(42);
   Graph_bmix_AsymoBmixStatecB6->GetZaxis()->SetLabelSize(0.035);
   Graph_bmix_AsymoBmixStatecB6->GetZaxis()->SetTitleSize(0.035);
   Graph_bmix_AsymoBmixStatecB6->GetZaxis()->SetTitleFont(42);
   graph->SetHistogram(Graph_bmix_AsymoBmixStatecB6);

blub.C and blub2.C don’t have any TH1 at all.


   pt = new TPaveText(0.15,0.9291672,0.85,0.995,"blNDC");
   pt->SetName("title");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetFillStyle(0);
   pt->SetTextFont(42);
   AText = pt->AddText("mixState asymmetry distribution with custom binning");
   pt->Draw();

again, blub.C and blub2.C don’t create any TText or TPaveText at all.

Is it expected that the output of TCanvas::SaveAs(“foobar.C”) depends on previous SaveAs calls?
rf108_plotbinning.C (4.13 KB)
blub3.C (25.6 KB)
blub2.C (19.2 KB)
blub.C (19.2 KB)

bumping this thread.

still wondering if this is a bug of TCanvas::SaveAs.

do you need Roofit to get this problem ?

histograms seem to be fine, but with a TGraph (root.cern.ch/doc/master/classTGraph.html) I see a difference between blub.C and blub3.C.

/// run with `root -l -b -q -n checkit.C
void checkit() {
  TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
  Double_t x[100], y[100];
  Int_t n = 20;
  for (Int_t i=0;i<n;i++) {
    x[i] = i*0.1;
    y[i] = 10*sin(x[i]+0.2);
  }
  auto gr = new TGraph(n,x,y);
  gr->Draw("AC*");

  c1->SaveAs("blub.C");
  c1->SaveAs("blub2.C");
  c1->SaveAs("blub2.pdf");
  c1->SaveAs("blub3.C");
}

I see that blub3.C is very different. It contains in addition the definition of the underlying histogram used by the TGRaph: Graph_Graph03
This is triggered by the saving in the pdf file just before. I have not idea why … (yet) … note that the graphics generated, when you execute back the 3 “bulb”, is the same.