Full width at half maximum for TGraph

TGraph::GetHistogram always returns a completely “empty” histogram, which is only used to draw the axes.

In general, you would need to take the array pointers returned by TGraph::GetX and TGraph::GetY (together with the array sizes returned by TGraph::GetN) and then use some standard C++ functions to find FWHM (just make sure that you TGraph::Sort it first).

If your graph is a scatter-plot of some “well defined” known distribution, then you could use TGraph::GetRMS (and TGraph::GetMean, if needed) and “calculate” FWHM from it:

{
  TGraph *g = new TGraph(10000);
  for (int i = 0; i < g->GetN(); i++)
    g->SetPoint(i, gRandom->Rndm(), gRandom->Gaus());
  // g->Sort();
  g->Draw("AP");
  cout << "X Mean (exact 0.5)      = " << g->GetMean(1) << endl;
  cout << "X RMS  (exact " << sqrt(1. / 12.) << ") = " << g->GetRMS(1) << endl;
  cout << "Y Mean (exact 0.0)      = " << g->GetMean(2) << endl;
  cout << "Y RMS  (exact 1.0)      = " << g->GetRMS(2) << endl;
}
1 Like