Re: [ROOT] More Graphs

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jan 14 2002 - 15:37:31 MET


Hi Giulo,

Your example had many bugs. I have simplified it in the file myclass.C below
To run it, just do:
 root > .L myclass.C
 root > main()

//----------file myclass.C
class MyClass {
public:
   void Draw();
};

void MyClass::Draw() {

  TCanvas *c = new TCanvas("c", "DEMO", 200,10,600,400);
  
  int n = 100;
  double *x=  new double[n];
  double *d=  new double[n];
  for(int i=0;i<n;i++) {x[i]=i; d[i] = x[i]+1;}
  
  TGraph *gr=new TGraph(n,x,d);
  gr->Draw("AC.");
}

int main(){

  MyClass c1,c2;
  c1.Draw();
  c2.Draw();
}

I strongly suggest to
 - look at the many examples in $ROOTSYS/tutorials
 - see the Users Guide at: ftp://root.cern.ch/root/Users_Guide_3_1d.pdf 

Rene Brun

Giulio Ballardin wrote:
> 
>    Part 1.1       Type: Plain Text (text/plain)
>               Encoding: quoted-printable
Hi,

I would like Draw more graphs in differents windows.
I created a class, and in this class I have
a member called "Draw".
It well runs.
But I have a problem: if I call this member for two different
objects, only the first one runs.

void MyClass::Draw()
{

  // double *d contains my values
  // n is the number of these values

  double* x;
  TGraph *gr;
  int i;
  TApplication* theApp;
  TCanvas *c ;
  double dd=0

  TROOT simple("simple","Test of histogramming and I/O"); 
  theApp = new TApplication("",&dd,NULL);
  c = new TCanvas("c", "DEMO", 200,10,600,400);
  
  x= (double*)calloc(n,sizeof(double));
  for(i=0;i<n;i++) x[i]=i;
  
  gr=new TGraph(n,x,d);
  gr->Draw("AC.");
  c->Update();
  theApp->Run(); 

}

Example:

int main(){

MyClass c1,c2;

/*elaboration of c1 and c2*/
c1.Draw();
c2.Draw();
}

..but I can see only the c1 draw!!!

Thank you,
Giulio Ballardin



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET