# Fill histogram with finer bin width with histogram data having coarser binning

Hi.

I am trying to extract the bin contents of a TH2 hist1 that has a coarse binning and fill another hist2 with the contents of hist1 using a finer bin width and preserve the tile size and the number of data points from the first histogram.cluster_nano.C (4.1 KB)

I would really appreciate your help

Hi @Xola,

can you give more details on what the problem is? What do you want people in this forum to do?

From the title, it sounds like you want to create a fine binning from data with coarse binning. That’s obviously impossible, since information was lost when the coarse binning was computed.
What you can do is do some educated guessing, e.g. when one bin blows up to three, you distribute the bin contents of the coarse bin equally over the finer bins, but this will not recover the last information.

Thank you for your reply. What you said in the last sentence is exactly what I am trying to do. That is the step that I am actually stuck on. So when you just plot the original data over a finer binning, what you get are small points in each of the finer bins but the rest of the bin corresponding to the coarser binning is empty. I would like you to help me distribute these small points equally over the width of the original bin

That can be done with a combination of

``````GetBinLowEdge()
GetBinContent()
SetBinContent()
``````

Check https://root.cern.ch/doc/master/classTH1.html for these functions. So what you have to do is to find all “fine” bins that overlap with the coarse bin, and distribute the bin content of the coarse bin into the fine bins.
If the number of bins is a multiple of the coarse number (N*n_coarse), and the axis ranges are the same, i.e. the bins align perfectly, it’s enough to just divide the bin content of coarse_i by N, and write this into all N bins that overlap with the coarse bin.

It worked. Thank you so much

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