How to reset the range and size of Bin?

As @alex_HXY said you should create h2with the same number of bin as h1.

Also I see that you create h3 with the name "n_energy_p/n". That’s not a good idea to have “/” in histograms’ names. See: