-- $Id: xss_01.lua,v 1.6 2008/07/24 20:42:25 dj Exp $ $debug -- XSS source simulator -- override must provide the following information: -- -- xss : the name of the XSS source. It may be one of -- DCM, HIREFS, EIPS, or PIGS. -- -- pitch, yaw: the source position in minutes of arc -- -- for EIPS the following must be specified: -- -- energy: the energy in keV -- spot: The EIPS spot FITS file, relative to EIPS_ROOT -- as defined below -- -- for PIGS the following must be specified: -- -- energy: the energy in keV -- -- for DCM, the following must be specified -- -- crystal: either 'TAP', 'Ge', or 'Al' -- energy: the energy in keV AXAF_ROOT = getenv( 'AXAF_ROOT' ) XSS_ROOT = AXAF_ROOT .. '/simul/databases/xss/' EIPS_ROOT = XSS_ROOT .. 'eips-19980828/' PIGS_IMAGE = XSS_ROOT .. 'pigs_spot_01.fits' dofile( AXAF_ROOT .. '/simul/databases/xss/xss_distance_01.lua' ) dofile( AXAF_ROOT .. '/simul/lib/lua/AXAFCoords.lua' ) -- dofile( AXAF_ROOT .. '/simul/lib/lua/store.lua' ) $ifnot XSS_TEST override( ) $end ------------------------------------------------------------------ ------------------------------------------------------------------ -- these two functions (table_copy and table_union) are used to -- generate the union of two tables. they are used later on -- to set up a new tagmethod for the "add" events for -- tables. this is just so that the code is cleaner later on, -- lua doesn't know how to "add" tables function table_copy( dest, src ) local i, v = next(src, nil) -- i is an index of t, v = t[i] while i do dest[i] = v i, v = next(src, i) -- get next index end return new end function table_union( op1, op2 ) new = {} table_copy( new, op1 ) table_copy( new, op2 ) return new end ------------------------------------------------------------------ ------------------------------------------------------------------ -- this is a helper function that will generate an error if the -- passed global variables aren't defined function checkglobal( pfx, ... ) local i = 1 while i <= arg.n do if nil == getglobal(arg[i]) then error( pfx .. "`" .. arg[i] .. "' isn't defined" ) end i = i + 1 end end ------------------------------------------------------------------ ------------------------------------------------------------------ -- this splits up a string on commas, and returns a table with -- each of the substrings as indices, with their order in the -- original string as the values function optsplit( string ) local fin local start = 1 local toks = {} toks.n = 0 fin = strfind( string, ',', start ) while ( fin ) do toks.n = toks.n + 1 toks[strsub( string, start, fin - 1 )] = toks.n start = fin + 1 fin = strfind( string, ',', start ) end toks.n = toks.n + 1 toks[strsub( string, start )] = toks.n return toks end ------------------------------------------------------------------ ------------------------------------------------------------------ function source( ) local deg2rad = 3.14159265358979/180.0 local arcsec2rad = deg2rad / 3600 local arcmin2rad = deg2rad / 60 local oldadd = settagmethod( tag( {} ), "add", table_union ) local pfx = 'xss: ' checkglobal( pfx, 'xss', 'energy', 'pitch', 'yaw' ) local theta, phi local el, az el, az = pitchyaw_2_osac_elaz( pitch, yaw ) theta, phi = osac_elaz_2_osac_polar( el, az ) theta, phi = osac_polar_2_raygen_polar( theta, phi ) -- split off possible options local src = optsplit( xss ) local src_pos = { theta = theta, phi = phi, z = z } ---------------------------------------------------------------- if ( src['EIPS'] ) then if ( nil == src_pos['z'] ) then src_pos['z'] = - xss_distance( 'EIPS' ) end begin_source( 'EIPS' ) mono( "EIPS-mono", energy, 1 ) if ( src['point'] ) then point( "EIPS-point", src_pos ) else if ( nil == spot ) then error( pfx .. "Must specify `spot' for EIPS source" ) end local eips_image = EIPS_ROOT .. spot image( "EIPS-image", { file = eips_image } + src_pos ) end end_source( 'EIPS' ) ---------------------------------------------------------------- elseif ( src['HIREFS'] ) then -- don't have an image for this yet, so just do monochromatic point -- source if ( nil == src_pos['z'] ) then src_pos['z'] = - xss_distance( 'HIREFS' ) end begin_source( 'HIREFS' ) mono( "HIREFS-mono", energy, 1 ) point( "HIREFS-point", src_pos ) end_source( 'HIREFS' ) elseif ( src['DCM'] ) then checkglobal( pfx, 'crystal' ) if ( nil == src_pos['z'] ) then src_pos['z'] = - xss_distance( 'DCM', crystal, 'energy', energy ) end -- don't have an image for this yet, so just do monochromatic point -- source begin_source( 'DCM' ) mono( "DCM-mono", energy, 1 ) point( "DCM-point", src_pos ) end_source( 'DCM' ) ---------------------------------------------------------------- elseif ( src['PIGS'] ) then if ( nil == src_pos['z'] ) then src_pos['z'] = - xss_distance( 'PIGS' ) end begin_source( 'PIGS' ) mono( "PIGS-mono", energy, 1 ) if ( src['point'] ) then point( "PIGS-point", src_pos ) else image( "PIGS-image", {file = PIGS_IMAGE} + src_pos) end end_source( 'PIGS' ) ---------------------------------------------------------------- else error( pfx .. "couldn't parse source string: " .. xss ) end end $if XSS_TEST source( ) $end