Displaying graphs before main() returns

From: Alex Mott <armott_at_mit.edu>
Date: Mon, 29 May 2006 14:37:08 -0400


Hi,

I am trying to simply display a set of graphs in a some canvases, and then prompt the user to save the file. I create the TCanvases using TCanvas *mycanv = new TCanvas("mycanv","name"); and then draw to it using the Draw() method from a TH1F, and nothing is displayed (the Canvas isn't even created. Even if the canvas is previously created in a different instance of the program, nothing is drawn to it. Only once the program has finished, and the main loop has returned are the canvases created and the TGraphs plotted to the canvases. If anyone knows how to fix that, it would be much appreciated.

Here is some code which generates the problem (this should compile on any build as far as I know):
#include <iostream>
#include "TROOT.h"
#include "TH1.h"
#include "TCanvas.h"

int main(){

   char save='n';
   TH1F *qw = new TH1F("qw","test",100,0,5);
   for(int i=0;i<100;i++)
     qw->Fill(1);

   TCanvas *qe = new TCanvas("qe","");
   qw->Draw();
   cout << endl << "Save?: (y/n)";
   cin >> save;
   return 0;
}

Alexander Mott
armott_at_mit.edu
Undergraduate
Department of Physics
Massachusetts Institute of Technology Received on Mon May 29 2006 - 20:37:25 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:58 MET