# TGaxis : non linear second axis

Hi,

I am trying to draw an histogram with a secondary axis (showing calibrated values).
I used some exemples from the tutorials. It works well when the secondary scale/axis is a linear function of the main axis. But when I try to use a non-linear one then the result is not what I expect…
Here is a test code which reproduces my problem:

[code]#include “TH1.h”
#include “Riostream.h”
#include “TF1.h”
#include “TGaxis.h”

int test(void)
{
int tmax=200;

TH1F *ht=new TH1F(“ht”,"",200,0,tmax);
ht->Fill(100,20);

ht->Draw();

TF1 *f_calib=new TF1(“f_calib”,“pol2”,0,1);

f_calib->SetParameter(0,100);
f_calib->SetParameter(1,10);
//f_calib->SetParameter(2,0.); // works well!
f_calib->SetParameter(2,1.); // does work with non linear function…

f_calib->SetRange(f_calib->Eval(0),f_calib->Eval(tmax));

TGaxis *A1 = new TGaxis(0,20,tmax,20,“f_calib”);
A1->SetTitle(“calibrated axis”);
A1->Draw();

cout << " f(0) = " << f_calib->Eval(0) << endl;
cout << " f(100) = " << f_calib->Eval(100) << endl;
cout << " f(200) = " << f_calib->Eval(200) << endl;

return(0);
}
[/code]

In this example, the central value of the secondary axis ( corresponding to for x=100) is expected to be 11110 but the tick on the secondary axis indicates a value of about 30000!
Could anyone explain me clearly how the secondary axis values are calculated from the const char* funcname argument of the constructor?

thanks
Alain

This is not how it works. It is like the option Log. The tick placement follows the function but the labels are the x value not f(x) … really like option log. The xmin and xmax values a given by the function limit.

``````{
int tmax=200;

TH1F *ht=new TH1F("ht","",200,0,tmax);
ht->Fill(100,20);

ht->Draw();

TF1 *f_calib=new TF1("f_calib","pol2",0,tmax);

f_calib->SetParameter(0,100);
f_calib->SetParameter(1,10);
f_calib->SetParameter(2,1.); // does work with non linear function...

TGaxis *A1 = new TGaxis(0,10,tmax,10,"f_calib");
A1->Draw();

cout << " f(0) = " << f_calib->Eval(0) << endl;
cout << " f(100) = " << f_calib->Eval(100) << endl;
cout << " f(200) = " << f_calib->Eval(200) << endl;

return(0);
}
``````

ok. But still I don’t understand why it works very well when using a linear function…
Anyway, does anyone know a way to set the secondary labels to f(x)?

thanks
Alain

a linear function does nothing . You get a linear spacing of the tick marks like a normal axis.