If you set the upper limit range to 0.7 you will miss the last point away way ? The range setting on histogram is based on the bins. If the value you choose for the upper limit is in the middle of a bin the closest upper bin limit will be used. You can do the following but you will mis the first and last points … up to you …
{
auto c = new TCanvas();
c->DrawFrame(0.3,-0.1,0.7,70);
TGraphErrors *g = new TGraphErrors("data.txt", "%lg %lg %lg");
// g->Sort(); // just a precaution
Int_t n = g->GetN();
Double_t *x = new Double_t[(n + 1)];
x[0] = (3.0 * g->GetX()[0] - g->GetX()[1]) / 2.0;
x[n] = (3.0 * g->GetX()[(n - 1)] - g->GetX()[(n - 2)]) / 2.0;
for (Int_t i = 1; i < n; i++)
{ x[i] = (g->GetX()[(i - 1)] + g->GetX()[i]) / 2.0; }
TH1D *h = new TH1D("h", "spectrum;x-value;#counts", n, x);
for (Int_t i = 0; i < n; i++) {
h->SetBinContent(i + 1, g->GetY()[i]);
h->SetBinError(i + 1, g->GetEY()[i]);
}
h->ResetStats(); // reset the statistics including the number of entries
h->Draw("SAME");
}