The way you specify the upper limit of your histogram looks a bin weird seems to me.
h2->GetNbinsX() will give you an integer corresponding to the number of bin along the
X axis o the histogram h2… is that really what you want ? is it not the upper edge of the last bin ?
I assume he wants to have “h2->GetNbinsX()” bins with bin centres at 0, 1, 2, …, (h2->GetNbinsX() - 1).
BTW. I think it would be more convenient if one used: TH1F *h1 = new TH1F("h1", "YProfile", h2->GetNbinsX(), 0.5, h2->GetNbinsX() + 0.5); Sooner or later one will try to draw it using the “Log” scale for “X”, so having all “X” axis values positive is a really good choice (actually, I have just noticed that if the scale begins at -0.5 then the “Logx” draws the histogram improperly -> “bin borders” in the canvas do not coincide with “x_bin_number -/+ 0.5”).