# How to find mode or maximum bin of a data set

**URL:** <https://root-forum.cern.ch/t/how-to-find-mode-or-maximum-bin-of-a-data-set/62773>\
**Category:** Newbie\
**Created:** [January 27, 2025, 7:34pm UTC](https://root-forum.cern.ch/t/how-to-find-mode-or-maximum-bin-of-a-data-set/62773 "2025-01-27T19:34:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spencer\_H](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spencer_h/32/38360_2.png) [@Spencer\_H](https://root-forum.cern.ch/u/Spencer_H)\
**Post date:** [January 27, 2025, 7:34pm UTC](https://root-forum.cern.ch/t/how-to-find-mode-or-maximum-bin-of-a-data-set/62773/1 "2025-01-27T19:34:51Z")

</div>

_ROOT Version:_ 6.34.02  
_Platform:_ Linux  
_Compiler:_ CMake

* * *

I’m new to ROOT so I’m looking for a simple way to find the mode of a data set or the x-axis value of the maximum bin in a histogram. Is there a command I can use in the browser or documentation on how to do this task?

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 28, 2025, 5:05am UTC](https://root-forum.cern.ch/t/how-to-find-mode-or-maximum-bin-of-a-data-set/62773/2 "2025-01-28T05:05:26Z")

</div>

You can find and search all the documentation at  
[https://root.cern/doc/master/](https://root.cern/doc/master/)  
(use the drop list at the top to select a given ROOT version if needed). You can also get there by clicking “Home” at the top of these forum’s pages, and then clicking on “Reference” on that home page.  
As for finding the bin (x-axis) with the maximum (y-axis value) of a histo, you can use

```auto
Int_t binNo = h->GetMaximumBin();

```

where `h` is your histo; see  
[https://root.cern/doc/master/classTH1.html#abb474ee303d1b44ffdf800803f12c7ad](https://root.cern/doc/master/classTH1.html#abb474ee303d1b44ffdf800803f12c7ad)  
but note that it returns the _bin number_, not the x-axis value that you see in the plotted x-axis; for the “real” value, once you have the bin number you can use any/all of:

```auto
h->GetXaxis()->GetBinCenter(binNo);
h->GetXaxis()->GetBinLowEdge(binNo);
h->GetXaxis()->GetBinUpEdge(binNo);

```

depending on what you want; see these methods here:  
[https://root.cern/doc/master/classTAxis.html#a299bed7dfb2452a7cc026e16f249f25c](https://root.cern/doc/master/classTAxis.html#a299bed7dfb2452a7cc026e16f249f25c)
