Relatively new to ROOT, and not sure what my problem is here:
I have a plot that measures amplitude vs. frequency, and have successfully found the maximum amplitude in a given range using:

double maxamp = G->GetHistogram()->GetMaximum();

However, I run into problems when trying to find the corresponding frequency (x-axis) of maximum amplitude. Searching through these forums, I found someone with a similar problem that used:

int binmax = G->GetHistogram()->GetMaximumBin();
double xMax = G->GetXaxis()->GetBinCenter(binmax);

But this doesn’t give the corresponding x-value for me. Instead, it appears to give the value of the lower limit of my x-axis.

For instance, if my limits of frequency are 5900Hz to 6100Hz, it outputs: 5900.0020278677 Hz
If my limits are 6000Hz to 6050Hz, it outputs: 5999.9987121388 Hz

What is your G? It looks like it is a TGraph and then G->GetHistogram() gets the histogram used to draw the axes. This histogram does not have any entries, so GetMaximumBin just returns the first bin.

Instead, all you can do is iterate through the points:

Your code worked for me with slight modification. Unfortunately, my ‘max_y’ value fell outside of the range I was looking at so I simply needed to take that into account: