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?
You can find and search all the documentation at
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
Int_t binNo = h->GetMaximumBin();
where h
is your histo; see
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:
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
1 Like