#! /usr/bin/perl $version ="1.00"; $date ="2002-11-11"; $author = "kaa"; # This script filters the XMM event file on PATTERN, PI, and FLAG # Get and parse the command line option if ($ARGV[0]=~/-(\S+)/){ $option=$1; if($option=~/h/){$help =1;} shift(@ARGV); } if($help){ print "\n xmmclean version $version $date $author\n\n"; print "usage: xmmclean [-h] infile outfile pattern flag\n\n"; print "This script filters the input XMM event file using the\n"; print "standard criteria ie PATTERN <= 12 (for MOS) or <= 4 (for PN),\n"; print "PI between 200 and 15000, and FLAG = 0. If a third argument is\n"; print "given then it is used for the upper limit on PATTERN. If a\n"; print "fourth argument is given it used for the upper limit on FLAG.\n"; print "This script should not be run on an event file that has been\n"; print "filtered using the SAS tool xmmselect.\n"; exit(0); } # we need HEASOFT... if($ENV{'LHEASOFT'} !~/\S/) { print "\n You need to set up HEASOFT to use this script.\n\n"; exit(0); } # Check that the user gave the correct number of arguments. if(@ARGV < 2 || @ARGV > 4) { print "\n usage : xmmclean [-h] infile outfile pattern flag\n"; print " type xmmclean -h to get more information\n\n"; exit(0); } $infile = $ARGV[0]; $outfile = $ARGV[1]; # check that DSTYP3 doesn't already exist in the input file. If it does # the user has already run xmmselect or the XMM folks have changed the # event file format. $command = "fkeypar $infile\[EVENTS\] DSTYP3"; system($command); if ( `pget fkeypar exist` eq "yes" ) { print "\n The DSTYP3 keyword already exists in the input file. Either you\n"; print " have already run xmmselect or the event file format has changed.\n\n"; exit(0); } # get the instrument name to set the default upper limit on the pattern $command = "fkeypar $infile+0 INSTRUME"; system($command); $instrument = `pget fkeypar value`; $instrument =~ tr/'\n//d; print "Instrument is ", $instrument, "\n"; if ( substr($instrument,0,5) eq "EMOS1" || substr($instrument,0,5) eq "EMOS2" ) { $pattern_max = 12; } elsif ( substr($instrument,0,3) eq "EPN" ) { $pattern_max = 4; } else { print "Instrument must be one of EMOS1, EMOS2, or EPN\n"; exit(0); } # If a third argument has been given then override the default pattern if ( @ARGV >= 3 ) { $pattern_max = $ARGV[2]; } # and if a fourth argument has been given then override the default flag if ( @ARGV == 4 ) { $flag_max = $ARGV[3]; } else { $flag_max = 0; } # run fselect to do filtering $command = "fselect infile=$infile\[EVENTS\] outfile=$outfile expr='PATTERN <= $pattern_max && PI <= 15000 && PI >= 200 && FLAG <= $flag_max' histkw=yes copyall=yes keycopy=yes clobber=no"; print "\n",$command,"\n\n"; system($command); # write the DS keywords $command = "fparkey FLAG $outfile\[EVENTS\] DSTYP3 add=yes comm='data subspace descriptor: name'"; system($command); $command = "fparkey PATTERN $outfile\[EVENTS\] DSTYP4 add=yes comm='data subspace descriptor: name'"; system($command); $command = "fparkey PI $outfile\[EVENTS\] DSTYP5 add=yes comm='data subspace descriptor: name'"; system($command); $command = "fparkey CHAN $outfile\[EVENTS\] DSUNI5 add=yes comm='data subspace descriptor: units'"; system($command); $command = "fparkey '0:$flag_max' $outfile\[EVENTS\] DSVAL3 add=yes comm='data subspace descriptor: value'"; system($command); $command = "fparkey '0:$pattern_max' $outfile\[EVENTS\] DSVAL4 add=yes comm='data subspace descriptor: value'"; system($command); $command = "fparkey '200:15000' $outfile\[EVENTS\] DSVAL5 add=yes comm='data subspace descriptor: value'"; system($command);