# Drawing a TH3D Histogram

**URL:** <https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619>\
**Category:** Newbie\
**Created:** [June 14, 2019, 5:42pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619 "2019-06-14T17:42:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marisa\_P](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marisa_p/32/20288_2.png) [@Marisa\_P](https://root-forum.cern.ch/u/Marisa_P)\
**Post date:** [June 14, 2019, 5:42pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/1 "2019-06-14T17:42:21Z")

</div>

Hello! I am trying to fill a histogram with x, y, and z variables, and I would like the color of each bin to reflect the number of entries in the bin. I am trying to use a TH3D, defined by the following:

```auto
// Histograms
        TH3D * h_q1_l = new TH3D("h_q1_l","Quartz 1 Map, Low Resolution",25,-0.025,0.025,50,-0.05,0.05,12,140,200);

```

And I fill it in and draw it with the following:

```auto
for (int ievt = 0; ievt < entries; ievt++)
        {
                t_T->GetEntry(ievt);
                cout << qx1 << endl;
                h_q1_l->Fill(qx1,qy1,ladc0);
        }

h_q1_l->Draw("SURF2");

```

However, when I draw the histogram it is completely empty. It has the correct number of entries, but no colors show up, and the means are all 0. This is true for all TH3D options, not just SURF2. I am 100% certain this is not an issue with my ROOT tree because if I change the histogram to a TH2D (removing the last 3 parameters in the definition), and leave the rest of the code as is, the histogram won’t be empty.

Please let me know if I am doing something wrong with my definition or Fill() function, or if there might be a better way to do this. Thank you!

---

<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:** [June 14, 2019, 5:56pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/2 "2019-06-14T17:56:47Z")

</div>

[Drawing options for 3D histograms](https://root.cern.ch/doc/master/classTHistPainter.html#HP25)

---

<div class="post-metadata">

**Author:** ![Marisa\_P](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marisa_p/32/20288_2.png) [@Marisa\_P](https://root-forum.cern.ch/u/Marisa_P)\
**Post date:** [June 14, 2019, 6:04pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/3 "2019-06-14T18:04:11Z")

</div>

According to this documentation, I am defining everything correctly. This does not answer why the histogram is empty. ![empty_hist](https://root-forum.cern.ch/uploads/default/original/3X/9/f/9f430ca5204ac0dd14a11dba1a62c6b5e66f9357.png)

---

<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:** [June 14, 2019, 6:10pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/4 "2019-06-14T18:10:10Z")

</div>

Before drawing, try to add: `gStyle->SetOptStat("nemruoi");`

---

<div class="post-metadata">

**Author:** ![Marisa\_P](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marisa_p/32/20288_2.png) [@Marisa\_P](https://root-forum.cern.ch/u/Marisa_P)\
**Post date:** [June 14, 2019, 6:19pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/5 "2019-06-14T18:19:55Z")

</div>

I tried adding this before and after the histogram was defined, but the histogram is still empty. Here is my code and the ROOT file, if they help. [QuartzMap.C](https://root-forum.cern.ch/uploads/default/original/3X/6/a/6aff4ddf7419f469195b40d424a56faafe263f31.C) (2.3 KB)  
[test\_430\_verf.root](https://root-forum.cern.ch/uploads/default/original/3X/4/b/4b4cd31ac435af3b162f5ba8ae4fdff4c3365c67.root) (88.7 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:** [June 14, 2019, 6:28pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/6 "2019-06-14T18:28:58Z")

</div>

Try with:

```auto
	TH3D *h_q1_l = new TH3D("h_q1_l", "Quartz 1 Map, Low Resolution;qx1;qy1;ladc0", 25, 0., 0., 50, 0., 0., 12, 0., 0.);

```

---

<div class="post-metadata">

**Author:** ![Marisa\_P](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/marisa_p/32/20288_2.png) [@Marisa\_P](https://root-forum.cern.ch/u/Marisa_P)\
**Post date:** [June 14, 2019, 6:33pm UTC](https://root-forum.cern.ch/t/drawing-a-th3d-histogram/34619/7 "2019-06-14T18:33:10Z")

</div>

It is now being filled! Thank you for your help!
