Add missing protection in OptimizeBasket.

Some of the branch (because they have been disabled for
example) may not have any entry.  So we now protect
against this case (actually seen in stress).

This fixes ROOT-5410