# Getting TH1F for a bin from TH2F

**URL:** <https://root-forum.cern.ch/t/getting-th1f-for-a-bin-from-th2f/45674>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [July 4, 2021, 10:25am UTC](https://root-forum.cern.ch/t/getting-th1f-for-a-bin-from-th2f/45674 "2021-07-04T10:25:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aman\_Upadhyay](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aman_upadhyay/32/23958_2.png) [@Aman\_Upadhyay](https://root-forum.cern.ch/u/Aman_Upadhyay)\
**Post date:** [July 4, 2021, 10:25am UTC](https://root-forum.cern.ch/t/getting-th1f-for-a-bin-from-th2f/45674/1 "2021-07-04T10:25:59Z")

</div>

Hi ROOT users,

I have a TH2F histogram with an x and y-axis. I want to extract the distribution of x variable for a particular y bin (or value). This should be a TH1F. Is there a way to extract bin-specific TH1F from TH2F?

I am new to root and stuck with this problem for some time now, and I will be very grateful for any help.

* * *

ROOT Version:6.24/00  
Platform:(NAME=“HefftorLinux”,ID\_LIKE=“arch”,VERSION\_ID=v2021-02-05)  
Compiler: gcc 11.1.0

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [July 4, 2021, 10:43am UTC](https://root-forum.cern.ch/t/getting-th1f-for-a-bin-from-th2f/45674/2 "2021-07-04T10:43:16Z")

</div>

Use [TH2F::ProjectionX](https://root.cern.ch/doc/master/classTH2.html#a974ece9e7d260f92df00a39dba14e5b0) See for example the [DynamicSlice.C](https://root.cern/doc/master/DynamicSlice_8C.html) tutorial.

---

<div class="post-metadata">

**Author:** ![Aman\_Upadhyay](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/aman_upadhyay/32/23958_2.png) [@Aman\_Upadhyay](https://root-forum.cern.ch/u/Aman_Upadhyay)\
**Post date:** [July 4, 2021, 10:59am UTC](https://root-forum.cern.ch/t/getting-th1f-for-a-bin-from-th2f/45674/3 "2021-07-04T10:59:03Z")

</div>

Thanks a lot!
