That's what Buddhism has been trying to unravel - the mechanism of happiness and suffering. It is a science of the mind.