Difference in output from script and CLING

This script:

  gStyle -> SetOptStat(0);
  TH2 * h = new TH2F("h", "h", 5, 0.0, 5.0, 5, 0.0, 5.0);
  h -> Fill(2.0, 2.0);
  TCanvas * c = new TCanvas();
  h -> Draw("COLZ");
  c -> SetRightMargin(0.5);

creates the following plot

However, when the same script is entered as a sequence of commands in CLING and adding

c -> Modified()

in the end the output is a different one

The output from the script is what was really intended.
Why is there such a difference and how to bring the output from CLING in conformity to the output from the script?

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

You MUST “set margins” before you “Draw” anything.

1 Like

@Wile_E_Coyote , In CLING we draw first and then we like to play

The result will depend on whether ROOT decides to “physically draw” something in the middle of your script or not.

@Wile_E_Coyote, I have never completely understood where and why TCanvas::Modified() is needed. Can you explain?

I usually execute:

if (gPad) { gPad->Modified(); gPad->Update(); } // make sure it's really (re)drawn

Let me try to explain:

When you have multiple statements (create a canvas, histogram, set line color, change drawing option etc), there is no interruption that ROOT could use to paint the histogram. gPad->Modified() tells the gPad that it should re-paint itself on the next gPad->Update() call.

In cling, after each input line, the current canvas gets updated automatically. So here, painting (of the histogram and the palette axis) happens before the final SetRightMargin(0.5);, while for the script case, the palette axis is drawn after SetRightMargin(0.5);.

Running c->SetRightMargin(0.5); before h->Draw("COLZ"); fixes this for both cases.

Makes sense?

Cheers, Axel.

1 Like

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