Root Histograms/Canvases in Xcode

I’ve been having a bit of trouble with drawing ROOT histograms and canvases with my code in Xcode on my Mac. From what I understand about histograms, this code

TH1D* h1 = new TH1D("h1", "", 50, 0, 100);
TCanvas* c1 = new TCanvas("c1", "", 300, 300);
c1->cd();
h1->Draw();

should create a new window for the canvas and put an empty histogram on it. Instead, nothing comes up at all. Something I can do is use this line

TApplication* app = new TApplication(“app”, &argc, argv);

at the beginning of the code and this line

app->Run(true);

at the end, and that pulls up the histogram. The problem is that I want to be able to see the histograms change over time (by updating the canvas) but lines after app->Run won’t happen until I quit the opened window. Is there something about Xcode that interferes with the opening of new windows, or do I need to do something entirely different to pull up the histogram? Honestly, this is my first time using Root, so I’m a bit confused.

Hi,

osx and xcode are not related to the way in which histograms are built and drawn.
I’d proceed step by step here. For example, the code

TH1D* h1 = new TH1D("h1", "", 50, 0, 100);
TCanvas* c1 = new TCanvas("c1", "", 300, 300);
c1->cd();
h1->Draw();

Does show a window with a canvas displaying an empty histogram. How did you run the lines? At the command line prompt? In a ROOT macro?

D

I just used the “Run” option in the Xcode IDE. I have given Xcode access to the relevant Root libraries so that the IDE can use the correct functions. I’m thinking that the IDE might run the code slightly differently than the command line would, but I don’t see why it would do that. Another possibility is that I left out an important ROOT library on accident, but, since all the functions are recognized by Xcode, I don’t really see how that could have happened.

When I ran the code you provided in the IDE, nothing happened. If I open up the command line and run it directly in Root, I do get the blank histogram. So something is going wrong in the IDE, presumably.

Thank you so much for taking the time to help with my problem, by the way.

Hi,

sure.
The code I provided is your code by the way. I would leave aside the IDE for the moment and proceed with simpler executions until the idiosyncrasies are understood.

Danilo