Do you know how I can open my graphs and histograms directly from my C++ code?
Right know I need to open root then TBrowser and select the canvas. I would like to skip this part and show the graph right after compilation, is that possible?
I tried system(“root”) which runs root but I can’t open the canvas then
When I do my_graph->Draw() nothing appears. I need to open a terminal, run root and then new TBrowser always in the terminal and find my canvas c1 to see my graph.
Even with c1->Update(); I can’t show the graph, no frame appears. I can show the graph when I open root in a new terminal but I would like to open the graph after compilation
#include <iostream>
#include "TROOT.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TH1F.h"
#include "TBrowser.h"
#include "TFrame.h"
using namespace std;
int main(int argc, char *argv[])
{
TCanvas *c1 = new TCanvas("c1", "c1", 200, 10, 1280, 720);
TH1F h1("h1","Histo from a Gaussian",100,-3,3);
h1.FillRandom("gaus", 10000);
h1.Draw();
TFile *file = new TFile("../Debug/test.root", "RECREATE");
file->WriteTObject(c1);
c1->Update();
c1->GetFrame()->SetBorderSize(12);
c1->Modified();
//system("root");
system("pause");
return 0;
}
Here you are
When I compile, a terminal appears with “press a key to continue” due to the system(“pause”) and nothing else.
To open the histogram (and it works) I do this:
Windows+R : cmd
root
new TBrowser()
double click on test.root
double click on c1