subroutine Add_RDM_HFConnections_HPHF(spawn, one_rdms, iLutJ, nJ, AvSignJ, AvSignHF, walkExcitLevel, IterRDM)
! This is called when we run over all TotWalkers in CurrentDets.
! It is called for each CurrentDet which is a single or double of the HF.
! It adds in the HF - S/D connection. The diagonal elements will already
! have been taken care of by the extract routine.
use FciMCData, only: HFDet_True, iLutHF_True
use rdm_data, only: one_rdm_t
type(rdm_spawn_t), intent(inout) :: spawn
type(one_rdm_t), intent(inout) :: one_rdms(:)
integer(n_int), intent(in) :: iLutJ(0:NIfTot)
integer, intent(in) :: nJ(nel)
real(dp), intent(in) :: AvSignJ(:), AvSignHF(:)
integer, intent(in) :: walkExcitLevel
integer, intent(in) :: IterRDM(:)
#ifdef DEBUG_
character(*), parameter :: this_routine = "Add_RDM_HFConnections_HPHF"
#endif
! Now if the determinant is connected to the HF (i.e. single or double),
! add in the diagonal elements of this connection as well -
! symmetrically because no probabilities are involved.
if ((walkExcitLevel == 1) .or. (walkExcitLevel == 2)) then
call Fill_Spin_Coupled_RDM(spawn, one_rdms, iLutHF_True, iLutJ, HFDet_True, nJ, AvSignHF(2::2), IterRDM*AvSignJ(1::2))
call Fill_Spin_Coupled_RDM(spawn, one_rdms, iLutJ, iLutHF_True, nJ, HFDet_True, AvSignJ(2::2), IterRDM*AvSignHF(1::2))
end if
end subroutine Add_RDM_HFConnections_HPHF