Plot histogram from root file and write to a new root file

Try to also use: m.Fill(pt) # weight = 1.

Actually, it seems to me that you are missing (right before “pt = ...”): tree.GetEntry(entryNum)