Re: Large array size problem in TGraph

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Wed, 19 Apr 2006 09:42:07 +0200 (MEST)


Do not use the Draw option "CP" when you have so many points and use a more optimized algorithm as shown below

Rene Brun

{

    gROOT->Reset();
    TCanvas *c1 = new TCanvas("c1"," ",200,10,700,500);     TH1F *hr = c1->DrawFrame(0.0001,0.00001,1,100);

    c1->SetLogx();
    c1->SetLogy();
    ifstream my("test.dat");

    const Int_t n = 999999;
    TGraph *gr = new TGraph(n);
    Double_t x, y;
    for (Int_t i=0;i<n;i++) {
      my >> x >> y;
      gr->SetPoint(i,x,y);

    }
    printf("finished reading data\n");
    gr->SetLineWidth(2);
    gr->GetXaxis()->SetTitle("x");
    gr->GetYaxis()->SetTitle("f(x)");

    //gr->Draw("CP");
    gr->Draw("lP");
}

On Wed, 19 Apr
2006, Ding Hengtong wrote:

>
> Hi Rooters,
>
> I want to plot a data file which has 999999 lines, I used
> TGraph class in ROOT but I can't get a figure but just a canvas with
> axis instead.
>
> My code is listed below and according to ROOT Guide, Int_t is 4 Bytes,
> ranges from -2^{31} to 2^{31}-1 and 999999 is actually in this range.
> And I also tried "Long64_t", by which I still can't get the figure I
> wanted. I don't know what's wrong.
>
> {
> gROOT->Reset();
> TCanvas *c1 = new TCanvas("c1"," ",200,10,700,500);
> TH1F *hr = c1->DrawFrame(0.0001,0.00001,1,100);
> c1->SetLogx();
> c1->SetLogy();
> ifstream my("test.dat");
> const Int_t n = 999999;
> Double_t x[n], y[n];
> for (Int_t i=0;i<n;i++) {
> my >> x[i] >> y[i];
> }
> TGraph *gr = new TGraph(n,x,y);
> gr->SetLineWidth(2);
> gr->GetXaxis()->SetTitle("x");
> gr->GetYaxis()->SetTitle("f(x)");
> gr->Draw("CP");
> }
>
> Thanks for any help.
>
> Regards,
>
> Hengtong
>
>
Received on Wed Apr 19 2006 - 09:42:20 MEST

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