subroutine event_display_draw_hits c c ********************************************************************** c c draw hits in the already-drawn detector picture of the h8 telescope. c c George Gollin, CPPM (Marseille) and university of Illinois (Urbana-Champaign) c g-gollin@uiuc.edu, 1999 c c ********************************************************************** c c include files holding common blocks and parameter statements go here: c note that they're in the same directory as this file. c #include "event_display.inc" #include "event_display_data.inc" c c ********************************************************************** c c non-common type definitions and array definitions go here: c c first time this routine is called, also some other flags: logical first_time, debug, write_info_to_plot logical noise_flag c character*100 text c c array of points for drawing connected X11 lines note the integer*2 spec: integer*2 icoordview(2,100) c c ********************************************************************** c c data statements go here: c c first time we're entering the routine: data first_time /.true./ c c turn on/off debug outputs: data debug /.false./ c c ********************************************************************** c c c initialize stuff: if(first_time) then first_time=.false. if(debug) print *,' event_display_draw_hits, first time' end if c c c Now I want to figure out how long I can make my representations of pulse c heights before I whack into the next plane when drawing little tick marks. c Look for closest neighbor to a strip (assuming x, y planes are in about c the same z position for each plane). I will assume that only strip plane 1 c is allowed at x=0, and NOT the other strip, or pixel, planes. zminsep=999999. do ipl1=1,4 do ipl2=ipl1+1,max_planes if(xplane_z0(ipl2) .ne. 0.) then if(abs(xplane_z0(ipl1) - xplane_z0(ipl2)) .lt. zminsep) . zminsep=abs(xplane_z0(ipl1) - xplane_z0(ipl2)) end if end do end do c c now set the pixels per count so that the ticks can go most of the way c across: pixels_per_strip_pulseheightx=0.8*zminsep/max_strip_pulseheight . * pixels_per_zx if(pixels_per_strip_pulseheightx .gt. 1.) . pixels_per_strip_pulseheightx=1. pixels_per_strip_pulseheighty=0.8*zminsep/max_strip_pulseheight . * pixels_per_zy if(pixels_per_strip_pulseheighty .gt. 1.) . pixels_per_strip_pulseheighty=1. c c c now do the same thing for dem1... zminsep1=999999. if(xplane_z0(ipldem1) .ne. 0.) then do ipl2=1,max_planes if(abs(xplane_z0(ipldem1) - xplane_z0(ipl2)).lt.zminsep1 . .and. ipl2 .ne. ipldem1) . zminsep1=abs(xplane_z0(ipldem1) - xplane_z0(ipl2)) end do end if c c c ...now do it for dem2. zminsep2=999999. if(xplane_z0(ipldem2) .ne. 0.) then do ipl2=1,max_planes if(abs(xplane_z0(ipldem2) - xplane_z0(ipl2)).lt.zminsep2 . .and. ipl2 .ne. ipldem2) . zminsep2=abs(xplane_z0(ipldem2) - xplane_z0(ipl2)) end do end if c c ...now do it for marebo zminsepm=999999. if(xplane_z0(ipldemm) .ne. 0.) then do ipl2=1,max_planes if(abs(xplane_z0(ipldemm) - xplane_z0(ipl2)).lt.zminsepm . .and. ipl2 .ne. ipldemm) . zminsepm=abs(xplane_z0(ipldemm) - xplane_z0(ipl2)) end do end if c ...now do it for module zminsepm=999999. if(xplane_z0(ipldemd) .ne. 0.) then do ipl2=1,max_planes if(abs(xplane_z0(ipldemd) - xplane_z0(ipl2)).lt.zminsepm . .and. ipl2 .ne. ipldemd) . zminsepm=abs(xplane_z0(ipldemd) - xplane_z0(ipl2)) end do end if c c to keep things neat, use the same scale for both pixel detectors. temp1=0.8*zminsep1/max_dem1_pulseheight temp2=0.8*zminsep2/max_dem2_pulseheight tempm=0.8*zminsepm/max_demm_pulseheight tempd=0.8*zminsepm/max_demd_pulseheight pixels_per_dem1_pulseheightx=min(temp1,temp2,tempm,tempd) * . pixels_per_zx if(pixels_per_dem1_pulseheightx .gt. 1.) . pixels_per_dem1_pulseheightx=1. pixels_per_dem2_pulseheightx=pixels_per_dem1_pulseheightx pixels_per_demm_pulseheightx=pixels_per_dem1_pulseheightx pixels_per_demd_pulseheightx=pixels_per_dem1_pulseheightx c pixels_per_dem1_pulseheighty=min(temp1,temp2,tempm)*pixels_per_zy if(pixels_per_dem1_pulseheighty .gt. 1.) . pixels_per_dem1_pulseheighty=1. pixels_per_dem2_pulseheighty=pixels_per_dem1_pulseheighty pixels_per_demm_pulseheighty=pixels_per_dem1_pulseheighty pixels_per_demd_pulseheighty=pixels_per_dem1_pulseheighty c c c c set the line color to blue: call ixsetlc(index_color_blue) c c Now draw lines to represent hits in the detector planes. Do x view first, c then y view. do iview=1,2 c c c calculate position and width of a clipping rectangle in case we've zoomed in, c where coordinates are in display pixels. if(iview .eq. 1) then c edge_top=top_edge_x edge_bot=bot_edge_x c iclipy_det_orig=pixel_at_x_9 - 1. iclipy_det_width=(pixel_at_x_0 - pixel_at_x_9) + 2. iclipx_det_orig=pixel_at_zx_0 - 1. iclipx_det_width=(pixel_at_zx_9 - pixel_at_zx_0) + 2. c pixels_per_strip_pulseheight=pixels_per_strip_pulseheightx pixels_per_dem1_pulseheight=pixels_per_dem1_pulseheightx pixels_per_dem2_pulseheight=pixels_per_dem2_pulseheightx pixels_per_demm_pulseheight=pixels_per_demm_pulseheightx pixels_per_demd_pulseheight=pixels_per_demd_pulseheightx c else c edge_top=top_edge_y edge_bot=bot_edge_y c iclipy_det_orig=pixel_at_y_9 - 1. iclipy_det_width=(pixel_at_y_0 - pixel_at_y_9) + 2. iclipx_det_orig=pixel_at_zy_0 - 1. iclipx_det_width=(pixel_at_zy_9 - pixel_at_zy_0) + 2. c pixels_per_strip_pulseheight=pixels_per_strip_pulseheighty pixels_per_dem1_pulseheight=pixels_per_dem1_pulseheighty pixels_per_dem2_pulseheight=pixels_per_dem2_pulseheighty pixels_per_demm_pulseheight=pixels_per_demm_pulseheighty pixels_per_demd_pulseheight=pixels_per_demd_pulseheighty c end if c edge_left=left_edge_z edge_right=right_edge_z c iclipy_whole_orig=edge_top iclipy_whole_width=edge_bot - edge_top c iclipx_whole_orig=edge_left iclipx_whole_width=edge_right - edge_left c c c now activate the clipping rectangle: call ixclip(ix11window1_id, iclipx_det_orig, iclipy_det_orig, . iclipx_det_width, iclipy_det_width) c c c loop over detector planes in this view: do ipl=1,max_planes c c load strip or pixel pitch values for detector in units of mm: if(ipl .ne. ipldem1 .and. ipl .ne. ipldem2 .and. . ipl .ne. ipldemm .and. ipl .ne. ipldemd) then pitchx=strip_pitch pitchy=strip_pitch number_to_draw=ifound_strip_hits(iview,ipl) scale=pixels_per_strip_pulseheight max_ph=max_strip_pulseheight c else if(ipl .eq. ipldem1) then pitchx=dem1_pitch_fine pitchy=dem1_pitch_coarse number_to_draw=ifound_dem1_hits scale=pixels_per_dem1_pulseheight max_ph=max_dem1_pulseheight c else if(ipl .eq. ipldem2) then pitchx=dem2_pitch_fine pitchy=dem2_pitch_coarse number_to_draw=ifound_dem2_hits scale=pixels_per_dem2_pulseheight max_ph=max_dem2_pulseheight c else if(ipl .eq. ipldemm) then pitchx=demm_pitch_fine pitchy=demm_pitch_coarse number_to_draw=ifound_demm_hits scale=pixels_per_demm_pulseheight max_ph=max_demm_pulseheight c ..demd else pitchx=demd_pitch_fine pitchy=demd_pitch_coarse number_to_draw=ifound_demd_hits scale=pixels_per_demd_pulseheight max_ph=max_demd_pulseheight end if c c c decide if we have zoomed in far enough so that we can write the detector c info on the plot. Do this by seeing how many pixels apart we would draw c hits in ajacent strips or pixel rows/columns. If the distance is large c enough, we can write text to the plot. First point is in the center of c first strip or pixel. call event_display_rowcol_to_raw(0, 0, ipl, xhit_raw, yhit_raw) zhit_raw=0. c c now transform to the lab frame: length=1 call event_display_apply_align(length, . xhit_raw, yhit_raw, zhit_raw, ipl, iview, . xhit_lab, yhit_lab, zhit_lab) c c now get the display pixel coordinates: if(iview .eq. 1) then call event_display_lab_to_xpixels( . xhit_lab, yhit_lab, zhit_lab, xpixel0, ypixel0) else call event_display_lab_to_ypixels( . xhit_lab, yhit_lab, zhit_lab, xpixel0, ypixel0) end if c c now do the same, but for a hit moved over one pitch spacing: call event_display_rowcol_to_raw(1, 1, ipl, xhit_raw, yhit_raw) zhit_raw=0. c c transform to the lab frame: length=1 call event_display_apply_align(length, . xhit_raw, yhit_raw, zhit_raw, ipl, iview, . xhit_lab, yhit_lab, zhit_lab) c c get the display pixel coordinates: if(iview .eq. 1) then call event_display_lab_to_xpixels( . xhit_lab, yhit_lab, zhit_lab, xpixel1, ypixel1) else call event_display_lab_to_ypixels( . xhit_lab, yhit_lab, zhit_lab, xpixel1, ypixel1) end if c c calculate how far over we've moved. hits are spaced in the screen-y c direction, so we only need to look at the change in the y pixel: deltaypixel=ypixel1 - ypixel0 c c c see how large the text we're writing might be: call ixtxtl(iwidth, iheight, 10, '1234567890') c write_info_to_plot=abs(deltaypixel) .ge. float(iheight) c c c c Now loop over hits, if there are any: if(number_to_draw .le. 0) go to 9188 c do ihit=1,number_to_draw c c c calculate position of hit, in raw detector coordinates: if(ipl .ne. ipldem1 .and. ipl .ne. ipldem2 .and. . ipl .ne. ipldemm .and. ipl .ne. ipldemd) then c c c strip: fill both x and y with this value... ihit_x=istrip_number_read(ihit, iview, ipl) ihit_y=istrip_number_read(ihit, iview, ipl) pulseheight=istrip_adc_read(ihit, iview, ipl) c c load text info to write if desired: if(write_info_to_plot) then c c integer versions, with protection against crashing the format: istr=min(ihit_x,99999) iph=min(abs(pulseheight),99999.) c text='strip:pulse' write(text(1:5), '(i5)') istr write(text(7:11), '(i5)') iph c squeeze out blanks: call cleft(text,1,lenocc(text)) c end if c c else if(ipl .eq. ipldem1) then c dem1: ihit_x=idem1_row_read(ihit) ihit_y=idem1_col_read(ihit) pulseheight=idem1_tot_read(ihit) c c load text info to write if desired: if(write_info_to_plot) then c c integer versions, with protection against crashing the format: irow=min(ihit_x,99999) icol=min(ihit_y,99999) iph=min(abs(pulseheight),99999.) c text='colxx,rowxx:pulse' write(text(1:5), '(i5)') icol write(text(7:11), '(i5)') irow write(text(13:17),'(i5)') iph c c c squeeze out blanks: call cleft(text,1,lenocc(text)) c end if c c else if(ipl .eq. ipldem2) then c dem2: ihit_x=idem2_row_read(ihit) ihit_y=idem2_col_read(ihit) pulseheight=idem2_tot_read(ihit) c c load text info to write if desired: if(write_info_to_plot) then c c integer versions, with protection against crashing the format: irow=min(ihit_x,99999) icol=min(ihit_y,99999) iph=min(abs(pulseheight),99999.) c text='colxx,rowxx:pulse' write(text(1:5), '(i5)') icol write(text(7:11), '(i5)') irow write(text(13:17),'(i5)') iph c c squeeze out blanks: call cleft(text,1,lenocc(text)) c end if c c else if(ipl .eq. ipldemm) then c marebo: ihit_x=idemm_row_read(ihit) ihit_y=idemm_col_read(ihit) pulseheight=idemm_tot_read(ihit) c c load text info to write if desired: if(write_info_to_plot) then c c integer versions, with protection against crashing the format: irow=min(ihit_x,99999) icol=min(ihit_y,99999) iph=min(abs(pulseheight),99999.) c text='colxx,rowxx:pulse' write(text(1:5), '(i5)') icol write(text(7:11), '(i5)') irow write(text(13:17),'(i5)') iph c c squeeze out blanks: call cleft(text,1,lenocc(text)) c end if c c else if(ipl .eq. ipldemd) then c module: ihit_x=idemd_row_read(ihit) ihit_y=idemd_col_read(ihit) pulseheight=idemd_tot_read(ihit) c c also figure out which module chip it is. A subtle point: detector c has 164 rows per chip, read out by 160 channels. The number_rows... c variable tells about detector cells, not readout cells. ichip_x=ihit_x / . (number_rows_per_modchip - number_shared_rows) ichip_y=ihit_y / number_cols_per_modchip c c let's assume that chip 0 has lowest numbered columns and rows, but that c the numbering wraps around: chip chip 15 is "above" chip 0. number_chips_per_mod= . (number_cols_demd / number_cols_per_modchip) * . (number_rows_demd / number_rows_per_modchip) c if(ichip_y .eq. 0) then ichip=ichip_x else ichip=number_chips_per_mod - ichip_x - 1 end if c load text info to write if desired: if(write_info_to_plot) then c c integer versions, with protection against crashing the format: irow=min(ihit_x,99999) icol=min(ihit_y,99999) iph=min(abs(pulseheight),99999.) c text='colxx,rowxx:pulse' write(text(2:3), '(i2)', iostat=io_err) ichip write(text(5:9), '(i5)') icol write(text(11:15), '(i5)') irow write(text(17:21),'(i5)') iph c c squeeze out blanks: call cleft(text,1,lenocc(text)) c end if c c end if c c call event_display_rowcol_to_raw( . ihit_x, ihit_y, ipl, xhit_raw, yhit_raw) zhit_raw=0. c c now shift the x value for channels 160 and up, since detector channels c 160-164 belong to the first chip, and share readout with lower-numbered c channels. if(ihit_x .ge. 160) . xhit_raw=xhit_raw + number_shared_rows*demd_pitch_fine c c now transform these to the lab frame, which has x,y = 0,0 at corners of c strip detectors, but NOT at corners of the smaller pixel detectors: length=1 call event_display_apply_align(length, . xhit_raw, yhit_raw, zhit_raw, ipl, iview, . xhit_lab, yhit_lab, zhit_lab) c c c now get the display pixel coordinates for the x view: if(iview .eq. 1) then call event_display_lab_to_xpixels( . xhit_lab, yhit_lab, zhit_lab, xpixel, ypixel) c else c call event_display_lab_to_ypixels( . xhit_lab, yhit_lab, zhit_lab, xpixel, ypixel) c end if c c c now calculate how far over to place the endpoint of this tick... if it's c a known hot pixel, it'll have a sign-flip on its pulseheight. noise_flag=pulseheight.lt.0. ticklength=abs(pulseheight) * scale tickmax=max_ph * scale if(ticklength .lt. 2.) ticklength=2. if(ticklength .gt. tickmax) ticklength=tickmax c c c now load the array of points: I want to start the tick a pixel to the c right of the detector plane. icoordview(1,1)=xpixel + 1. icoordview(2,1)=ypixel icoordview(1,2)=xpixel + ticklength icoordview(2,2)=ypixel c c c now draw the line to represent this hit: use red if it's a noisy strip. iwilldraw=2 if(noise_flag) call ixsetlc(index_color_red) c call ixline(iwilldraw,icoordview) c c now reset color if necessary: if(noise_flag) call ixsetlc(index_color_blue) c c c now write info about this hit if there's room on the plot: we've already c loaded the text. if(write_info_to_plot) then c c get size (in pixels) of text: call ixtxtl(iw, ih, lenocc(text),text) c c write it to the left of the detector plane... ix=xpixel -3 - iw c c ... and vertically centered with the tick mark (positive is down!) iy=ypixel + ih/2 c c write the text here, after checking that I'm not outside the clip rectangle c in the vertical direction (X11 lets you write text outside a clip rectangle!) if(iy .ge. iclipy_det_orig .and. . iy .le. iclipy_det_orig + iclipy_det_width) . call ixtext(0, ix, iy, 0., 1., lenocc(text), text) c end if c c c here's the end of the loop over hits: end do c c 9188 continue c here's the end of the loop over planes: end do c c now deactivate the clipping rectangle: call ixnocli(ix11window1_id) c c here's the end of the loop over views: end do c c c c now update the window, synchronizing it to the job, but not bothering c to raise it: mode_synchronize=10 call ixupdwi(mode_synchronize) c c c reset the default line color to black: call ixsetlc(index_color_black) c c return end