#! /star/local/bin/tcsh # # AMR 06/06/02 set version=1.5 nice +19 cat < tempfm01 set hidetx = `grep "Legal maximum for DETX" < tempfd01 | head -1 | awk '{print $1}'` echo $hidetx' 20400 / Maximum for DETX (altered)' >> tempfm01 set lodety = `grep "Legal minimum for DETY" < tempfd01 | head -1 | awk '{print $1}'` echo $lodety' -20400 / Minimum for DETY (altered)' >> tempfm01 set hidety = `grep "Legal maximum for DETY" < tempfd01 | head -1 | awk '{print $1}'` echo $hidety' 20400 / Maximum for DETY (altered)' >> tempfm01 fmodhead tempEv01 tempfm01 rm -f tempfm01 evselect -w 0 -V 0 table=tempEv01 spectrumset=tempsp01 expression="ANNULUS(0,0,$r0,$r1,DETX,DETY)" $parspec evselect -w 0 -V 0 table=tempEv01 imageset=tempim01 expression="ANNULUS(0,0,$r0,$r1,DETX,DETY)" $parimage rm -f tempEv01 # CREATE BG SPEC echo 'Creating BG spectrum (Pattern expression - '$patexp' )...' evselect -w 0 -V 0 table=$bg filteredset=tempEv02 expression="$patexp" updateexposure=N writedss=Y withfilteredset=Y destruct=Y keepfilteroutput=T evselect -w 0 -V 0 table=tempEv02 spectrumset=tempsp02 expression="ANNULUS(0,0,$r0,$r1,DETX,DETY)" $parspec rm -f tempEv02 # IF, MAKE PRE-SRC IMAGE set srcpixno=0 if ($ev2 != 0) then echo 'Creating image from pre-source-subtracted Ev file ...' cp $ev2 tempEv03 # alter legal DET values fdump tempEv03 tempfd03 1 1-1 clobber=yes if (-e tempfm01) rm -f tempfm01 set lodetx = `grep "Legal minimum for DETX" < tempfd03 | head -1 | awk '{print $1}'` echo $lodetx' -20400 / Minimum for DETX (altered)' > tempfm01 set hidetx = `grep "Legal maximum for DETX" < tempfd03 | head -1 | awk '{print $1}'` echo $hidetx' 20400 / Maximum for DETX (altered)' >> tempfm01 set lodety = `grep "Legal minimum for DETY" < tempfd03 | head -1 | awk '{print $1}'` echo $lodety' -20400 / Minimum for DETY (altered)' >> tempfm01 set hidety = `grep "Legal maximum for DETY" < tempfd03 | head -1 | awk '{print $1}'` echo $hidety' 20400 / Maximum for DETY (altered)' >> tempfm01 fmodhead tempEv03 tempfm01 rm -f tempfm01 evselect -w 0 -V 0 table=tempEv03 imageset=tempim02 expression="ANNULUS(0,0,$r0,$r1,DETX,DETY)" $parimage rm -f tempEv03 echo 'Estimating pixels lost due to source removal...' farith tempim02 tempim01 tempim03 SUB clobber=yes fcarith tempim03 1.0E-20 tempim04 ADD clobber=yes farith tempim03 tempim04 tempim05 DIV clobber=yes set srcpixno = `fimgstat tempim05 0 1 | grep sum | awk '{print $8}'` set srcpixno = `echo $srcpixno 1600 | awk '{print $1*$2}'` endif echo 'Scaling and subtracting background...' cp tempsp01 sp_s_$root'.fits' cp tempsp02 sp_b_$root'.fits' punlearn fcalc punlearn fdelcol fcalc tempsp02 tempsp03 COUNTS2 "$bgscale * COUNTS" clobber=yes fcalc tempsp03 tempsp06 COUNTS "COUNTS2" clobber=yes fdelcol tempsp06+1 COUNTS2 N Y fdelcol tempsp03+1 COUNTS N Y faddcol tempsp03 tempsp01 COUNTS fcalc tempsp03 tempsp04 COUNTS1 "COUNTS" clobber=yes fdelcol tempsp04+1 COUNTS N Y fcalc tempsp04 tempsp05 COUNTS "COUNTS1 - COUNTS2" clobber=yes fdelcol tempsp05+1 COUNTS1 N Y fdelcol tempsp05+1 COUNTS2 N Y cp tempsp05 sp_bs_$root'.fits' cp tempsp06 sp_scb_$root'.fits' #dsplot -w 0 -V 0 table=sp_bs_$root'.fits' x='CHANNEL' y='COUNTS' if ($rmfgen == Y) then echo "Creating rmf for source spectrum..." rmfgen -w 0 -V 0 spectrumset=sp_s_$root'.fits' rmfset=sp_s_$root'.rmf' endif if ($arfgen == Y) then echo "Creating detector map for arfgen..." evselect -w 0 -V 0 table=$ev withimageset=Y imageset=detmap_$root'.ds' xcolumn=DETX ycolumn=DETY withxranges=Y ximagemin=-20000 ximagemax=20000 withyranges=Y yimagemin=-20000 yimagemax=20000 imagebinning=imageSize ximagesize=80 yimagesize=80 expression='((DETX,DETY) IN CIRCLE(0,0,'$r1'))' writedss=Y updateexposure=Y echo "Creating arf for source spectrum..." arfgen -w 0 -V 0 spectrumset=sp_s_$root'.fits' arfset=sp_s_$root'.arf' setbackscale=Y withbadpixcorr=Y badpixlocation=$ev extendedsource=Y detmaptype=dataset detmaparray=detmap_$root'.ds:' if ($arfgen == Y) then echo "Calculating BACKSCAL (witharfgen=Y)..." punlearn fkeyprint punlearn fparkey fkeyprint sp_s_$root'.fits'+1 BACKSCAL exact=yes outfile=tempba01 clobber=yes set backscal=`grep BACKSCAL= < tempba01 | head -1 | awk '{print $2}'` echo "Backscale for source spectrum: "$backscal if ($ev2 != 0) then set backsc_c = `echo $backscal $srcpixno | awk '{print $1-$2}'` echo "...minus sources/bad pixels newly subtracted... "$backsc_c fparkey $backsc_c sp_s_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes fparkey $backsc_c sp_b_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes fparkey $backsc_c sp_scb_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes fparkey $backsc_c sp_bs_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes else fparkey $backscal sp_s_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes echo "BACKSCAL added to spectra..." fparkey $backscal sp_b_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes fparkey $backscal sp_scb_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes fparkey $backscal sp_bs_$root'.fits'+1 BACKSCAL comm='Scaling factor for background ' add=yes endif echo "BACKSCAL added to spectra..." endif rm -f tempsp?? rm -f tempba?? rm -f tempim?? rm -f tempfd?? echo "Createspectra completed." exit