#!/usr/bin/perl -w use SAS; require "esas_parameters_init.pl"; require "esas_GVariables.pm"; &init(); &run(); #hi #======================================================================== sub init() { #.. Create object to store parameters #.. Define Global Variables use vars qw($gv); $gv = esas_GVariables->new(); #.. Init Program Parameters &cheese_parameters_init(@ARGV); # $task = "cheese"; # $version = "4.0"; # $date = "2010-02-24"; # $author = "S. L. Snowden"; # print "\n"; # print "Task: $task \n"; # print "Version: $version \n"; # print "Date: $date \n"; # print "Author: $author \n"; # Included in SAS: Date # SAS Version: # A. Ibarra Ibaibarriaga } ## @method void run() # Run Cheese # @return Void #======================================================================== sub run() { # Set the variables $nexp=0; foreach ( $gv->Cheese_prefixm ) { print "val $_\n"; $nexp = $nexp + 1; $prefix[$nexp] = $_; print "mos prefix $nexp: $prefix[$nexp]\n"; } $nexpp=0; foreach ($gv->Cheese_prefixp ) { print "val $_\n"; $nexpp = $nexpp + 1; $prefixp[$nexpp] = $_; print "pn prefix $nexpp: $prefixp[$nexpp]\n"; } $verb = $gv->Cheese_verb; $scale = $gv->Cheese_scale; print "verb: $verb\n"; print "scale: $scale\n"; $rate = $gv->Cheese_rate; print "rate: $rate\n"; $dist = $gv->Cheese_dist; print "dist: $dist\n"; $clobber = $gv->Cheese_clobber; print "clobber: $clobber\n"; $elow = $gv->Cheese_elow; $ehigh = $gv->Cheese_ehigh; $rate = 1.e-14 * $rate; #$rate = 0.32 * $rate / 1.e-12; print "elow: $elow\n"; print "ehigh: $ehigh\n"; open( JUNK_HNDL, ">>command.csh" ); # First create an attitude file if necessary $affile = "atthk.fits"; if ( -r $affile ) { print "attitude file already exists\n"; print "use the old file\n"; print " \n"; } else { $comm = "atthkgen atthkset=atthk.fits timestep=1 "; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; } # Next extract the mos images in the selected band eV band for ( $nn = 1 ; $nn <= $nexp ; $nn++ ) { $imfile = "mos".$prefix[$nn]."-obj-im.fits"; if ( -r $imfile ) { print "image file already exists: $imfile\n"; if ( $clobber == 1 ) { print "clobber it an continue\n"; $comm = "evselect table=mos".$prefix[$nn]."-clean.fits:EVENTS ". "withfilteredset=yes expression='(PATTERN<=12)&&(FLAG == 0)". "&&(PI in [".$elow.":".$ehigh."])' filtertype=expression ". "imagebinning='imageSize' imagedatatype='Int32' ". "imageset=mos".$prefix[$nn]."-obj-im.fits squarepixels=yes ". "ignorelegallimits=yes withxranges=yes withyranges=yes ". "xcolumn='X' ximagesize=900 ximagemax=48400 ximagemin=3401 ". "ycolumn='Y' yimagesize=900 yimagemax=48400 yimagemin=3401 ". "updateexposure=yes filterexposure=yes verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } else { print "use the old file\n"; } print " \n"; } else { print "create event image\n"; $comm = "evselect table=mos".$prefix[$nn]."-clean.fits:EVENTS ". "withfilteredset=yes expression='(PATTERN<=12)&&(FLAG == 0)". "&&(PI in [".$elow.":".$ehigh."])' filtertype=expression ". "imagebinning='imageSize' imagedatatype='Int32' ". "imageset=mos".$prefix[$nn]."-obj-im.fits squarepixels=yes ". "ignorelegallimits=yes withxranges=yes withyranges=yes ". "xcolumn='X' ximagesize=900 ximagemax=48400 ximagemin=3401 ". "ycolumn='Y' yimagesize=900 yimagemax=48400 yimagemin=3401 ". "updateexposure=yes filterexposure=yes verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } # Now make mos exposure maps for the FOV image $imfile = "mos" . $prefix[$nn] . "-exp-im.fits"; if ( -r $imfile ) { print "exposure image file already exists: $imfile\n"; if ( $clobber == 1 ) { print "clobber it an continue\n"; $comm = "eexpmap attitudeset=atthk.fits ". "eventset=mos".$prefix[$nn]."-clean.fits:EVENTS ". "expimageset=mos".$prefix[$nn]."-exp-im.fits ". "imageset=mos".$prefix[$nn]."-obj-im.fits ". "pimax=".$ehigh." pimin=".$elow." withdetcoords=no ". "verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } else { print "use the old file\n"; } print " \n"; } else { print "create the exposure map\n"; $comm = "eexpmap attitudeset=atthk.fits ". "eventset=mos".$prefix[$nn]."-clean.fits:EVENTS ". "expimageset=mos".$prefix[$nn]."-exp-im.fits ". "imageset=mos".$prefix[$nn]."-obj-im.fits ". "pimax=".$ehigh." pimin=".$elow." withdetcoords=no ". "verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } # Make a mask $imfile = "mos".$prefix[$nn]."-mask-im.fits"; if ( -r $imfile ) { print "exposure image file already exists: $imfile\n"; if ( $clobber == 1 ) { print "clobber it an continue\n"; $comm = "emask detmaskset=mos".$prefix[$nn]."-mask-im.fits ". "expimageset=mos".$prefix[$nn]."-exp-im.fits ". "threshold1=0.1 threshold2=0.5 verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } else { print "use the old file\n"; } print " \n"; } else { print "create the mask\n"; $comm = "emask detmaskset=mos".$prefix[$nn]."-mask-im.fits ". "expimageset=mos".$prefix[$nn]."-exp-im.fits ". "threshold1=0.1 threshold2=0.5 verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } } # Next extract the pn images in the selected band eV band for ( $nnp = 1 ; $nnp <= $nexpp ; $nnp++ ) { print "nexpp $nexpp\n"; $imfile = "pn" . $prefixp[$nnp] . "-obj-im.fits"; if ( -r $imfile ) { print "image file already exists: $imfile\n"; if ( $clobber == 1 ) { print "clobber it an continue\n"; $comm = "evselect table=pn".$prefixp[$nnp]."-clean.fits:EVENTS ". "withfilteredset=yes expression='(PATTERN<=12)&&(FLAG == 0)&&". "(PI in [".$elow.":".$ehigh."])&&(DETY in [-16510:14345])' ". "filtertype=expression imagebinning='imageSize' imagedatatype='Int32' ". "imageset=pn".$prefixp[$nnp]."-obj-im.fits squarepixels=yes ". "ignorelegallimits=yes withxranges=yes withyranges=yes xcolumn='X' ". "ximagesize=900 ximagemax=48400 ximagemin=3401 ycolumn='Y' ". "yimagesize=900 yimagemax=48400 yimagemin=3401 updateexposure=yes ". "filterexposure=yes verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } else { print "use the old file\n"; } print " \n"; } else { print "create the event image\n"; $comm = "evselect table=pn".$prefixp[$nnp]."-clean.fits:EVENTS ". "withfilteredset=yes expression='(PATTERN<=12)&&(FLAG == 0)&&". "(PI in [".$elow.":".$ehigh."])&&(DETY in [-16510:14345])' ". "filtertype=expression imagebinning='imageSize' imagedatatype='Int32' ". "imageset=pn".$prefixp[$nnp]."-obj-im.fits squarepixels=yes ". "ignorelegallimits=yes withxranges=yes withyranges=yes xcolumn='X' ". "ximagesize=900 ximagemax=48400 ximagemin=3401 ycolumn='Y' ". "yimagesize=900 yimagemax=48400 yimagemin=3401 updateexposure=yes ". "filterexposure=yes verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } # Now make pn exposure maps for the FOV image $imfile = "pn" . $prefixp[$nnp] . "-exp-im.fits"; if ( -r $imfile ) { print "exposure image file already exists: $imfile\n"; if ( $clobber == 1 ) { print "clobber it an continue\n"; $comm = "eexpmap attitudeset=atthk.fits ". "eventset=pn".$prefixp[$nnp]."-clean.fits:EVENTS ". "expimageset=pn".$prefixp[$nnp]."-exp-im.fits ". "imageset=pn".$prefixp[$nnp]."-obj-im.fits ". "pimax=".$ehigh." pimin=". $elow." withdetcoords=no ". "verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } else { print "use the old file\n"; } print " \n"; } else { print "create the exposure map\n"; $comm = "eexpmap attitudeset=atthk.fits ". "eventset=pn".$prefixp[$nnp]."-clean.fits:EVENTS ". "expimageset=pn".$prefixp[$nnp]."-exp-im.fits ". "imageset=pn".$prefixp[$nnp]."-obj-im.fits ". "pimax=".$ehigh." pimin=". $elow." withdetcoords=no ". "verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } # Make a mask $imfile = "pn" . $prefixp[$nnp] . "-mask-im.fits"; if ( -r $imfile ) { print "exposure image file already exists: $imfile\n"; if ( $clobber == 1 ) { print "clobber it an continue\n"; $comm = "emask detmaskset=pn".$prefixp[$nnp]."-mask-im.fits ". "expimageset=pn".$prefixp[$nnp]."-exp-im.fits ". "threshold1=0.1 threshold2=0.5 verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } else { print "use the old file\n"; } print " \n"; } else { print "create the mask\n"; $comm = "emask detmaskset=pn".$prefixp[$nnp]."-mask-im.fits ". "expimageset=pn".$prefixp[$nnp]."-exp-im.fits ". "threshold1=0.1 threshold2=0.5 verbosity=".$verb; print JUNK_HNDL "$comm\n"; print JUNK_HNDL " \n"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } } # Set the parameter names $tempdet = 0; for ( $nn = 1 ; $nn <= $nexp ; $nn++ ) { if ( $nn == 1 ) { $imlist = "mos" . $prefix[$nn] . "-obj-im.fits"; $explist = "mos" . $prefix[$nn] . "-exp-im.fits"; $bkglist = "mos" . $prefix[$nn] . "-bkgimage.fits"; $piminlist = " " . $elow . " "; $pimaxlist = " " . $ehigh . " "; $ecflist = "1.2"; $det = substr( $prefix[$nn], 0, 1 ); if ( $tempdet != $det ) { $masklist = "mos" . $prefix[$nn] . "-mask-im.fits"; $tempdet = $det; } } else { $imlist = $imlist . " mos" . $prefix[$nn] . "-obj-im.fits"; $explist = $explist . " mos" . $prefix[$nn] . "-exp-im.fits"; $bkglist = $bkglist . " mos" . $prefix[$nn] . "-bkgimage.fits"; $piminlist = $piminlist . " " . $elow . " "; $pimaxlist = $pimaxlist . " " . $ehigh . " "; $ecflist = $ecflist . " 1.2"; $det = substr( $prefix[$nn], 0, 1 ); if ( $tempdet != $det ) { $masklist = $masklist . " mos" . $prefix[$nn] . "-mask-im.fits"; $tempdet = $det; } } } if ( $nexpp >= 1 ) { for ( $nnp = 1 ; $nnp <= $nexpp ; $nnp++ ) { if ( $nnp == 1 ) { if ( $nexp >= 1 ) { $imlist = $imlist . " pn" . $prefixp[$nnp] . "-obj-im.fits"; $explist = $explist . " pn" . $prefixp[$nnp] . "-exp-im.fits"; $bkglist = $bkglist . " pn" . $prefixp[$nnp] . "-bkgimage.fits"; $piminlist = $piminlist . " " . $elow . " "; $pimaxlist = $pimaxlist . " " . $ehigh . " "; $masklist = $masklist . " pn" . $prefixp[$nnp] . "-mask-im.fits"; $ecflist = $ecflist . " 3.2"; } else { $imlist = "pn" . $prefixp[$nnp] . "-obj-im.fits"; $explist = "pn" . $prefixp[$nnp] . "-exp-im.fits"; $bkglist = "pn" . $prefixp[$nnp] . "-bkgimage.fits"; $piminlist = " " . $elow . " "; $pimaxlist = " " . $ehigh . " "; $masklist = "pn" . $prefixp[$nnp] . "-mask-im.fits"; $ecflist = "3.2"; } } else { $imlist = $imlist . " pn" . $prefixp[$nnp] . "-obj-im.fits"; $explist = $explist . " pn" . $prefixp[$nnp] . "-exp-im.fits"; $bkglist = $bkglist . " pn" . $prefixp[$nnp] . "-bkgimage.fits"; $piminlist = $piminlist . " " . $elow . " "; $pimaxlist = $pimaxlist . " " . $ehigh . " "; $masklist = $masklist . " pn" . $prefixp[$nnp] . "-mask-im.fits"; $ecflist = $ecflist . " 3.2"; } } } # Do the first box detection print "$imlist\n"; print "$explist\n"; print "$masklist\n"; print "$bkglist\n"; print "$piminlist\n"; print "$pimaxlist\n"; print "$ecflist\n"; $comm = "eboxdetect detmasksets='".$masklist."' withdetmask=yes ". "imagebuffersize=900 expimagesets='".$explist. "' ". "withexpimage=yes nruns=3 likemin=8 boxsize=5 ecf='".$ecflist."' ". "imagesets='".$imlist."' verbosity=".$verb." boxlistset=boxlist.fits ". "pimin='".$piminlist."' pimax='".$pimaxlist."'"; print "$comm\n"; print " \n"; system "$comm"; print " \n"; for ( $nn = 1 ; $nn <= $nexp ; $nn++ ) { $comm = "esplinemap boxlistset=boxlist.fits ". "imageset=mos".$prefix[$nn]."-obj-im.fits ". "expimageset=mos".$prefix[$nn]."-exp-im.fits ". "withexpimage=yes detmaskset=mos".$prefix[$nn]."-mask-im.fits ". "withdetmask=yes bkgimageset=mos".$prefix[$nn]."-bkgimage.fits ". "pimin=".$elow." pimax=".$ehigh." idband=1 verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } for ( $nnp = 1 ; $nnp <= $nexpp ; $nnp++ ) { $comm = "esplinemap boxlistset=boxlist.fits ". "imageset=pn".$prefixp[$nnp]."-obj-im.fits ". "expimageset=pn".$prefixp[$nnp]."-exp-im.fits ". "withexpimage=yes withdetmask=yes ". "detmaskset=pn".$prefixp[$nnp]."-mask-im.fits ". "bkgimageset=pn".$prefixp[$nnp]."-bkgimage.fits ". "pimin=".$elow." pimax=".$ehigh." idband=1 ". "verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; print " \n"; } $comm = "eboxdetect detmasksets='".$masklist."' withdetmask=yes ". "imagebuffersize=900 expimagesets='".$explist."' withexpimage=yes ". "nruns=3 likemin=10 boxsize=5 ecf='".$ecflist. "' ". "imagesets='".$imlist."' boxlistset=boxlist-f.fits ". "pimin='".$piminlist."' pimax='".$pimaxlist . "' boxsize=5 ". "ecf='".$ecflist."' imagesets='".$imlist."' "."usemap=yes ". "bkgimagesets='".$bkglist."' verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; print " \n"; $comm = "emldetect imagesets='".$imlist."' bkgimagesets='".$bkglist."' ". "boxlistset=boxlist-f.fits mllistset=emllist.fits mlmin=12 ". "dmlextmin=10 maxextent=20 expimagesets='".$explist."' ". "withexpimage=yes detmasksets='".$masklist."' withdetmask=yes ". "imagebuffersize=900 mlmin=10 scut=0.9 ecut=0.68 ecf='".$ecflist."' ". "mergedlistset=mergedlist.fits pimin='".$piminlist."' ". "pimax='".$pimaxlist."' verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; print " \n"; $emllistvar = "emllist.fits"; # Fix to fill in the emllist.fits null values for the combined value if ( -r $emllistvar ) { print "emllist.fits file exists\n"; $comm = "mv emllist.fits emllistout.fits"; system "$comm"; $comm = "fill_list srclistin=emllistout.fits srclistout=emllist.fits"; system "$comm"; # Create the background regions selection expression for ( $nn = 1 ; $nn <= $nexp ; $nn++ ) { $det = substr( $prefix[$nn], 0, 1 ) + 1; $comm = "region eventset=mos".$prefix[$nn]."-clean.fits ". "operationstyle=global srclisttab=emllist.fits:SRCLIST ". "expression='(FLUX >= ".$rate.")&&(ID_INST == 0)&&". "(ID_BAND == 0)&&(DIST_NN >= ".$dist.")&&(DET_ML >= 15)' ". "bkgregionset=mos".$prefix[$nn]."-bkg_region-det.fits ". "energyfraction=".$scale." radiusstyle=enfrac outunit=detxy ". "verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; $comm = "region eventset=mos".$prefix[$nn]."-clean.fits ". "operationstyle=global srclisttab=emllist.fits:SRCLIST ". "expression='(FLUX >= ".$rate.")&&(ID_INST == 0)&&". "(ID_BAND == 0)&&(DIST_NN >= ".$dist.")&&(DET_ML >= 15)' ". "bkgregionset=mos".$prefix[$nn]."-bkg_region-sky.fits ". "radiusstyle=contour bkgratestyle=col nosrcellipse=yes ". "bkgfraction=".$scale." outunit=xy verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; # Create the masks $comm = "make_mask inimage=mos".$prefix[$nn]."-obj-im.fits ". "inmask=mos".$prefix[$nn]."-mask-im.fits ". "outmask=mos".$prefix[$nn]."-cheese.fits ". "reglist=mos".$prefix[$nn]."-bkg_region-sky.fits"; print "$comm\n"; print " \n"; system "$comm"; } # Do it again for the pn for ( $nnp = 1 ; $nnp <= $nexpp ; $nnp++ ) { $comm = "region eventset=pn". $prefixp[$nnp]."-clean.fits ". "operationstyle=global srclisttab=emllist.fits:SRCLIST ". "expression='(DIST_NN >= ".$dist.")&&(FLUX >= ".$rate.")". "&&(ID_INST == 0)&&(ID_BAND == 0)&&(DET_ML >= 15)' ". "bkgregionset=pn".$prefixp[$nnp]."-bkg_region-det.fits ". "energyfraction=".$scale." radiusstyle=enfrac ". "outunit=detxy verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; $comm = "region eventset=pn".$prefixp[$nnp]."-clean.fits ". "operationstyle=global srclisttab=emllist.fits:SRCLIST ". "expression='(DIST_NN >= ".$dist.")&&(FLUX >= ".$rate.")". "&&(ID_INST == 0)&&(ID_BAND == 0)&&(DET_ML >= 15)' ". "bkgregionset=pn".$prefixp[$nnp]."-bkg_region-sky.fits ". "radiusstyle=contour bkgratestyle=col nosrcellipse=yes ". "bkgfraction=".$scale." outunit=xy verbosity=".$verb; print "$comm\n"; print " \n"; system "$comm"; # Create the masks $comm = "make_mask inimage=pn".$prefixp[$nnp]."-obj-im.fits ". "inmask=pn".$prefixp[$nnp]."-mask-im.fits ". "outmask=pn".$prefixp[$nnp]."-cheese.fits ". "reglist=pn".$prefixp[$nnp]."-bkg_region-sky.fits"; print "$comm\n"; print " \n"; system "$comm"; # Get rid of a few more extra files system "rm -f filtered.fits"; } } else { print "emllist.fits file does not exist\n"; print "Copy the nominal masks to cheese masks \n"; for ( $nn = 1 ; $nn <= $nexp ; $nn++ ) { $det = substr( $prefix[$nn], 0, 1 ) + 1; # Create the masks $comm = "cp mos".$prefix[$nn]."-mask-im.fits ". "mos".$prefix[$nn]."-cheese.fits "; print "$comm\n"; print " \n"; system "$comm"; } for ( $nnp = 1 ; $nnp <= $nexpp ; $nnp++ ) { # Create the masks $comm = "cp pn".$prefixp[$nnp]."-mask-im.fits ". "pn".$prefixp[$nnp]."-cheese.fits "; print "$comm\n"; print " \n"; system "$comm"; # Get rid of a few more extra files system "rm -f filtered.fits"; } } }