Hello,
i’ve programmed a litte programm which generates random numbers and puts them into a TH1F:
#include <iostream>
#include <stdio.h>
#include "src/RandomIT.cpp"
#include <TH1F.h>
#include <TCanvas.h>
#include <TFile.h>
using namespace std;
int main (void)
{
TFile *RootFile = new TFile("Test.root", "RECREATE");
RandomIT *t = new RandomIT();
TH1F *h = new TH1F("Test", "TEST", 100, 0, 1);
for (int i = 0; i < 10000; i++)
{
// cout << t -> GetRandomNumber() << endl;
h -> Fill(t -> GetRandomNumber());
}
TCanvas *c = new TCanvas("Test", "Test", 800, 600);
c -> Draw();
h -> Draw();
RootFile -> Write();
return 0;
}
I compile it with g++ outside of root with a little makefile:
CC=g++
SOURCES=RandomTest.cpp
OBJECTS=$(SOURCES:.cpp=.o)
CFLAGS = -c -g -Wall `root-config --cflags`
LDFLAGS = `root-config --glibs`
EXECUTABLE=RandomTest
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -rf *.o $(EXECUTABLE)
The root file can be created and its possible to read it out afterwards.
But why its not possible to show the canvas and the hist?
Has someone a hint what i’am doing wrong?
Thanks in advance.
Jo