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
#include<iostream>
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);

  g_graph->SetMarkerStyle(22);
  g_graph->SetMarkerSize(1.2);
  g_graph->SetMarkerColor(kRed);

  for(int ctr=1;ctr<=npts;ctr++){
    g_graph->SetPoint(ctr,ctr,ctr*ctr-ctr);
  }



  c_graph->Divide(1,2);

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


  c_graph->Print("graph_test.png");
}

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.

Slava

The histogram return by TGraph::GetHistogram is the internal member fHistogram and is there only to draw the axis. See:
https://root.cern/doc/master/classTGraph.html#ac4a8e1770391785421e2b66be52930ca

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

Slava