Home | News | Documentation | Download

Boost-1.70 released, new library boost::histogram

It has been a while since I announced here that the boost::histogram library is nearing completion. And now it happened, Boost-1.70 was released on April 12th, 2019, with boost::histogram.

github https://github.com/boostorg/histogram
documentation https://www.boost.org/doc/libs/1_70_0/libs/histogram/doc/html/index.html
chat with me https://gitter.im/Scikit-HEP/community or https://cpplang.slack.com

boost::histogram is a powerful library to make histograms, profiles, and more. boost::histogram was designed to be useful for the beginner and expert alike. It is very customizable, but the defaults are set so that it is safe, fast, memory-efficient for people who just want to get work done. The design is similar to RHist, but offers even more flexibility. It can replace TH1, TH2, TH3, THn, THnSparse, TProfile, TProfile2D, TProfile3D. In the future, it could also replace TProfile2Poly.

A Python frontend is currently developed by Henry Schreiner and myself, an alpha version can be accessed here.


Thanks, Hans!

I am aware of a couple of other (also C++) histogram libraries, too. Yours is nice, and we want RHist to be at least as nice :wink: I’m curious to hear how we can improve ROOT’s histograms based on what you have learned!

Cheers, Axel.

Why not reuse the existing code?
Why create yet another library which will not be compatible with anything else?

Last but not least, can ROOT be convinced to deal with / import “boost::histogram”?

Dear Axel,

the point of making boost::histogram was to offer a standard solution so that people can stop reinventing histograms. All code has bugs, but if many people use the same code, it is going to have fewer bugs. That’s why boost::histogram was designed to be super flexible, so that if you don’t like a given part, you can switch that out and still use the rest.

Conceptually, histograms and profiles can be split into three orthogonal components (as explained here)

  • Axes: converts values to bin indices
  • Storage: manages memory for the histogram cells
  • Accumulators: the object that sits in a cell and reacts to data that is sorted into the cell

The components are orthogonal, because they can be combined arbitrarily, they only talk through their respective interfaces to each other. To get a sparse histogram, you replace a array-based storage with a map-based storage. To go from histogram to profile, you replace an integer or floating point counter per cell with an object that keeps track of the sum of values and the number of times a value was entered in each cell. This design allows maximum code re-use.

You could replicate these ideas in ROOT, but that would go against the idea of sharing as much code as possible to have fewer bugs and ease maintenance.

It is said here that ROOT 7 will use “standard C++ types”, so why not use boost::histogram as the foundation for a custom histogram class. ROOT 7 could inherit from boost::histogram and implement a ROOT-like interface and additional capabilities on top of that foundation. boost is the best standard in the C++ world next to having something in the official C++ standard library.

I also want to be be clear that boost::histogram only addresses the focused problem of histogramming and profiling data, it does not provide functionality to fit data or to plot data. These features should come from other libraries such as ROOT.

Thank you for this statement, I also think that it best if we share as much code as possible. boost::histogram is an honest attempt to establish an open standard for histograms in the C++ world, which should benefit everyone. As explained in my answer to Axel, I think it would be great if libraries such as ROOT would build their tools on top of standard solutions. C++ offers interfaces and encapsulation, so nobody has to see boost::histogram on the surface. Still, by using it internally, one gains from external improvements and maintenance of the implementation.

Note that you can depend only on header only parts of Boost in order to use Boost::Histogram, no built components are required. Might make building RHist on top of Boost::Histogram an interesting possibility…

Libraries like boost::histogram are usually much more accessible than any ROOT solution since the overhead of getting it is much lower.

It would be nice to move as many general features out of ROOT to make them available to the general public :).