How can we plot the TH1 histogram with different bin width?


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.24/02
Platform: Ubuntu 20.04
Compiler: gcc 9.3.0

Dear ROOT experts,

I want to plot a histogram with different bin width, for example

I don’t know how to plot the histogram like this. The TH1 class contains a method called TH1::Rebin(). However, this method can only rebin the histogram globally. I just need to merge some bins in the histogram.

1 Like

Hi,

you need a hisotgram with variable bin size, https://root.cern.ch/root/html534/guides/users-guide/Histograms.html#constant-or-variable-bin-width

Hi @zzl0024; let us know whether you still have problems for this after taking a look to the guide mentioned by @yus.

Cheers,
J.

You can “merge some bins in the histogram”.
See the “case 2 xbins!=0” in the TH1::Rebin method description.

A simple example can be found in this post.

Thank you!

Thank you! Your method is also very useful. If I want to plot a histogram from a TTree, I can only use this method to plot the histogram with variable bin width. :grin:

If you want to make a projection of a tree then it is a better idea to create a histogram with the desired (variable) binning in advance.

1 Like

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