Create a 2D histogram from two histograms

Hi,
I am wondering if there is way to create a 2D histogram from two other histograms which are stored in the root file. Mainly, I have the Muon_eta and Muon_phi variables, which I want to plot as a function of each other. F.g. on y axis Muon_eta and on x axis Muon_phi. How could I do this?
Thanks!

That’s not possible,
You need to fill the 2D histogram from the original tree variables.

Oh, that’s sad to know… But let’s say if I want to fill it from the original tree variables Muon_eta and Muon_phi, then how do I fill them?

tree->Draw("Muon_eta:Muon_phi");

Thank you…
In my case, given that I already have these variables stored in the root file, isn’t there a way around like, for example, extract X and Y values from each histogram and plot them in 2D hist? Then from Muon_eta I would have X1 and Y1 values, let’s say array of them, and from Muon_phi X2 and Y2 values… and then fill a 2D hist with these…

Otherwise, could you please expand your answer to how could I apply this to analysis code with RDataFrame, where I need to explicitly create and fill a 2D histogram in one go, and then draw it with hist.emplace since there is no option of simply doing it like you said…
Just an example of how I am doing it for 1D histograms:
auto muon_pt = df.Histo1D( {"Muon_pt","",50,0,200}, "Muon_pt", weight); hist.emplace("BasicDistributions", muon_pt);

Histo2D

1 Like

Alright, thank you, I will rerun the whole analysis then if there is no other option… But just to make it clear, it’s not possible to do it the way I described above?

Only 2D → 2 x 1D is possible.

Search for “profile” and “projection” in the TH2 class reference.