# How to round values before plotting 2D histogram from TTree

**URL:** <https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [June 15, 2023, 3:50pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315 "2023-06-15T15:50:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [June 15, 2023, 3:50pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/1 "2023-06-15T15:50:11Z")

</div>

Hi,

I want to plot a 2D histogram from a TTree, I use the following command :

```auto
tree11->Draw("(1.6*QdcQ[1]/1.5):1.6*QdcQ[0]>>h12");

```

and I get the following plot :

![image](https://root-forum.cern.ch/uploads/default/original/3X/2/8/2834531cb9a19fd77c1506dd903818ace7851a99.png)

But it seems that I have decimal values (as I multiply and divide with decimal numbers before plotting), I would like to round the values in the branches before plotting, how can I do it, I tried using Nint but it doesn’t work.

Thank you !

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 15, 2023, 3:55pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/2 "2023-06-15T15:55:58Z")

</div>

```auto
ntuple->Draw("TMath::Nint(px):py")

```

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [June 15, 2023, 4:39pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/3 "2023-06-15T16:39:55Z")

</div>

I tried this but still it doesn’t work :

What I did was I set the maximum of the histogram and then plot like :

```auto
h12->SetMaximum(5);
tree11->Draw("TMath::Nint(1.6*QdcQ[1]/1.5):(TMath::Nint(1.6*QdcQ[0]))>>h12");

```

and I have the same figure.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 16, 2023, 7:08am UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/4 "2023-06-16T07:08:42Z")

</div>

You said:

> [@gini](#):
>
> I would like to round the values in the branches before plotting,

That is exactly what `TMath::Nint` does in the last command you posted. What should be an integer? axis value or the histogram content (the histogram content is also btw)?

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [June 16, 2023, 8:19am UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/5 "2023-06-16T08:19:37Z")

</div>

I see that in the color palette, I have values from 1 to 5 (from the figure), with decimal values, I want to have rounded values here ie., I want to round the histogram content.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 16, 2023, 8:40am UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/6 "2023-06-16T08:40:01Z")

</div>

The histogram `h12` is filled with integer values because by default the weight of each “fill” is 1. The fact palette axis shows decimal values does not mean your histogram has decimal contents. It is only because the number of divisions for the Z axis is too large. Reduce it until you see integer values only.

Also, if your historgam has only 4 values on Z you might want to have a palette with 4 colors only.

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [June 16, 2023, 3:18pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/7 "2023-06-16T15:18:23Z")

</div>

I tried to reduce the Z axis but still I dont get integer values, also I made a palette with 4 colours.  
I am attaching the root file here with.  
[try.root|attachment]  
[nez.root](https://root-forum.cern.ch/uploads/short-url/5P7zZUKcCfzd93fbyWbqnWb6jQz.root) (1.8 MB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 16, 2023, 3:21pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/8 "2023-06-16T15:21:21Z")

</div>

```auto
h12->GetZaxis()->SetNdivisions(5);

```

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [June 16, 2023, 3:22pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/9 "2023-06-16T15:22:53Z")

</div>

> [@couet](#):
>
> `h12->GetZaxis()->SetNdivisions(505);`

Amazing! That works…  
Thank you for the prompt response.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 16, 2023, 3:25pm UTC](https://root-forum.cern.ch/t/how-to-round-values-before-plotting-2d-histogram-from-ttree/55315/10 "2023-06-16T15:25:44Z")

</div>

If that’s you want I am not sure you need the Nint in the draw command
