Pros/cons using projected TH2 as replacement for many TH1s

Dear all!

I would like to ask the experts for a short answers to the following question before I start profiling myself:

Apart from bookkeeping, which pros and cons do you see in using a TH2 from which TH1s are projected for each bin in a postprocessing step compared to using only TH1s in the first place?

import ROOT
ROOT.gRandom = ROOT.TRandom3(0)

nxbins = 9
h1s = [ROOT.TH1D("h1_%d"%i,"h1_%d"%i, 100, -5, 5) for i in xrange(nxbins)]
h2 = ROOT.TH2D("h2","h2", nxbins, 0, nxbins, 100, -5, 5)

for x in xrange(100):
    xbin = ROOT.gRandom.Uniform(nxbins)
    value = ROOT.gRandom.Gaus()
    h2.Fill(xbin, value)

c1 = ROOT.TCanvas("c1","c1")
stack = ROOT.THStack(h2, "y")

c2 = ROOT.TCanvas("c2","c2")
for (i,h) in enumerate(h1s):

c1 and c2 show the very same result. The final implementation will be in C++.

Thanks in advance,



If in the end you use TH1, the least amount of CPU work is to create the TH1 in the first place. The downside will be that the initial memory cost will be slightly larger (more meta data) at the ‘beginning’ (i.e. until the TH1 are created by the projection … at which time the total memory use will be larger (all the data being duplicated) …