Today I’ve started the particle laboratory and I have my first problem. I do a multichannel analysis and I have an histogram count/channel. I want to plot the histo with two orizzonatal scale, one for the number of channel and the second for the energy (energy = energy(channel)).
So I try with this simple program:
#include <iostream>
using namespace std;
void axis()
{
TH1F *histo = new TH1F("histo", "istogramma", 100, -3, 3);
histo->FillRandom("gaus",5000);
double x[] = {0, 1, 2};
double y[] = {10, 20, 30};
// TGraph *histo = new TGraph(3,x,y);
TCanvas *canv = new TCanvas();
histo->Draw();
cout << "x min: " << histo->GetXaxis()->GetXmin() << '\n';
cout << "x max: " << histo->GetXaxis()->GetXmax() << '\n';
cout << "y min: " << histo->GetYaxis()->GetXmin() << '\n'; //why 1?
cout << "y max: " << histo->GetYaxis()->GetXmax() << '\n'; //why 1?
cout << " : " << histo->GetContourLevelPad(10) << '\n';
cout << " : " << histo->GetBufferSize() << '\n';
cout << " : " << canv->GetFrame()->GetY1() <<'\n';
cout << " : " << canv->GetFrame()->GetY2() << endl;
TGaxis *axis2 = new TGaxis(histo->GetXaxis()->GetXmin(),
histo->GetYaxis()->GetXmin(),
histo->GetXaxis()->GetXmax(),
histo->GetYaxis()->GetXmin() //or max is the same
,0.,10.); //my energy min and max (now not calculated)
axis2->Draw();
}
I used the TGaxis class for the second axis, but it doesn’t work, in particular I’m not able to get the y position of the axis. I want that the second axis is at the top of the histogram, so I initialize the y1 and y2 parameter of the TGaxis parameter by histo->GetXaxis()->GetXmax(), but this is 1, and not (in my case) 150. If I change TH1F with TGraph all work.