TTree histogram rebinning in log scale

Dear Root team,

I am trying to plot a weighted histogram from an NTuple in which I would like the binning to be in log-scale. I explain myself:
In my ntuple, I have two quantities X and Y. To plot a histogram of X weighted by Y I do:
This provides a histogram of X weighted by Y but each bin has the same size in linear scale.
However, I would like to be able to transform this histogram with bin of the same size in log scale.
Is there an option for that and how should I proceed. I know I can do it with a macro but I am looking for a simple option.
Best and thanks in advance for your help.

I guess you can make htemp a non equidistant bins histograms.

Thanks. I tried the command kLogx in Draw() but it did not work

not sure I unsderstand what you mean …

I tried the following, hopping my 1000 bins sizes would be distributed in a log scale (log of the bin range similar in the whole histogram) but I had no success.

The third parameter is the drawing option. I do not know from where you got this “kLogX” option ? … it does not exist…

ntuple->Draw("TMath::Log(X) >> htemp(1000)", "Y");

Another solution is to create a histogram with an appropriate binning (see an example below) and then:
ntuple->Draw("X >> htemp", "Y");

  Double_t xlow = 10.; // xlow > 0
  Double_t xup = 100000.; // xup > xlow
  const Int_t nbinsx = 4; // nbinsx > 1
  Double_t dx = TMath::Log(xup / xlow) / nbinsx;
  Double_t xbins[(nbinsx + 1)];
  xbins[0] = xlow; xbins[nbinsx] = xup;
  for (Int_t i = 1; i < nbinsx; i++) xbins[i] = xlow * TMath::Exp(dx * i);
  TH1D *htemp = new TH1D("htemp", "my htemp;my X;my Y", nbinsx, xbins);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.