function calc_pgen_triple(nI, ex) result(pgen)
! get the probability to get excitation `ex` from a determinant `nI`
integer, intent(in) :: nI(nel)
integer, intent(in) :: ex(2, 3)
real(dp) :: pgen
integer :: ms, i, tgt_spin
character(*), parameter :: t_r = "calc_pgen_triple"
! get the spin
ms = 0
! sum up the spin of the single orbitals
do i = 1, 3
ms = ms + G1(ex(2, i))%ms
end do
! start with pTriples
pgen = pTriples
! then, add the spin bias and electron picking probs
if (ms == -3) then
pgen = pgen * p0A * pgen3B
else if (ms == -1) then
pgen = pgen * p2B * pgen2B
else if (ms == 1) then
pgen = pgen * (1 - p2B - p0A - p0B) * pgen1B
else if (ms == 3) then
pgen = pgen * p0B * pgen0B
else
call stop_all(t_r, "Invalid spin")
end if
! Add the probability of picking these three target orbitals
if (tNoSymGenRandExcits) then
call calc_pgen_triple_target_nosym(ms, pgen)
else
call calc_pgen_triple_target_sym(nI, ex, ms, pgen)
end if
end function calc_pgen_triple