# Problem in Colz text e

**URL:** <https://root-forum.cern.ch/t/problem-in-colz-text-e/26049>\
**Category:** ROOT\
**Created:** [August 28, 2017, 5:58pm UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049 "2017-08-28T17:58:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![nab](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nab](https://root-forum.cern.ch/u/nab)\
**Post date:** [August 28, 2017, 5:58pm UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/1 "2017-08-28T17:58:32Z")

</div>

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.

Cheers,  
Nab

[loose.cc](https://root-forum.cern.ch/uploads/default/original/2X/e/ef6c7b54cc1101936d992c5936fe10e74dd61ea6.cc) (2.9 KB)  
[tt\_final\_new.root](https://root-forum.cern.ch/uploads/default/original/2X/3/3f283cf11b25067bf3895b06cde00c60812c7b45.root) (10.0 KB)

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [August 29, 2017, 9:34am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/2 "2017-08-29T09:34:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 29, 2017, 9:39am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/3 "2017-08-29T09:39:09Z")

</div>

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](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/4). 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).

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [August 29, 2017, 9:54am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/4 "2017-08-29T09:54:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 29, 2017, 10:00am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/5 "2017-08-29T10:00:18Z")

</div>

```auto
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.

[nt2.cc](https://root-forum.cern.ch/uploads/default/original/2X/2/2a2dd405dbada940942630f1c9e27855e2d94fa4.cc) (3.7 KB)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [August 29, 2017, 2:12pm UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/6 "2017-08-29T14:12:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 29, 2017, 2:36pm UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/7 "2017-08-29T14:36:56Z")

</div>

Hi,

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),

Lorenzo

---

<div class="post-metadata">

**Author:** ![nab](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nab](https://root-forum.cern.ch/u/nab)\
**Post date:** [August 29, 2017, 5:27pm UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/8 "2017-08-29T17:27:30Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 30, 2017, 7:11am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/9 "2017-08-30T07:11:58Z")

</div>

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

Lorenzo

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [August 30, 2017, 9:10am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/10 "2017-08-30T09:10:19Z")

</div>

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.

> [@Problem in 2D histograms calculations](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/11):
>
> Until a proper “rebin” method for 2-D histograms is implemented (if ever), you can try to use the attached macro. [nt2.cc](https://root-forum.cern.ch/uploads/default/original/2X/e/e4dadb39641dc7aade37004e90fc77c33a5a7206.cc) (5.6 KB)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [September 13, 2017, 9:10am UTC](https://root-forum.cern.ch/t/problem-in-colz-text-e/26049/11 "2017-09-13T09:10:26Z")

</div>

Closed on September 13, 2017, 9:10am UTC

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