record_hit_2D_sub Subroutine

private subroutine record_hit_2D_sub(this, hitpoint, history)

check if a hit is on the detector and record it if so

Type Bound

detector2D

Arguments

Type IntentOptional Attributes Name
class(detector2D), intent(inout) :: this
type(hit_t), intent(in) :: hitpoint

Interaction information

type(history_stack_t), intent(inout) :: history

Photon packet history


Source Code

    subroutine record_hit_2D_sub(this, hitpoint, history)
        !! check if a hit is on the detector and record it if so

        use historyStack, only : history_stack_t
        use sim_state_mod, only : state

        class(detector2D),     intent(inout) :: this
        !> Interaction information
        type(hit_t),           intent(in)    :: hitpoint
        !> Photon packet history
        type(history_stack_t), intent(inout) :: history

        real(kind=wp), volatile :: x, y
        integer       :: idx, idy

        if(this%check_hit(hitpoint))then
            x = hitpoint%pos%z + this%pos%x
            y = hitpoint%pos%y + this%pos%y
            idx = min(int(x / this%bin_wid_x) + 1, this%nbinsX)
            idy = min(int(y / this%bin_wid_y) + 1, this%nbinsY)
            if(idx < 1)idx = this%nbinsX
            if(idy < 1)idy = this%nbinsY
            !$omp atomic
            this%data(idx, idy) = this%data(idx, idy) + 1
            if(this%trackHistory)then
                call history%write()
            end if
        end if
        if(state%trackHistory)call history%zero()
        end subroutine record_hit_2D_sub