# TH2 from a TH3 slice

**URL:** <https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386>\
**Category:** General Chat\
**Created:** [April 6, 2023, 8:00am UTC](https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386 "2023-04-06T08:00:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![martis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@martis](https://root-forum.cern.ch/u/martis)\
**Post date:** [April 6, 2023, 8:00am UTC](https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386/1 "2023-04-06T08:00:36Z")

</div>

Hello,  
I would like to store a TH2 from a TH3 slice. Actually, the idea is like the SetShowProjection, but I want to do it from a macro and store the TH2 for comparison with other TH2.

Is that possible? I guess so.

Thanks  
Salva

---

<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:** [April 6, 2023, 8:08am UTC](https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386/2 "2023-04-06T08:08:18Z")

</div>

> [@Drawing dose volume histograms (DVHs)](https://root-forum.cern.ch/t/drawing-dose-volume-histograms-dvhs/44858/3):
>
> You can project a 3-d histogram into 1-d or 2-d (also profile) histograms: [TH3::Project3D](https://root.cern/doc/master/classTH3.html#a94dd0a21d42fd95756e906e7f50fa293) ; [TH3::ProjectionX](https://root.cern/doc/master/classTH3.html#a6b8fe187592c6c36f5e443535a480af6) ; [TH3::ProjectionY](https://root.cern/doc/master/classTH3.html#a38e8e5a4a25027b1f399637b70afb8bd) ; [TH3::ProjectionZ](https://root.cern/doc/master/classTH3.html#a65ed465ab42638e18ba9ee50b14fa4ad) ; [TH3::Project3DProfile](https://root.cern/doc/master/classTH3.html#a6d7a16f7b0b13019e649a03f3ee35684)

---

<div class="post-metadata">

**Author:** ![martis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@martis](https://root-forum.cern.ch/u/martis)\
**Post date:** [April 6, 2023, 8:33am UTC](https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386/3 "2023-04-06T08:33:26Z")

</div>

Thanks a lot for pointing me to [TH3:.Project3D](https://root.cern/doc/master/classTH3.html#a94dd0a21d42fd95756e906e7f50fa293). It looks like Projec3D only takes one argument.

What I would like is to make a slice of a TH3. The idea I have in mind is: myTH3-\>Project3D(“xy”,fromZbin=1,toZbin=1), and then repeat for other bins in Z.  
Actually, this is something similar to SetShowProjection(“xy”,1) and then change the bin

Thanks  
Salva

---

<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:** [April 6, 2023, 8:36am UTC](https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386/4 "2023-04-06T08:36:01Z")

</div>

The [TH3::Project3D](https://root.cern/doc/master/classTH3.html#a94dd0a21d42fd95756e906e7f50fa293) explicitly says that you need to use [TAxis::SetRange](https://root.cern/doc/master/classTAxis.html#aed523b084d6b3f24f6b1128d7810e199) to select a bin range along an axis (and don’t forget to “reset” the range after you are done).

---

<div class="post-metadata">

**Author:** ![martis](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@martis](https://root-forum.cern.ch/u/martis)\
**Post date:** [April 6, 2023, 8:40am UTC](https://root-forum.cern.ch/t/th2-from-a-th3-slice/54386/5 "2023-04-06T08:40:30Z")

</div>

Thanks
