# Automatically separate histogram into X ~equally portions

**URL:** <https://root-forum.cern.ch/t/automatically-separate-histogram-into-x-equally-portions/49413>\
**Category:** Newbie\
**Created:** [March 30, 2022, 8:37pm UTC](https://root-forum.cern.ch/t/automatically-separate-histogram-into-x-equally-portions/49413 "2022-03-30T20:37:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abunka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@abunka](https://root-forum.cern.ch/u/abunka)\
**Post date:** [March 30, 2022, 8:37pm UTC](https://root-forum.cern.ch/t/automatically-separate-histogram-into-x-equally-portions/49413/1 "2022-03-30T20:37:58Z")

</div>

Hello,  
is there a way that I can divide a histogram into a number of sections, roughly equal in the number of entries?  
For example, I have a 2d histogram and I want to take the projection in 6 different regions, with a nearly equal number of entries ending up in each section (it can’t be equal because of binning I guess). I can request the projection to cover only a select range of bins, but what should I do to get these sections to cover similar event counts without going through them by hand?  
ROOT 6.20/06 on lxplus  
Thanks!

---

<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:** [March 31, 2022, 5:36am UTC](https://root-forum.cern.ch/t/automatically-separate-histogram-into-x-equally-portions/49413/2 "2022-03-31T05:36:09Z")

</div>

I am not sure ROOT provides an automatic way to do that. I guess you will need to implement the algorithm yourself. @moneta can confirm.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 31, 2022, 7:25am UTC](https://root-forum.cern.ch/t/automatically-separate-histogram-into-x-equally-portions/49413/3 "2022-03-31T07:25:41Z")

</div>

Hi,  
In reality we have something to divide the histograms in different regions according to the integral content. Look at [`TH1::GetQuantiles`](https://root.cern.ch/doc/master/classTH1.html#a2be4a5889f7421047d68b0a398675b8d). There is also a tutorial for this: [ROOT: tutorials/math/hlquantiles.C File Reference](https://root.cern.ch/doc/master/hlquantiles_8C.html).

Cheers

Lorenzo
