Fixed derivatives in histogram

(backported from master, see commit 92717cb65fc1b2a67be0adb01c635c6fce0a905f)
Fixed regtest

After 4525d50f4babf4db72acf0831c49055558ebac66
changelog