(since we are still fishing for a problem in this PR, why not make a simple fix)
! iDetIds.empty()
(and similarly below) takes less cycles