Filling a TH2 from two existing TH1

Hi rooters,

I want to fill a TH2 histogram with data stored in two different TH1 histograms. The 1-dimensional histograms are extracted by means of the Project3D method from TH3 histograms, which in turn belong to different TTree objects.

Have you any idea on how I can do this?


This can’t be done.
Assume your first TH1 contains “n” bins (i.e. you have “n” bin values) and your second TH2 contains “m” bins (i.e. you have “m” bin values) … then you have “n+m” bin values in total.
Now, TH2 would contain “nm" bins, so you would need to provide "nm” bin values.

So basically, If I know the number of bins I need, I can allocate the TH2 and then fill it by… “for loops”?
Or I misunderstood your reply? :confused:

In a loop, you can use any of the available “Fill” methods or the “SetBinContent” method: