TGraph and TGraph2D related help

Hi,
I am reading in a data file looks something like this:
1.00000e+00 1.16406e+00 1.16406e+00 1.16406e+00 3.54108e-02
2.00000e+00 1.29160e+00 1.29160e+00 1.29160e+00 7.08215-02
3.00000e+00 1.39797e+00 1.39797e+00 1.39797e+00 1.06232e-01
.
.
.
1.00000e+02 3.88716e+00 3.88716e+00 3.88716e+00 3.54108e+00
1.00000e+00 -6.41140e-01 -8.54853e-01 -1.06857e+00 2.84036e+00
.
.
.
1.00000e+02 -7.22261e+00 -6.77120e+00 -7.44832e+00 6.41945e+00
1.00000e+00 4.01140e+00 4.01140e+00 4.21197e+00 5.88821e+00
.
.
.
1.00000e+02 4.91727e+00 4.91727e+00 5.16314e+00 3.59464e+01

I am using TGraph to plot the data. However, for every block of data from 1…100 I would like to set a different marker style. I have tried making if statements which would go through the indicies and set markers for each 100 numbers. This didnt work.
I have also tried reading the data into different arrays (a1,a2,a3… each of size 100) then make different TGraph objects and plot them on the same graph but this doesnt work for TGraph2D.
I would appreciate some feedback.
Cheers.

Can you send a small example showing what you are doing ?

This is what I currently have:
{
gROOT->Reset();
const Int_t nmax=400;
Float_t t1[nmax], x1[nmax], y1[nmax], z1[nmax], v1[nmax];
Int_t ntimes, m = 0;
FILE * pFile;
pFile = fopen("…/…/work/ode45.dat",“r”);
for(Int_t i=0; i<nmax;i++){
fscanf(pFile,"%f %f %f %f %f",&t1[i],&x1[i],&y1[i],&z1[i],&v1[i]);
ntimes++;
}
cout<<"Number of data points: "<<ntimes<<endl;
TCanvas *c1 = new TCanvas(“c1”);
c1->Divide(2,1);
TGraph2D *gr1 = new TGraph2D(nmax,x1,y1,z1);
TGraph *gr = new TGraph(nmax,t1,v1);
gr->GetXaxis()->SetTitle(“t”);
gr->GetYaxis()->SetTitle(“v”);
c1->cd(1);
gr->Draw(“AP”);
c1->cd(2);
gr1->SetMarkerStyle(20);
gr1->Draw(“CP”);
c1->Update();
c1->Modified();
fclose(pFile);
}

and this is what I was trying to do…this isnt complrete cause I have actually lost the previous work:
{
gROOT->Reset();
const Int_t nmax=400;
Float_t t1[nmax], x1[nmax], y1[nmax], z1[nmax], v1[nmax];
Float_t t2[nmax], x2[nmax], y2[nmax], z2[nmax], v2[nmax];
Float_t t3[nmax], x3[nmax], y3[nmax], z3[nmax], v3[nmax];
Float_t t4[nmax], x4[nmax], y4[nmax], z4[nmax], v4[nmax];
Int_t ntimes, m = 0;
FILE * pFile;
pFile = fopen("…/…/work/ode45.dat",“r”);
for(Int_t i=0; i<nmax;i++){
fscanf(pFile,"%f %f %f %f %f",&t1[i],&x1[i],&y1[i],&z1[i],&v1[i]);
ntimes++;
}

TGraph *gr1 = new TGraph(10,t1,v1);
TGraph *gr2 = new TGraph(10,t2,v2);
TGraph *gr3 = new TGraph(10,t3,v3);
TGraph gr4 = new TGraph(10,t4,v4);
//
//for loops were here
//
for(Int_t i=0; i<nmax/4;i++){
//got through first 100 indices and set the marker to whatever
}
for(Int_t i=100; i<2
nmax/4;i++){
//got through first 100 indices and set the marker to whatever
}
//&c &c

TMultiGraph *m = new TMultiGraph();
m->Add(gr1);
m->Add(gr2);
m->Add(gr3);
m->Add(gr4);
m->Draw(“AP”);
fclose(pFile);
}

This didnt work either though I know TMultiGraph works for TGraph objects and not TGraph2D. I would really like to make a 3 dimensional plot with every block of 100 data points plotted using a different marker style.
Thank you very much.

Thanks, but that’s is not a running example. What you do seems correct. Can you send me a running example (if possible as attachment) and also tell me what you mean by “it does not work” …
Thanks in advance.

Hi,
I have attached the data file and the working macro (the first one in the last post) and I hope this will help clarify what I am trying to achieve.

I have also attached the second macro which fails miserably. Executing this gives me the follwoing:

Warning in TGraph2D::Build: Replacing existing 2D graph: Graph2D (Potential me
mory leak).
Warning in TGraph2D::Build: Replacing existing 2D graph: Graph2D (Potential me
mory leak).
Warning in TGraph2D::Build: Replacing existing 2D graph: Graph2D (Potential me
mory leak).
Warning in TGraph2D::Build: Replacing existing 2D graph: Graph2D (Potential me
mory leak).
Error: Can’t call TMultiGraph::Add(gr1) in current scope C:\work\ode45draw.C(63)

Possible candidates are…
(in TMultiGraph)
C:\root\bin\libGraf.dll -1:-1 0 public: virtual void TMultiGraph::Add(TGraph*
graph,Option_t* chopt=);
C:\root\bin\libGraf.dll -1:-1 0 public: virtual void TMultiGraph::Add(TMultiG
raph* multigraph,Option_t* chopt=);
*** Interpreter error recovered ***

Thank you very much.
ode45draw.C (1.49 KB)
xode45draw.C (616 Bytes)

Sorry, the data file didnt attach the first time. Changed the extension.
ode45.txt (24.3 KB)

Ok thanks. You cannot put a TGraph2D in a Multigraph. Multigraphs hold only TGraphs. Also you are using the TGraph plotting options to Draw a TGraph2D. Have a closer look at the TGraph2D documentation.

BUt I am not sure you need TGraph2D because, from your first post, I understand that you would like to draw several TGraphs on the same plot uing different markers. That’s what the macro
$ROOTSYS/tutorials/graphs/multigraph.C is doing.

Since I would like to see a 3D plot also, I would like to be able to distinguish between the tracks. Hence, why I would like to use different markers. I just cant see how I can set different marker styles for the data and still plot it in 3D using TGraph2D. Is there anyother way to plot the data in 3D?
Thanks again.

Try this:

{
   TNtuple *ntuple = new TNtuple("ntuple","ntuple","x1:x2:x3:x4:x5");
   ntuple->ReadFile("ode45.dat");
   ntuple->SetMarkerStyle(21);
   ntuple->SetMarkerColor(kRed);
   ntuple->Draw("x1:x2:x3");
   ntuple->SetMarkerColor(kBlue);
   ntuple->SetMarkerStyle(20);
   ntuple->Draw("x3:x4:x5","","same");
}

Thank you very much. I think I can use this better. :smiley: