Fill TH2D with 2 TH1D data sets

Hi all,

I’m reading and plotting two 1D histograms from a root file successfully and would like to create a TH2D histogram with the data in those 2 TH1D objects. How can I fill the TH2D histo with that data?



Hi Tim,

In order to fill the 2D histogram, you’d need the original data used to fill the two 1D histograms in order to know about the correlations. They cannot be reconstructed from the two 1D histograms alone.

If you have the original data points, you can fill a TH2D histogram with its Fill() method that takes both an x and an y value.


Hi Jakob,

thanks for the reply.

So it seems to be impossible to pass the data into a TH2D from 2 TH1D’s?

I’ve just a bit of investigating and it seems I can pull the bin contents entry by entry (TH1D->GetBinContent(int_t bin)) and then fill the TH2D entry by entry. Tedious but possible. I’ll try that over the next few days.

Thanks again.



It’s impossible because the information on the other variable is lost when creating the 1D histograms, the correlations cannot be restored afterwards. See for instance 2D plot draw command using 2 1D histograms

Thanks Jakob. I was having a dumb moment. Of course you can extract 1D histograms from a 2D but you can’t construct a 2D histogram from two 1D histograms.