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) h1s[int(xbin)].Fill(value) c1 = ROOT.TCanvas("c1","c1") stack = ROOT.THStack(h2, "y") stack.Draw("pads") c2 = ROOT.TCanvas("c2","c2") c2.Divide(3,3) for (i,h) in enumerate(h1s): c2.cd(i+1) h.Draw()
c1 and c2 show the very same result. The final implementation will be in C++.
Thanks in advance,