TGraph: GetPoint

Hii,
I am new user of root. I have a plot using TGraph and I want to extract the x and y values corresponding each data point. I am using GetPOint(int, double,double) for that. But it is not working. The following is my code:

{

TFile *f = new TFile(“inocross.root”);
if (!f) {
cout << "Failed to open: " << “inocross.root” << endl;
return;
}
TGraph h1 = (TGraph)gDirectory->Get(“nu_mu_Fe56/coh_cc”);
if (!h1) {
cout << "Failed to retrieve: " << “nu_mu_Fe56/coh_cc” << endl;

return;
}
h1->Draw(“AC”);
int num;
double numx,numy;
Double_t x, y;
num=h1->GetN();
numx=h1->GetX();
numy=h1->GetY();
cout<<"numberx "<<numx<<endl;
for(int i=0;i<num;i++)
cout<GetPoint(i,x,y)<<endl;
}
Could you tell me what is going wrong?
Thanks in advance!

Ok… the problem with GetX() and GetY() is solved… (I did a very silly mistake :stuck_out_tongue: ). But please help me in using the GetPoint(int, double&, double&)!!

Ok… the problem is solved :slight_smile:

{

Double_t x[10] = {1,2,3,4,5,6,7,8,9,10};
Double_t y[10] = {2,1,4,3,6,5,8,7,10,9};

TCanvas *c = new TCanvas(“gr”,“gr”, 700,500);
gr = new TGraph(10,x,y);

Double_t ax[10],ay[10];
Int_t n;

n=gr->GetN(); //get ploted array dimention

cout<<n<<endl;

for(Int_t i=0; i<n; i++) {

gr->GetPoint(i,ax[i],ay[i]); 
cout<<i<<"th element of X array: "<<ax[i]<<endl;
cout<<i<<"th element of Y array: "<<ay[i]<<endl;

}

gr->Draw(“ap*”);

}

how did you resolve this pls?