Problem in Colz text e

Dear developers,

I am writting a script in which I am getting different 2D histograms and do some calculations (as suggested by Wile_E_Coyote ). After that I am plotting the histograms in Colz text e format. But the main issue is I am drawing different histograms having different entries like tight histo, loose histo, nt2, nt3 etc but it will only plotting tight entries values on all plots.
Secondly when I divide two histograms h1/h2 it give me an error of “unequal bin size division”, and for Nt3 it gives me potential memory leak. Kindly help me to resolve this problem.

Nab (2.9 KB)
tt_final_new.root (10.0 KB)

I do not understand exactly what you are trying to do, but you are redefining the h2 variable and drawing it in the same canvas that then you draw the original h2 coming from the file.

The core of the problem is that (s)he wants to rebin a “fix bin sizes” 2-D histogram into a “variable bin sizes” histogram. Current ROOT (up to and including 6.10.04) supports it only for 1-D histograms (i.e. not for 2-D, neither for 3-D histograms -> I guess you could put it on your “to-do” list).

1 Like

Wouldn’t Add()ing the fixed bin hist to the variable bin hist solve this, also for 2D? I thought that’s an operation we support?

Info in <TH2D::Add>: Attempt to add histograms with different number of bins - trying to use TH1::Merge
Error in <Merge>: Cannot merge histograms - limits are inconsistent:
 first: h1 (4, 10.000000, 100.000000), second: third_tight_mu_pt_eta (100, 0.000000, 300.000000)

And even if I use “h1 (6, 0.000000, 300.000000)”, the same errors are still there. (3.7 KB)

Thanks, @Wile_E_Coyote! Okay, we need help from @moneta here :slight_smile:


Histogram with different bins cannot be added or merged. TH1::Merge supports adding histogram with compatible bins, but only for the non-variable case and if there are common bin edges.
For example you can merge h1 (0,1,2,3,4) with h2(0,2,4),



It means I can add them but set the range of new histograms from 0 to onward?
Am I correct?

No, as I have said before you cannot add (or merge) a variable size histogram with am histogram with fixed bin size.
The only solution for you is to loop on bins of the histogram with finer binning, grep the content using GetBinContent and then re-set the correct content in the target histogram using SetBinContent


SetBinContent does not manage bin errors’ propagation (nor any “statistics” propagation) at all. That’s why proper “rebin” methods for 2-D and 3-D histograms are really needed.

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