Routine to check if a particle will hit a NPA detector
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in), | dimension(3) | :: | r0 | Starting point of particle |
|
real(kind=Float64), | intent(in), | dimension(3) | :: | v0 | Particle velocity |
|
integer, | intent(out) | :: | d_index | Index of NPA detector. Zero if particle doesn't hit |
||
real(kind=Float64), | intent(out), | optional | dimension(3) | :: | rd | Point where particle hit detector |
integer, | intent(in), | optional | :: | det | Index of NPA detector to check |
subroutine hit_npa_detector(r0, v0, d_index, rd, det)
!+ Routine to check if a particle will hit a NPA detector
real(Float64), dimension(3), intent(in) :: r0
!+ Starting point of particle
real(Float64), dimension(3), intent(in) :: v0
!+ Particle velocity
integer, intent(out) :: d_index
!+ Index of NPA detector. Zero if particle doesn't hit
real(Float64), dimension(3), intent(out), optional :: rd
!+ Point where particle hit detector
integer, intent(in), optional :: det
!+ Index of NPA detector to check
real(Float64), dimension(3) :: d, a
real(Float64) :: t_a,t_d
integer :: i, s, ndet
if(present(det)) then
s = det
ndet = det
else
s = 1
ndet = npa_chords%nchan
endif
d_index = 0
detector_loop: do i=s,ndet
!! Find where trajectory crosses detector plane
call line_plane_intersect(r0,v0,npa_chords%det(i)%detector%origin, &
npa_chords%det(i)%detector%basis(:,3),d,t_d)
!! Find where trajectory crosses aperture plane
call line_plane_intersect(r0,v0,npa_chords%det(i)%aperture%origin, &
npa_chords%det(i)%aperture%basis(:,3),a,t_a)
!! If both points are in plane boundaries and the
!! particle is heading toward the detector then its a hit
if(in_boundary(npa_chords%det(i)%aperture,a) .and. &
in_boundary(npa_chords%det(i)%detector,d) .and. &
(t_d.gt.0.0) ) then
d_index = i
exit detector_loop
endif
enddo detector_loop
if(present(rd)) rd = d
end subroutine hit_npa_detector