completing the function "ght_tree_calculate_z"