#!/usr/bin/perl use strict; use warnings; # # Repipelines the data and applies standard filters to event files. The output event files # follow the naming convention instrument_evt2.fits. # # Requirements: # 0) Must be run from ODF/odf directory. # 1) Assumes that SAS has been initialized. # # Find out which detectors to process. my $process_pn; my $process_mos; my $test_ans_mos = 0; my $test_ans_pn = 0; print "Process MOS data? Y/N: "; chomp ($process_mos = <> ); if (($process_mos eq 'Y') or ($process_mos eq 'y')) { $test_ans_mos = 1; } if (($process_mos eq 'N') or ($process_mos eq 'n')) { $test_ans_mos = 1; } if ($test_ans_mos == 0) { print "Unexpected response, exiting now. \n" ; exit; } print "Process PN data? Y/N: "; chomp ($process_pn = <> ); if (($process_pn eq 'Y') or ($process_pn eq 'y')) { $test_ans_pn = 1; } if (($process_pn eq 'N') or ($process_pn eq 'n')) { $test_ans_pn = 1; } if ($test_ans_pn == 0) { print "Unexpected response, exiting now. \n"; exit; } if (($process_mos =~ m/n/i) and ($process_pn =~ m/n/i)) { print "Neither MOS nor PN processing is requested, exiting. \n" ; exit; } # Verify we're in the right directory. my @res1; my $baseDir; my $currDir; chomp ($currDir = `pwd`); if ($currDir =~ m/ODF/) { print "In the ODF directory, continuing. \n"; @res1 = split(/ODF/, $currDir); $baseDir = $res1[0]; } if ($currDir =~ m/odf/) { print "In the ODF directory, continuing. \n"; @res1 = split(/odf/, $currDir); $baseDir = $res1[0]; } if ($currDir !~ m/ODF/i) { print "Not in the ODF directory, stopping now. \n"; exit; } # # I assume SAS has been initialized. Continue merrily on. # $ENV{SAS_ODF} = $currDir; $ENV{SAS_ODFPATH} = $currDir; print "Making the ccf.cif... \n"; `cifbuild`; $ENV{SAS_CCF} = $currDir.'/ccf.cif'; print "Extending the ODF summary file... \n"; `odfingest`; my $sumsas = glob ("*SUM.SAS"); $ENV{SAS_ODF} = $currDir.'/'.$sumsas; print "$ENV{SAS_ODF}\n"; print "$ENV{SAS_ODFPATH}\n"; print "$ENV{SAS_CCF}\n"; chdir $baseDir; if (! -d $baseDir.'/proc') { `mkdir proc`; } chdir $baseDir.'/proc'; if (($process_mos eq "y") or ($process_mos eq "Y")) { print "Processing the MOS files... \n"; `emproc`; } if (($process_pn eq "y") or ($process_pn eq "Y")){ print "Processing the PN files... \n"; `epproc`; } my $currLine; if (($process_mos eq "y") or ($process_mos eq "Y")) { my $m1_evt1 = glob ("*EMOS1*ImagingEvts.ds"); my $m2_evt1 = glob ("*EMOS2*ImagingEvts.ds"); `cp $m1_evt1 'm1_evt1.fits'`; `cp $m2_evt1 'm2_evt1.fits'`; print "Applying standard filters to MOS data... \n"; `evselect table=m1_evt1.fits:EVENTS withfilteredset=yes expression='(PATTERN<=12)&&(PI in [200:12000])&&#XMMEA_EM&&(FLAG == 0)' filteredset=m1_evt2.fits filtertype=expression keepfilteroutput=yes updateexposure=yes filterexposure=yes` ; `evselect table=m2_evt1.fits:EVENTS withfilteredset=yes expression='(PATTERN<=12)&&(PI in [200:12000])&&#XMMEA_EM&&(FLAG == 0)' filteredset=m2_evt2.fits filtertype=expression keepfilteroutput=yes updateexposure=yes filterexposure=yes`; `rm m1_evt1.fits`; `rm m2_evt1.fits`; } if (($process_pn eq "y") or ($process_pn eq "Y")) { my $pn_evt1 = glob ("*EPN*ImagingEvts.ds"); `cp $pn_evt1 'pn_evt1.fits'`; print "Applying standard filters to PN data... \n"; # Is the PN in timing mode? `fkeyprint pn_evt1.fits+0 datamode outfile=datamode.list`; my $timingflag = 0; open (DATAMODE, "<", "datamode.list"); while ($currLine = ) { if ($currLine =~ m/DATAMODE= 'TIMING '/ ) { $timingflag = 1; } } close (DATAMODE); `rm datamode.list`; if ($timingflag eq 0) { `evselect table=pn_evt1.fits:EVENTS withfilteredset=yes expression='(PATTERN<=12)&&(PI in [200:15000])&&#XMMEA_EP&&(FLAG == 0)' filteredset=pn_evt2.fits filtertype=expression keepfilteroutput=yes updateexposure=yes filterexposure=yes`; } else { `evselect table=pn_evt1.fits:EVENTS withfilteredset=yes expression='(PATTERN<=4)&&(PI in [200:15000])&&#XMMEA_EP&&(FLAG == 0)' filteredset=pn_evt2.fits filtertype=expression keepfilteroutput=yes updateexposure=yes filterexposure=yes`; } `rm pn_evt1.fits`; } print "Done.";