Converting TGraph into TH1F Histogram

Ah yes, the TGraph::GetHistogram() returns the empty histogram as explained here. To get a real histogram with values off a TGraph, replace

TH1F *hist = gr->GetHistogram();

with this:

        TH1F* hist = new TH1F("hist", Form("%s;%s;%s", gr->GetTitle(), gr->GetXaxis()->GetTitle(), gr->GetYaxis()->GetTitle()), 1000, 0.9*TMath::MinElement(sizeof(x)/sizeof(*x), x), 1.1*TMath::MaxElement(sizeof(x)/sizeof(*x), x));
        for (unsigned short i=0; i < gr->GetN(); ++i) // setting bin contents to the TGraph values
        {
                double x,y;
                gr->GetPoint(i, x, y);
                hist->Fill(x, y); // uncertainties are of course screwed up
        }
        for (unsigned short i=1; i < hist->GetNbinsX(); ++i) // let's nullify the y-axis uncertainties as it was in the TGraph
                hist->SetBinError(i, 0);

(via this post)