Inconsistent behaviour in manipulating stats

Dear ROOT experts,

If I give in the next code line by line on the command line then I get the desired result, see att., but when I it from its file, as argument to the root executeable, I get an error, see below.

That I find a big inconsistency.

Does anyone know what is going on and more importantly, how can I make this work from a script??

Many thanks in advance,

Ytsen de Boer.

{

TCanvas c;
TH1F h1(“h1”, “h1”, 1, 0, 1);
h1.Fill(.3, .4)

h1.Draw();
TPaveStats* st= (TPaveStats*)gPad->GetPrimitive(“stats”)->Clone();
st->SetName(“new”)
st->SetX1NDC(.6);
st->SetX2NDC(.8);
st->SetY1NDC(.9);
st->SetY2NDC(1.);
st->Draw()
TH1F h2(“h2”,“h2”,2, 0, 1);
h2.Fill(.3, .5); h2.Fill(.7, 0.8);
h2.SetLineColor(2);
h2.Draw();
st->Draw();

};

===============================

[h1mars03] ~/tmp/H1Validation $ root test.stat.C


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.14/00 14 December 2006 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

FreeType Engine v2.1.9 used to render TrueType fonts.
Compiled on 15 December 2006 for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.16.16, November 24, 2006
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing test.stat.C…
Error: illegal pointer to class object GetPrimitive(“stats”) 0x0 3 test.stat.C:8:
*** Interpreter error recovered ***
root [1]




Add the statement

c.Update();after the line

Rene