Memory usage of 3D and 2D+1D histogram

just a simple question out of curiosity. I am creating a lot of histograms (~5000) in my ARA analysis and I recently switched from 2D+1D histogram combination (for pt eta/phi distributions) to 3D histograms to reduce the number of histograms. Now I get an error:

Exception: St9bad_alloc (C++ exception)

I traced this back and it happens right after I have created a 3D histogram and when I try to call histo.Sumw2(). I suspect it is a memory problem.

So I was wondering if a 3D histogram uses more memory that the combination of 2D+1D histogram which seems to be the case after my observation.


The space used by TH3 is nXnYnZ bins.

To save memory, you may consider THnSparse a multi-dim histogram. see: