PRO hrc_view, template, NO_XY_BLUR = no_xy_blur, $ NO_PLOT = no_plot, BIG_SUCKER = big_sucker, SMALL_DUDE=small_dude, $ HRC = hrc, L1 = l1, SAVE_IT = save_it, PROCESS_ALL=process_all, $ IDLSAV=idlsav ; Procedure to read a PSU event file, convert to quasi-level1 product, ; and create a useful plot (color .gif). ; ; ; Input Arguments/KEYWORDS: ; ; template The trw_id to read/plot: 'H-HAS-EA-2.001' ; It can also be wild-carded: 'H-HAS-PI-*' to do a bunch ; of plots, however only the last is returned in HRC and L1. ; /NO_XY_BLUR Normally the event positions are uniformly ; blurred by +/- 0.5 pixel in making the Level 1 DETX, DETY ; (in mm from nominal aim point); this keyword turns ; off the blurring. ; /NO_PLOT Don't make a plot ; /BIG_SUCKER Use this keyword to make one big ; plot of the colored events in X,Y ; (for John Houck's poster) ; /IDLSAV Use the IDL save file of the format TRW_ID_l1.idlsav ; as the input for plotting purposes (no L1 created.) ; Output KEYWORDS: ; ; HRC This is the structure from the ASC HRC L1 FITS file and ; contains tags: ; L1 This is the structure containing the value-added ; ; /SAVE_IT If this KEYWORD is set the L1 structure is saved ; into an IDL save file in save_dir (below) with the ; name: trw_id_l1.idlsav ; /PROCESS_ALL Generally if a wild-card template gives multiple files ; then the list is printed and execution stops. ; To allow multiple file processing PROCESS_ALL loops ; through all files found. (Useful for a one-time ; creation of .gif and .idlsav file set.) ; ; ; Tried to make it standalone except for: ; mrdfits from astrolib (might have to type astrolib to IDL ; prompt to setup stuff.) ; dd_load_ct - (from ~dd/idl/useful/) loads color table for event plots ; ;--------------------------------------------------------------- ; ;--------------------------------------------------------------- ; . ... . . ... ... ; Some "constant" directories: ; HRC data at MIT: HRC_data_dir = '/nfs/spectra/d6/HRC_data/' ; what directory to put the resulting .gif plot... gif_dir = '/nfs/spectra/d6/HRC_data/' ; and IDL save file save_dir = '/nfs/spectra/d6/HRC_data/' ; . ... . . ... ... ; Some numerical constants, etc. ; u,v pixel size in mm i_pix_size = 0.006429 ; mm ; For S array, use the v (dispersion) pixel size... sv_pix_size = 0.006429 ; mm ; nominal aim points for I and S arrays in X,Y coordinates: ; HRC-I i_aim_x = 16600. ; from 'EA-6.001 i_aim_y = 16100. ; these agree better with data ; HRC-S s_aim_x = 2.*16384. s_aim_y = 4096. ; . ... . . ... ... ; Get the file name(s) ; If more than one file matches, list them and return... ; (unless /PROCESS_ALL!) ; get the filename - same as the TRW-ID ; get around the file structure with a FINDFILE with wild cards (*): all_found = findfile(hrc_data_dir+template, COUNT=nfound) if nfound EQ 0 then begin print, 'hrc_view: non-existant TRW-ID' RETURN end if nfound GT 1 AND NOT(KEYWORD_SET(PROCESS_ALL)) then begin print, 'hrc_view: found '+STRING(nfound,FORMAT='(I4)')+' files:' for ifile = 0, n_elements(all_found)-1 do begin file_name = all_found(ifile) ; get the TRW ID from the filename... pieces = STR_SEP(file_name, '/') trw_id = pieces(n_elements(pieces)-1) print, ifile,': ',trw_id end print, 'hrc_view: please select one of the above' RETURN end print, '' ; Process the file(s) for ifile=0, n_elements(all_found)-1 do begin file_name = all_found(ifile) if NOT(KEYWORD_SET(IDLSAV)) then begin ; . ... . . ... ... ; get the TRW ID from the filename... pieces = STR_SEP(file_name, '/') trw_id = pieces(n_elements(pieces)-1) hrcpos = strpos(trw_id,'hrc_') evtpos = strpos(trw_id,'_evt') trw_id = strmid(trw_id,hrcpos+4,evtpos-(hrcpos+4)) print, trw_id ; Use TRW ID to determine I or S array: s_array = 0 if STRPOS(trw_id,'hs') EQ 2 then s_array = 1 if s_array then print, 'HRC-S' else print, 'HRC-I' if s_array then begin aim_x = s_aim_x aim_y = s_aim_y pix_size = sv_pix_size end else begin aim_x = i_aim_x aim_y = i_aim_y pix_size = i_pix_size end ; read the event file in hrc = mrdfits(file_name, 2) print, tag_names(hrc) ; Now for some processing... ; ---------------------------------------------- ;# Define the "energy" array ; Map the PHA values (0-255) to 0. to 10. hrc_e = 10.0*FLOAT(hrc.pha)/255.0 ;# Coordinate scaling to mm w.r.t. aim point ; Create floating values: hrc_x = FLOAT(hrc.DETX) ; was X hrc_y = FLOAT(hrc.DETY) ; was Y ; Randomize for better event X,Y plots (also simulates dither and aspect ; correction effects...) ; e.g., blur them by a "pixel" if NOT(KEYWORD_SET(NO_XY_BLUR)) then begin hrc_x = hrc_x + RANDOMU(SEED,n_elements(hrc_x)) - 0.5 hrc_y = hrc_y + RANDOMU(SEED,n_elements(hrc_y)) - 0.5 end ; Keep hrc_X and hrc_Y around for the plotting (below) ; Create the DETX and DETY in mm from nominal aim point: hrc_detx = pix_size * (hrc_x - aim_x) hrc_dety = pix_size * (hrc_y - aim_y) ; # Flag "bad" events ; if there is a STATUS tag then use it... if TOTAL(STRPOS(tag_names(hrc),'STATUS') GE 0) GT 0 then begin hrc_status = hrc.status end else begin ; some don't have it... hrc_status = LONG(INTARR(n_elements(hrc))) end ; Time is time: hrc_time = hrc.time ; - - - - - - - - - - - - - - - - - ; end of "Level 1" processing ; Create the L1 structure to return ; L1 has the tags: DETX, DETY, ENERGY one_event = {detx:0.0, dety:0.0, energy:0.0, status:0L, time:DOUBLE(0)} L1 = REPLICATE(one_event, n_elements(hrc)) ; Fill it L1.detx = hrc_detx L1.dety = hrc_dety L1.energy = hrc_e L1.status = hrc_status L1.time = hrc_time If KEYWORD_SET(save_it) then begin SAVE, L1, FILENAME=save_dir+trw_id+'_l1.idlsav' end ; All done with L1 end else begin ; end of NOT IDLSAV ; . ... . . ... ... ; If IDLSAV files then: ; get the TRW ID from the filename... pieces = STR_SEP(file_name, '/') trw_id = pieces(n_elements(pieces)-1) trw_id = STRMID(trw_id, 0, STRPOS(trw_id,'_l1.idlsav')) print, trw_id ; Use TRW ID to determine I or S array: s_array = 0 if STRPOS(trw_id,'S') EQ 4 then s_array = 1 if s_array then print, 'HRC-S' else print, 'HRC-I' if s_array then begin aim_x = s_aim_x aim_y = s_aim_y pix_size = sv_pix_size end else begin aim_x = i_aim_x aim_y = i_aim_y pix_size = i_pix_size end ; read the event file in restore, file_name print, tag_names(l1) hrc_x = aim_x + L1.detx/pix_size hrc_y = aim_y + L1.dety/pix_size hrc_e = L1.energy hrc_status = L1.status hrc_time = L1.time end ; of IDLSAV ; . ... . . ... ... ;- - - - - - - - - - - - - - - - - - - - - - - - - ; Make pretty pictures... if NOT(KEYWORD_SET(NO_PLOT)) then begin ; Calc a floating time since beginning of data set ; in seconds ftime = hrc_time ftime = ftime - MIN(ftime) ; time order the events and arrays ; (in case they are not, e.g. came from qpoe somewhere) time_order = SORT(ftime) ftime = ftime(time_order) hrc_x = hrc_x(time_order) hrc_y = hrc_y(time_order) hrc_e = hrc_e(time_order) hrc_status = hrc_status(time_order) hrc_time = hrc_time(time_order) ; PLOTTING section ; Select "valid" events: ok_es = where( (hrc_status AND '3FFF00'xL) EQ 0 , nok ) n_total = n_elements(hrc_status) if nok GE 1 then begin ftime = ftime(ok_es) hrc_x = hrc_x(ok_es) hrc_y = hrc_y(ok_es) hrc_e = hrc_e(ok_es) hrc_status = hrc_status(ok_es) print, '' print, ' Total events accepted ( "3FFF00" criteria ) : ' + $ STRING(n_elements(ok_es)) + $ ' ['+STRING(100.0*FLOAT(n_elements(ok_es))/$ FLOAT(n_total),FORMAT='(F6.1)')+' % ]' end ; Now the plots... ; limit the number of events plotted (except for time plot) n_bunch = 20000 ; take the n_bunch events from the middle of the series nevents = n_elements(hrc_x) if nevents GT n_bunch then begin ; use middle n_bunch pes = indgen(n_bunch) + (nevents - n_bunch)/2 -1 end else begin ; use em all pes = indgen( nevents ) end min_pes = min(pes) max_pes = max(pes) print, '' ; Plot to .gif set_plot, 'X' if s_array then begin if KEYWORD_SET(BIG_SUCKER) OR KEYWORD_SET(SMALL_DUDE) then begin if KEYWORD_SET(BIG_SUCKER) then begin window, 2, xsi=1000, ysi=300 !p.multi = 0 char_size = 1.6 end else begin window, 2, xsi=300, ysi=90 !p.multi = 0 char_size = 0.1 end end else begin window, 2, xsi=550, ysi=700 !p.multi = [0,1,4] char_size = 1.6 end end else begin ; I-array if KEYWORD_SET(BIG_SUCKER) OR KEYWORD_SET(SMALL_DUDE) then begin if KEYWORD_SET(BIG_SUCKER) then begin window, 2, xsi=800, ysi=750 !p.multi = 0 char_size = 1.6 end else begin window, 2, xsi=300, ysi=90 !p.multi = 0 char_size = 0.1 end end else begin window, 2, xsi=450, ysi=850 !p.multi = [0,1,2] char_size = 1.6 end end ; Color table for PHA-->color coding dd_load_ct ; Colors for the events based on energy hrc_colors = 3+FIX(252.*((hrc_E - 0.5)/(10.0-0.5))) ; Plot the events in physical space with a cross-hair ; at the nominal aim point location if s_array then begin plot, hrc_x(pes), hrc_y(pes), PSYM=3, BACK=2, COLOR=1, $ XRANGE=[8000.,56000.], XSTY=1, $ YRANGE = [2500.,6000.], YSTY=1, /NODATA, CHARSIZE = char_size, $ XTITLE = 'DETX (pixels)', YTITLE='DETY (pixels)', $ TITLE = trw_id plots, hrc_x(pes), hrc_y(pes), COLOR=hrc_colors(pes), PSYM=3 print, ' nominal aim point (X,Y) = '+$ STRING(s_aim_x)+STRING(s_aim_y) oplot, s_aim_x+[0.,0.], s_aim_y+[-100.,100.], COLOR=1 oplot, s_aim_x+[-100.,100.], s_aim_y+[0.,0.], COLOR=1 end else begin plot, hrc_x(pes), hrc_y(pes), PSYM=3, BACK=2, COLOR=1, $ XRANGE=aim_x+[-10000.,10000.], XSTYLE=1, $ YRANGE = aim_Y+[-3000.,3000.], YSTYLE=1, /NODATA, CHARSIZE = char_size, $ XTITLE = 'DETX (pixels)', YTITLE='DETY (pixels)', $ TITLE = trw_id plots, hrc_x(pes), hrc_y(pes), COLOR=hrc_colors(pes), PSYM=3 print, ' nominal aim point (X,Y) = '+$ STRING(i_aim_x)+STRING(i_aim_y) oplot, i_aim_x+[0.,0.], i_aim_y+[-100.,100.], COLOR=1 oplot, i_aim_x+[-100.,100.], i_aim_y+[0.,0.], COLOR=1 end if NOT(KEYWORD_SET(BIG_SUCKER) OR KEYWORD_SET(SMALL_DUDE)) then begin ; I-array has last 3 plots smaller if NOT(s_array) then !p.multi = [3,1,6] ; HRC PHA histogram of all events ; pha_bin_size = 0.01 ; pha_hist = histogram(hrc_e, MIN=0., MAX=10.0, BINSIZE=pha_bin_size) ; pha_es = pha_bin_size*indgen(n_elements(pha_hist)) ; keV ; 1/26/98 dd replaced the above const E bins with const log bins: ; log_hist is in ~dd/idl/useful. pha_bin_EdE = 100.0 log_hist, hrc_e, 1.+1./pha_bin_EdE, pha_es, pha_hist plot_oo, pha_es, pha_hist, PSYM=10, BACK=2, COLOR=1, $ XRANGE=[0.5, 10.], XSTYLE=1, YRANGE=[1.,(MAX(pha_hist) > 1.E4)], $ TITLE = 'HRC PHA: .../'+trw_id, CHARSIZE = char_size, $ XTITLE = 'Pulse height (10*PHA/255)', YTITLE='counts (bin = E/'+$ STRCOMPRESS(STRING(pha_bin_EdE,FORMAT='(F8.1)'),/REMOVE_ALL)+')' pha_colors = 3+FIX(252.*((pha_es - 0.5)/(10.0-0.5))) plots, pha_es, pha_hist, PSYM=1, COLOR=pha_colors ; Plot the Energy vs X if s_array then begin plot_io, hrc_x(pes), hrc_e(pes), PSYM=3, BACK=2, COLOR=1, $ XRANGE=[8000.,56000.], XSTY=1, $ YRANGE = [0.5, 10.], /NODATA, CHARSIZE = char_size, $ XTITLE = 'DETX (pixels)', $ YTITLE='Pulse height (10*PHA/255)', YSTYLE=1 plots, hrc_x(pes), hrc_e(pes), COLOR=hrc_colors(pes), PSYM=3 end else begin plot_io, hrc_x(pes), hrc_e(pes), PSYM=3, BACK=2, COLOR=1, $ XRANGE=aim_x+[-7500.,7500.], XSTYLE=1, $ YRANGE = [0.5, 10.], /NODATA, CHARSIZE = char_size, $ XTITLE = 'DETX (pixels)', $ YTITLE='Pulse height (10*PHA/255)', YSTYLE=1 plots, hrc_x(pes), hrc_e(pes), COLOR=hrc_colors(pes), PSYM=3 end ; Plot the events vs time of arrival - see dropped frames etc! y_rang = aim_x+[-7500.,7500.] if s_array then y_rang = [8000.,56000.] plot, ftime, hrc_x, PSYM=3, BACK=2, COLOR=1, /NODATA, $ YRANGE=y_rang, YSTYLE=1, CHARSIZE = char_size, $ XTITLE = 'Time (TIME - MIN(TIME))', YTITLE='DETX (pixels)' plots, ftime, hrc_x, PSYM=3, COLOR=hrc_colors oplot, ftime(min_pes)*[1.,1.], y_rang, COLOR=1 oplot, ftime(max_pes)*[1.,1.], y_rang, COLOR=1 end ; Finish the .gif output wshow,2,iconic=0 image = tvrd() tvlct, red, green, blue, /GET if KEYWORD_SET(BIG_SUCKER) OR KEYWORD_SET(SMALL_DUDE)then begin if KEYWORD_SET(BIG_SUCKER) then begin write_gif, gif_dir+trw_id+'_big.gif', image, red, green, blue end else begin write_gif, gif_dir+trw_id+'_small.gif', image, red, green, blue end end else begin write_gif, gif_dir+trw_id+'_anal.gif', image, red, green, blue end !p.multi = 0 end ; of NO_PLOT ;- - - - - - - - - - - - - - - - - - - - - - - - - end ; of ifile loop over files RETURN END