Draw() function not working for Histograms

I am trying to extract data from a tree and put it into a histogram using a c++ program, however I am having the issue that the program creates the TCanvas for the histogram when I use the Draw() function, but I never see a canvas pop up on my screen. For reference, I am using a Windows machine, but am running the code on a linux machine I have connected to using bitvise ssh and am using Xming. I am able to see histograms pop up when I create a TBrowser and click on a branch from the tree. I also tried not even filling the histogram with data from the tree and just trying to get the system to draw a histogram I filled with integers generated by a for loop but that did not work either. I have posted my code below for reference.

int main()
{
        TFile* F = new TFile("Output.root", "READ", "File");

        TTree* T = (TTree*) F->Get("RecTree");

        TH1* Hist = new TH1I("Hist", "Energy", 100, 0, 1.3);

        int i;
        float Energy;

        T->SetBranchAddress("VetoEnergy", &Energy);

        for(i = 0; i < T->GetEntries(); i++)
        {
              T->GetEntry(i);
              Hist->Fill(Energy);
        }
  
        F->Close();

        Hist->Draw();

        return 0;
}

_ROOT Version: 6.18/04
_Platform: Linux and Windows


If Energy is a float in the tree, try instead:

TH1F* Hist = new TH1F("Hist", "Energy", 100, 0, 1.3);

(if it’s double, use TH1D).

Do

TH1* Hist = new TH1I("Hist", "Energy", 100, 0, 1.3);
Hist->SetDirectory(nullptr);

to avoid the histogram from being deleted when the file is Closed.

I tried both approaches and neither worked. I also tried simplifying the code down to

        TH1* Hist = new TH1I("Hist", "Energy", 100, 0, 20);

        int i;
      

        for(i = 0; i <  11; i++)
        {
              Hist->Fill(i);
        }

        Hist->Draw()

and that did not work either. Any suggestions? Thanks.

Try to connect to your Linux machine using ssh -X -Y ... and, if you get no warnings nor errors, as a first test try to start there an xterm (and if you get a new terminal window displayed then it should also work for ROOT).