TGraph GetHistogram()

Dear rooters,

I got a strange problem trying to manipulate histograms that I got from graphs. Initially, I was trying to integrate the resulting histogram b/n some limits (the whole reason I needed this), and I was getting 0 as a result all the time.

Then I decided to check what is going on by eye, but the pad where I draw it comes up empty, although axes seem to have correct ranges.

Here is a simple example of what I am doing.

// C++ files
using namespace std;
// ROOT files
#include "TROOT.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TAxis.h"
#include "TH1.h"

int main()
  const Int_t npts=10;

  TCanvas *c_graph = new TCanvas("c_graph","");
  TGraph  *g_graph = new TGraph(npts);


  for(int ctr=1;ctr<=npts;ctr++){


  c_graph->cd(1); g_graph->Draw("APl");
  c_graph->cd(2); g_graph->GetHistogram()->Draw();


Pad #2 is empty.

Could anybody help me with this? If you can directly help me with the problem of integrating graph between some x-values, it’ll be even better.


The histogram return by TGraph::GetHistogram is the internal member fHistogram and is there only to draw the axis. See:

Thank you. I guess I expected too much of it.