# Problem in 2D histograms calculations

**URL:** <https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029>\
**Category:** ROOT\
**Created:** [August 26, 2017, 4:24am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029 "2017-08-26T04:24:56Z")\
**Posts on this page:** 12\
**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 26, 2017, 4:24am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/1 "2017-08-26T04:24:56Z")

</div>

Dear developers,

I am writing a script in which i am trying to rebin my histograms and draw them in “colz text e” draw option. At the same time i want to evaluate this formula  
nt3 = f\*nt2/(1-f)  
I am not doing the job correctly. I did what I understand. Please help me to solve this issue.  
I am attaching my script and root file.

Cheers,  
nab

[tt\_final\_new.root](https://root-forum.cern.ch/uploads/default/original/2X/3/3f283cf11b25067bf3895b06cde00c60812c7b45.root) (10.0 KB)  
[nt2.cc](https://root-forum.cern.ch/uploads/default/original/2X/6/68b0f77492eb635bfe45e17a218f3faacc1b0e1d.cc) (2.1 KB)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 26, 2017, 6:51am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/2 "2017-08-26T06:51:26Z")

</div>

Hi,

what is the actual issue? We cannot debug/write your code 😅

---

<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 26, 2017, 6:59am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/3 "2017-08-26T06:59:09Z")

</div>

Hi,

The actual issues are 🙂

1. I donot know how to draw histograms in “colz text e”
2. I want to mutliply two 2D histograms and then draw in “colz text e”
3. Basically i have to calculate the above mentioned formula

nt3= f\*nt2/1-f  
where f and nt2 are 2D histograms and f=h1/h2

---

<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 26, 2017, 11:36am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/4 "2017-08-26T11:36:29Z")

</div>

Note: you cannot change histogram binning the way you try it. You need to use the “correct” binning when you create your histograms (which are then stored in your “tt\_final\_new.root” file).

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

---

<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 26, 2017, 11:47am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/5 "2017-08-26T11:47:14Z")

</div>

Dear Wile\_E\_Coyote,

Thank you.  
Is there is some other way to change the bining of the histograms. Because at that instance I cannot change the binning due to long running jobs, it will take much time to do it again.

---

<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 26, 2017, 12:06pm UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/6 "2017-08-26T12:06:06Z")

</div>

Dear Wile\_E\_Coyote,

I want the following plot. That is why I changed the bin size. I just want to plot my data inside these bins.

 ![plot](https://root-forum.cern.ch/uploads/default/original/2X/e/edd941f4d020bff1b95ff4785e86f535e6dd375a.jpg)

---

<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 26, 2017, 5:01pm UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/7 "2017-08-26T17:01:23Z")

</div>

I modified the “[nt2.cc](http://nt2.cc)” macro in my previous post. it includes some “rebinning” now (this is the closest to what you want, which can be achieved with your current histograms).

---

<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 27, 2017, 4:18am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/8 "2017-08-27T04:18:58Z")

</div>

Dear Wile\_F\_Coyote,

I am again facing difficulty in binning the histograms like above mentioned plot. When I will try to rebin x and y axis seperately it will not plot the data in the respective bins.  
bin\_x={10,20,40,75,100,150}  
bin\_y={1,1.5,2,2.5,3}  
It just give me the points in these bins. I want the color plot like above.  
Kindly help me to do it.

Cheers,  
Nab

---

<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, 10:36pm UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/9 "2017-08-28T22:36:17Z")

</div>

Thank you Wile\_E\_Coyote for your unconditional help 😃

---

<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, 6:27pm UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/10 "2017-08-29T18:27:45Z")

</div>

Dear Wile\_E\_Coyote,

I have used the script sent by you. I changed the binning like

" int nxg = 8, nyg = 30; // how many bins to merge  
int nxf = 2, nyf = 0; // the first bin to use / draw  
int nxl = 3, nyl = -2; // the last bin to use / draw  
"  
I am getting the plot like below. I want to change y-axis 0-3 (0-1, 1-2, 2-3)with equal bin size (if variable binning is not possibe). How I would get this.

Thanks.  
Nab  
[loose\_ttbar.root](https://root-forum.cern.ch/uploads/default/original/2X/b/b344b5698c9fa293f011b2489975c5a6186ddd1d.root) (13.0 KB)

---

<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, 11:52am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/11 "2017-08-30T11:52:50Z")

</div>

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, 11:53am UTC](https://root-forum.cern.ch/t/problem-in-2d-histograms-calculations/26029/12 "2017-09-13T11:53:06Z")

</div>

Closed on September 13, 2017, 11:53am UTC

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