Fixed the branch ordering

This fixes a critical bug in the ordering of the logic tree branches. As a consequence a wrong number of realizations was generated. No tests covered that bug, but it was affecting Yufang's SHARE computation, by generating 20 realizations instead of 320, so I discovered it. Since this is a serious problem I am going to give a LGTM to myself and open a ticket to add a test covering the issue