Hi! I have a very simple C++ program that runs fine in the interpreter, but when I convert it to standalone code, fails to draw the only histogram.
// header imports
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <string>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include "TSystem.h"
#include "TMath.h"
#include "TH1.h"
#include "TRandom3.h"
#include "TCanvas.h"
int main()
{
// Define a new canvas
TCanvas *canvas = new TCanvas("c1", "testing");
//change canvas height
canvas->SetWindowSize(900, 600);
int bin_length = 100;
int i;
TH1 *hist1 = new TH1F("hist1", "this should be a normal histogram", bin_length, 0,4);
canvas->cd(1);
TRandom3 *ran = new TRandom3();
for(i=0;i<30000;i++)
{
hist1->Fill(ran->Gaus(1,1), ran->Gaus(1,1));
}
std::cout << ran->Gaus(1,1) << std::endl;
hist1->Draw();
return 0;
}
The program runs without any errors, compiles with no errors or warnings, and successfully displays a random number. However, it doesn’t display the histogram. Any ideas what might be causing this?
Thanks in advance!