[trivial question] TH1F and log scale

Hi ROOTers,
I have to book an TH1F hisogram with a variable Z ranging on many order of magnitude
(let’s say from 1 to 10000). Moreover, I need a binning with increasig bin widths.
The simplest way is to define a histogram for the new variable
W = log10(Z)
ranging from 0 to 4 with uniform binning.
But, when I draw it, I’d like to see Z with the log scale on x axis,
instead of seeing W with a linear scale.
How to do that?

2 ways:

  1. Using GUI: on the TCanvas pop up menu choose the log x scale

  2. In your macro or at root prompt: gPad->SetLogx()

see example below using a variable bin width histogram

Rene

[code]void logx() {
const int nbins=20;
Double_t xbins[nbins+1];
double dx = 4./nbins;
double l10 = TMath::Log(10);
for (int i=0;i<=nbins;i++) {
xbins[i] = TMath::Exp(l10idx);
}
TH1F *h = new TH1F(“h”,“test”,nbins,xbins);

TRandom r;
for (int j=0;j<100000;j++) h->Fill(r.Uniform(1,10000)/(0.02*j+1));
TCanvas *c1 = new TCanvas(“c1”);
c1->SetLogx();
h->Draw();
}
[/code]

@ couet,
Thank you, but my problem deals with the binning.

@ brun
Thank you. At the end, I’ll proceed in this way. In my request I wondered if it’s possible
to solve my problem with just a graphic superimposition of my linear histogram over a
log-scaled frame (i.e. without defining any “ad hoc” binning). I get the idea it was possible
with PAW (using “null”)…

I do not understand your remark about the PAW command “null”.
The equivalent in ROOT is TPad::DrawFrame

pad.DrawFrame(xmin,ymin,xmax,ymax); but I do not see the relationship with your problem.

Rene

The example code you have posted has fit perfectly to what I was looking for :stuck_out_tongue:

Thanks!