Problem with TGaxis using TF1

When I run the following code, creating a TGaxis using a TF1, the TGaxis doesn’t look correct.

TH2D *h2;
TF1 *fcm;
TGaxis *g1;

void t()
{
  h2 = new TH2D("h2", "Lab Frame to CoM Frame energy scale",
                100, 1.e9, 1.e20, 100, 1.e9, 1.e15);
  h2->SetStats(kFALSE);
  h2->SetXTitle("Lab Frame energy (eV)");
  h2->SetYTitle("CoM Frame energy (eV)");

  fcm = new TF1("fcm", "sqrt(0.5*pow(938.e6, 2.) + 0.5*938.e6*x)",
                1.e9, 1.e20);
  g1 = new TGaxis(1.e9, 1.e11, 1.e20, 1.e11, "fcm", 510, "G");


  h2->Draw();
  fcm->Draw("same");
  g1->Draw();

  c1->SetLogy();
  c1->SetLogx();
  c1->Update();
}


As can be seen in the function plot at 10^{20} eV the value of fcm is ~10^{14} eV. Why doesn’t the TGaxis properly reflect that?

You cannot cumulate a function axis and the log scale. The Log scale is a particular case of a “function axis”. See the axis examples.

Do you mean the examples here: http://root.cern.ch/root/html534/TGaxis.html#TGaxis:TGaxis@3?

Is there an example somewhere of how to do what I’m trying to do?

I used a simpler funtcion to see what’s going on:

TH2D *h2;
TF1 *fcm;
TGaxis *g1;

void funaxis()
{
  h2 = new TH2D("h2", "Lab Frame to CoM Frame energy scale",
                100, 1.e9, 1.e20, 100, 1.e9, 1.e15);
  h2->SetStats(kFALSE);
  h2->SetXTitle("Lab Frame energy (eV)");
  h2->SetYTitle("CoM Frame energy (eV)");

  fcm = new TF1("fcm", "x*x",0.1, 10.);
  g1 = new TGaxis(1.e9, 1.e11, 1.e20, 1.e11, "fcm", 510, "");


  h2->Draw();
  fcm->Draw("same");
  g1->Draw();

  c1->SetLogy();
  c1->SetLogx();
  c1->Update();
}

You can see that the axis limits are the limits of the function and that the ticks are spread according to x*x …
Like in log scales: the labels are the same as the linear scale but the ticks are spread according to the log of the values.
Seems to me the option G in the example you mentioned is wrong …