PRO hist_from_events, evt_file, hist_file, $ XCENTER=xcenter, YCENTER=ycenter, $ AXIS_ANGLE=axis_angle, $ PHA_RANGE=pha_range, $ REG_SIZE=reg_size, BIN_SIZE=bin_size, $ PLOT_EVENTS=plot_events, $ CHAR_SCALE=char_scale ; Read in an event file (of various formats...) ; and output 1D histogram in rdb format. ; Default title for histogram hist_title = evt_file ; Defaults for xcenter, ycenter if n_elements(XCENTER) EQ 0 then XCENTER = 0. ; mm if n_elements(YCENTER) EQ 0 then YCENTER = 0. ; mm center_fmt = '(F8.3)' ; Default AXIS_ANGLE if n_elements(axis_angle) LE 0 then axis_angle = 0.0 ; Default for PHA_RANGE ; default is no range! ; Default for reg_size if n_elements(reg_size) EQ 0 then reg_size = 0.22 ; mm ; Default for bin_size if n_elements(bin_size) EQ 0 then bin_size = 0.010 ; mm ; Default for char_scale if n_elements(char_scale) EQ 0 then char_scale = 1.0 ; dd's MARX idl save files ; ------------------------ ; Is it from xrcf_sim of flight_sim ? if STRPOS(evt_file, 'ml1.idlsav') GE 0 then begin restore, evt_file fac_y = ml1.detx - xcenter fac_z = ml1.dety - ycenter energies = ml1.energy ; change hist_title, remove upper dir info and ; add center, angle after file name wheremarx = STRPOS(evt_file, 'MARX') whereml1 = STRPOS(evt_file, 'ml1.idl') hist_title = STRMID(evt_file, wheremarx, whereml1-wheremarx) + $ ', '+STRING(axis_angle,FORMAT='(F9.3)')+' deg., ('+ $ STRCOMPRESS( STRING(xcenter,FORMAT=center_fmt)+','+ $ STRING(ycenter,FORMAT=center_fmt)+' )' ) end ; XRCF HSI fits files ; ------------------- ; Is it real HSI data? if STRPOS(evt_file, 'hsi') GE 0 AND $ STRPOS(evt_file,'.fits') GE 0 then begin hsi = xrcf_hsi_read(evt_file,/FAC,/PBLUR) fac_y = hsi.y/1000.0 - xcenter ; mm fac_z = hsi.z/1000.0 - ycenter ; mm energies = hsi.pha ; change hist_title (remove upper dir info and ; add angle after file name wherehsi = STRPOS(evt_file, 'hsi') hist_title = STRMID(evt_file, wherehsi, 80) + $ ', '+STRING(axis_angle,FORMAT='(F9.3)')+' deg., ('+ $ STRCOMPRESS( STRING(xcenter,FORMAT=center_fmt)+','+ $ STRING(ycenter,FORMAT=center_fmt)+' )' ) end ; XRCF ACIS & HRC in dd's "Level 1" idl save files ; ------------------------------------------------ ; Is it dd processed ACIS or HRC Level 1 data ? if STRPOS(evt_file, 'ml1.idlsav') LT 0 AND $ STRPOS(evt_file, 'l1.idlsav') GE 0 then begin restore, evt_file fac_y = l1.detx - xcenter fac_z = l1.dety - ycenter energies = l1.energy ; change hist_title (remove upper dir info and ; add angle after file name whereACIS = STRPOS(evt_file, 'ACIS_anal') whereHRC = STRPOS(evt_file, 'HRC_data') wheremarx = MAX([whereACIS, whereHRC, 0]) whereml1 = STRPOS(evt_file, '.idlsav') hist_title = STRMID(evt_file, wheremarx, whereml1-wheremarx) + $ ', '+STRING(axis_angle,FORMAT='(F9.3)')+' deg., ('+ $ STRCOMPRESS( STRING(xcenter,FORMAT=center_fmt)+','+ $ STRING(ycenter,FORMAT=center_fmt)+' )' ) end ; Rotate them by ROT_ANGLE = -1.0*AXIS_ANGLE ; For axis_angle = 0, binning is done along Y_facility if n_elements(axis_angle) EQ 0 then axis_angle=0.0 rot_angle = -1.0*axis_angle rot_y = fac_y * COS(!DTOR*rot_angle) - fac_z * SIN(!DTOR*rot_angle) rot_z = fac_y * SIN(!DTOR*rot_angle) + fac_z * COS(!DTOR*rot_angle) ; select the events ; based on region and possibly energy if n_elements(PHA_RANGE) LT 2 then begin sel = where( (ABS(rot_y) LE reg_size) AND $ (ABS(rot_z) LE reg_size) ) end else begin sel = where( (ABS(rot_y) LE reg_size) AND $ (ABS(rot_z) LE reg_size) AND $ (energies GE pha_range(0)) AND $ (energies LE pha_range(1)) ) end rot_y = rot_y(sel) rot_z = rot_z(sel) if KEYWORD_SET(PLOT_EVENTS) then begin ; if plot_events is set to an integer, use that ; as the number of data points to show if plot_events GT 10 then begin nmax = n_elements(rot_y)-1 plot, rot_y(0:(plot_events < nmax)), $ rot_z(0:(plot_events < nmax) ), PSYM=3, $ XRANGE=[-reg_size, reg_size], XSTYLE=1, $ YRANGE=[-reg_size, reg_size], YSTYLE=1, $ TITLE = hist_title, CHARSIZE = char_scale print, ' ' print, ' plotted events: ', (plot_events < nmax)+1 end else begin plot, rot_y, rot_z, PSYM=3, $ XRANGE=[-reg_size, reg_size], XSTYLE=1, $ YRANGE=[-reg_size, reg_size], YSTYLE=1, $ TITLE = hist_title, CHARSIZE = char_scale end end ; make the histogram along fac_y lin_hist, rot_y, bin_size, hist_axis, hist_counts ; write the histogram ; START - - - - - - hist_write_template.pro - - - - - ; Include and modify the following code to output data ; to an rdb histogram file ; ; column names hist_struct = {bin: 0.0, count:0.0, err:0.0} hist = REPLICATE(hist_struct, n_elements(hist_counts)) ; ; fill the strucuture from desired arrays... hist.bin = hist_axis ; mm hist.count = hist_counts hist.err = SQRT(hist_counts) ; ; create header information ; each line is an element in the string array ; each line should start with a "#" ; optional parameters have the format: ; "# param_name[:][TAB]value_string" ; ; customize for application... your_header=['# created by hist_from_events.pro, '+SYSTIME(),$ '# ', $ '# input_file: '+evt_file, $ '# xcenter: '+STRING(xcenter,FORMAT='(F9.3)') , $ '# ycenter: '+STRING(ycenter,FORMAT='(F9.3)') , $ '# axis_angle: '+STRING(axis_angle,FORMAT='(F9.3)') ] ; ; parameters that hist routines might use: hist_header=['# for histogram routines use:', $ '# title: '+hist_title, $ '# bin_axis: Position', $ '# bin_unit: mm' ] header = [your_header, hist_header] ; ; and write it out to desired file if n_elements(hist_file) EQ 0 then hist_file = 'temp_hist.rdb' rdb_write, hist_file, hist, HEAD = header ; END - - - - - - hist_write_template.pro - - - - - RETURN END