Overlaying ProfileY on TH2D

Hello Everyone,

I have these two plots that I would like to overlay on top of each other. But, some how I am unable to. Here is a pdf of the plots: overlayingPlots.pdf (154.8 KB)

What I want is for the ProfileY plot to be superimposed onto the TH2D plot. Here is my attempt:

cloneHistogram2->Draw("colz [cut1]");
TProfile* histo2ProfY1 = cloneHistogram2->ProfileY("histo2ProfY1", 0, -1, "[cut1]");
histo2ProfY1->SetLineWidth(2);
histo2ProfY1->SetLineColor(kBlack);
histo2ProfY1->Draw("SAME");

But that doesn’t seem to work, and from the searching around I have done, it seems like it is a problem related to the fact that I am using TProfileY and not TProfileX.

I also don’t really get the solution provided on the following thread from 2011, but there might be a more robust solution by now for this problem:

Can someone please help me with this? Thank you very much!

The plots do have very different axis ranges they will not overlay properly. Can you post the plot you get ?

I actually don’t end up being able to get a plot with the way I approach it. It only shows the 2D plot with no 1D overlay.

One point is that, as couet said, in your TProfile the scales of x-y don’t match the 2D plot, so even if you could do “same”, the second plot wouldn’t show --in fact, x and y are swapped, so you may want to swap them back if you want them to represent the same.
Anyway maybe you can try sometihng like this (create a second Pad on top of the first one and draw the second plot there):

1 Like