subroutine check_septum_clearance(bunch, n_clear,n_hit, n_lost, bunch_clear,ix_septum) use bmad use ramp_parameters implicit none type (bunch_struct)bunch, bunch_clear real(rp) x integer j integer ix_septum, n_clear, n_lost, n_hit n_clear = 0 n_lost = 0 n_hit = 0 do j=1,size(bunch%particle(:)) if(bunch%particle(j)%state == alive$)then if(ix_septum /= 0)bunch%particle(j)%state = lost$ x=bunch%particle(j)%vec(1) if((x - x_septum(ix_septum))*sign(1.0_rp,x_septum(ix_septum)) > 0 .and. (abs(x) - abs(x_wall(ix_septum)))< 0)then !particle clears septum - lost to circulating beam -> ext beam n_clear = n_clear+1 if(ix_septum /= 0)bunch%particle(j)%state = alive$ if(ix_septum == 0)then bunch%particle(j)%state = lost$ bunch_clear%particle(j) = bunch%particle(j) bunch_clear%particle(j)%state = alive$ endif endif if(abs(x) - abs(x_wall(ix_septum)) > 0)then !particle hits outer aperture and is lost to circulating beam n_lost=n_lost + 1 bunch%particle(j)%state = lost$ endif if((x - x_septum(ix_septum))*sign(1.0_rp,x_septum(ix_septum)) < 0 .and. (x_septum(ix_septum)-x)*sign(1.0_rp,x_septum(ix_septum)) < t_septum(ix_septum))then !particle hits septum and is lost n_hit = n_hit + 1 bunch%particle(j)%state = lost$ endif endif end do return end