Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 but can't see it in windows

Here is a case in Guide:

TF1 efunc("efunc","exp([0]+[1]*x)",0.,5.);
efunc.SetParameter(0,1);
efunc.SetParameter(1,-1);
TH1F h("h","example histogram",100,0.,5.);
for (int i=0;i<1000;i++) {h.Fill(efunc.GetRandom());}
h.Draw();

and the result is:

Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1

without any Histogram was shown.

ROOT Version: 6.24.02
Platform: Ubuntu
Compiler: Not Provided


Hi,

Can you modify your macro and create objects dynamically:

TF1 efunc("efunc","exp([0]+[1]*x)",0.,5.);
efunc.SetParameter(0,1);
efunc.SetParameter(1,-1);
auto h = new TH1F("h","example histogram",100,0.,5.);
for (int i=0;i<1000;i++) {h->Fill(efunc.GetRandom());}
h->Draw();

Otherwise object is destroyed before it can be painted.

Well, I don’t understand “object is destroyed”. The code is from here:A ROOT Guide For Beginners. Even I tried

auto h = new TH1F("h","example histogram",100,0.,5.);

The result is still

Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1

without any graph

When you creates histogram with:

TH1F h("h","example histogram",100,0.,5.);

it automatically destroyed when leaving function scope.
Canvas rendering performed afterwards - therefore canvas does not “see” such object.

When object created dynamically with new operator, it will remain “alive” and can be rendered.

Does modified code works for you?

No, I still can’t get a histogram like this:


it’s from ROOT Guide I mentioned above.

Very strange, for me following macro works as expected:

tut.cxx (219 Bytes)