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
linev
July 2, 2024, 7:32am
2
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
linev
July 2, 2024, 8:03am
4
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.
linev
July 2, 2024, 9:13am
6
Very strange, for me following macro works as expected:
tut.cxx (219 Bytes)
Well, I guess I find the solution. The reason is lacking Xming. Download it and for Win10 the DISPLAY Configuration is
export DISPLAY=localhost:0.0
and for Win11 is
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0