Getting list of points inside a rectangle area

I have a scatterplot and want to get the list of plotted points in a certain rectangular region, provided I have an x1,y1,x2,y2 rectangular region. Is there a method for this?

How about

for (int i=1; i<myhisto->GetNbinsX(); i++)
	for (int j=1; j<myhisto->GetNbinsY(); j++)
		if (myhisto->GetBinContent(i, j) > 0. && myhisto->GetXaxis()->GetBinCenter(i) > x1 && myhisto->GetXaxis()->GetBinCenter(i) < x2 && myhisto->GetYaxis()->GetBinCenter(j) > y1 && myhisto->GetYaxis()->GetBinCenter(j) < y2)
			printf("This is your point!\n");

That doesn’t seem to work. In my test example I have a graph like this, and then getting the histogram from that.

[code] const Int_t n = 200;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i0.1;
y[i] = 10
printf(" i %i %f %f \n",i,x[i],y[i]);
TGraph *gr = new TGraph(n,x,y);
gr->SetTitle(“a simple graph”);

    histogram = gr->GetHistogram();[/code]

Unfortunately histogram->GetNbinsY() returns zero, so the for loop exits immediately.

Try: for (int i = 0; i < gr->GetN(); i++) { if (gr->GetX()[i] > x1 && gr->GetX()[i] < x2 && gr->GetY()[i] > y1 && gr->GetY()[i] < y2) { std::cout << i << " " << gr->GetX()[i] << " " << gr->GetY()[i] << std::endl; } }

Thanks! That works perfectly. Just one last question, is it possible to access the TMarker property for those points? I am not seeing an easy accessor for that.

All markers for a TGraph are the same.
If you want to draw these points with a different marker style, then the easiest way is to create (and draw) another TGraph (which would contain just your “selected” points).