Hi there,
I am inexperienced at ROOT, but would like to use its libraries in my C++ programs. I am using a g++ compiler on a Linux platform. With the following piece of stand-alone code (below and attached, partially lifted from ROOT examples), I am just trying to plot a histogram. It compiles perfectly but produces a segmentation fault when I run it. Does anyone see what is wrong with it?
Thanks,
Penny
int hsimple();
#ifndef CINT
#include “TH1.h”
#include “TRandom.h”
#include “TApplication.h”
#include “TGraph.h”
#include “TCanvas.h”
#endif
//______________________________________________________________________________
int main()
{
return hsimple();
}
int hsimple()
{
Int_t argc; char** argv=0;
TApplication theApp(“App”, &argc, argv);
TH1F *hpx = new TH1F(“hpx”,“This is the px distribution”,100,-4,4);
// Fill histogram randomly
Float_t px, py, pz;
for ( Int_t i=0; i<10000; i++) {
gRandom->Rannor(px,py); //px and py will be two gaussian random numbers
pz = pxpx + pypy;
hpx->Fill(px);
}
TGraph *gr001 = new TGraph(hpx);
gr001->Draw();
theApp.Run();
return 0;
}
hsimple.cxx (728 Bytes)