Ok, so I’m hoping to be able to do this, but I’m not sure if it can be done. I want to use the ROOT libraries to create and display histograms and other graphs inside of a Cocoa based program. I’ve got ROOT installed, and have successfully compiled and run several simple programs that use the libraries, but whenever I call the Draw() command on a histogram, the console displays a message along the lines of “TCanvas::MakeDefCanvas: created default TCanvas with name c1”, and no graphics are displayed. For reference, here is the code that generates that message:
[code]#include
using namespace std;
int hsimple();
#ifndef CINT
#include “TFile.h”
#include “TH1.h”
#include “TH2.h”
#include “TProfile.h”
#include “TNtuple.h”
#include “TRandom.h”
//______________________________________________________________________________
int main()
{
return hsimple();
}
#endif
int hsimple()
{
// Create a new ROOT binary machine independent file.
// Note that this file may contain any kind of ROOT objects, histograms,
// pictures, graphics objects, detector geometries, tracks, events, etc…
// This file is now becoming the current directory.
TFile hfile(“hsimple.root”,“RECREATE”,“Demo ROOT file with histograms”);
// Create some histograms, a profile histogram and an ntuple
TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
// Fill histograms 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 = px*px + py*py;
Float_t random = gRandom->Rndm(1);
hpx->Fill(px);
hpxpy->Fill(px,py);
hprof->Fill(px,pz);
ntuple->Fill(px,py,pz,random,i);
}
int bob;
hpx->Draw();
cin >> bob;
// Save all objects in this file
hfile.Write();
// Close the file. Note that this is automatically done when you leave
// the application.
hfile.Close();
return 0;
}
[/code]
Now, I presume that I’m doing something wrong, or missing a step somewhere, so what would be really great is if someone could provide a small sample program that will actually generate graphics. If that’s even possible.
My ultimate goal is to be able to display the graph inside a regular Cocoa view of some sort, rather than in an X11 window. Again, not sure if this is even possible.
Thanks,
Paul