#! /usr1/local/bin/perl5 $version ="1.10"; $date ="2001-06-25"; $author = "kaa"; # This script checks the observation date of the input event file, finds # the correct gain correction file, then runs acis_process_events. If a # third argument is given it is used as a gain file and overrides any # other choices. # Get and parse the command line option if ($ARGV[0]=~/-(\S+)/){ $option=$1; if($option=~/h/){$help =1;} shift(@ARGV); } if($help){ print "\n acisgaincorr version $version $date $author\n\n"; print "usage: acisgaincorr [-h] input_event_file output_event_file gain_file\n\n"; print "This script checks the observation date of the input event file,\n"; print "uses that to find the correct gain file, then corrects the gain\n"; print "and writes to the output event file. This requires CIAO to be\n"; print "set up and runs the tool acis_process_events. If a third argument\n"; print "is given this is taken as the name of a gain file. In this case\n"; print "gain correction is always performed.\n\n"; exit(0); } # Check that CIAO is really set up if($ENV{'ASCDS_BIN'} !~/\S/) { print "\n You need to set up CIAO to use this script.\n\n"; exit(0); } # and we also 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 != 3) { print "\n usage : acisgaincorr [-h] input_event_file output_event_file gain_file\n"; print " type acisgaincorr -h to get more information\n\n"; exit(0); } $infile = $ARGV[0]; $outfile = $ARGV[1]; if(@ARGV == 3) { $gainfile = $ARGV[2]; } else { $gainfile = 'none'; } # If the gainfile has not been input then find out what it should be and # whether gain correction is required. if ($gainfile eq 'none') { # First read the DATE-OBS keyword from the input file to find the observation # date $command = "fkeypar $infile DATE-OBS\n"; system($command); $obsdate = `pget fkeypar value`; $year = substr($obsdate,1,4); $month = substr($obsdate,6,2); $day = substr($obsdate,9,2); print "\n","Observation performed on ",$month,"/",$day,"/",$year,"\n"; # The following somewhat messy code decides which gain file to use. if($year > 2000) { print "Detector temperature is -120 C\n"; $gainfile = 'acisD2000-08-12gainN0003.fits'; } elsif($year == 2000) { if( ($month == 1 && $day > 29) || $month < 7 || ($month == 7 && $day < 4) ) { print "Detector temperature is -120 C\n"; $gainfile = 'acisD2000-01-29gainN0003.fits'; } elsif ( ($month == 7 && $day >= 4) && ($month == 7 && $dat < 6) ) { print "Detector temperature is -120 C\n"; $gainfile = 'acisD2000-07-04gainN0003.fits'; } elsif ( ($month == 7 && $day >= 6) || ($month == 8 && $dat < 12) ) { print "Detector temperature is -120 C\n"; $gainfile = 'acisD2000-07-06gainN0003.fits'; } elsif ( ($month == 8 && $day >= 12) || $month > 8 ) { print "Detector temperature is -120 C\n"; $gainfile = 'acisD2000-08-12gainN0003.fits'; } else { print "Detector temperature is -110 C\n"; $gainfile = 'acisD1999-09-16gainN0004.fits'; } } elsif($year == 1999) { if ( ($month == 9 && $day > 16) || $month > 10 ) { print "Detector temperature is -110 C\n"; $gainfile = 'acisD1999-09-16gainN0004.fits'; } elsif ( ($month == 8 && $day > 23) || ($month == 9 && $day <= 16) ) { print "Detector temperature is -100 C and CTI is changing rapidly\n"; $gainfile = 'acisD1999-08-13gainN0002.fits'; } elsif ( $month == 8 && $day > 11 && $day <= 23 ) { print "Detector temperature is -100 C\n"; $gainfile = 'acisD1999-08-13gainN0002.fits'; } else { print "Detector temperature is -90 C\n"; $gainfile = 'acisD1999-07-22gainN0002.fits'; } } # Read the event extension to find the gain file actually used in processing $command = "fkeypar $infile GAINFILE\n"; system($command); $gainfile_used = `pget fkeypar value`; $gainfile_used =~ tr/'\n//d; if ( substr($gainfile_used,length($gainfile_used)-length($gainfile)) eq $gainfile ) { print "Gain file used in processing is current - correction not required\n"; exit(0); } else { print "Gain file used in processing was ", $gainfile_used,"\n"; print "Correcting to use ", $gainfile, "\n"; } # Get the location of the Chandra data and put together the full path for # the gain file. At the moment this is hardwired to the CALDB area but should # really use quzcif to find the correct directory. $caldir = $ENV{'CALDB'} . "/data/chandra/acis/bcf/gain/"; $gainfile = $caldir . $gainfile; } # Now find out what mode the data were acquired in so we can set the eventdef # correctly. $command = "fkeypar $infile READMODE\n"; system($command); $readmode = `pget fkeypar value`; $readmode =~ tr/a-z/A-Z/; $readmode =~ tr/ '\n//d; $command = "fkeypar $infile DATAMODE\n"; system($command); $datamode = `pget fkeypar value`; $datamode =~ tr/a-z/A-Z/; $datamode =~ tr/ '\n//d; if ( $readmode eq "TIMED" ) { if ( $datamode eq "FAINT" || $datamode eq "VFAINT" ) { $eventdef = "{d:time,s:ccd_id,s:node_id,i:expno,s:chip,s:tdet,d:det,d:sky,s:phas,l:pha,f:energy,l:pi,s:fltgrade,s:grade,x:status}"; } elsif ( $datamode eq "GRADED" ) { $eventdef = "{d:time,s:ccd_id,s:node_id,i:expno,s:chip,s:tdet,d:det,d:sky,s:corn_pha,l:pha,f:energy,l:pi,s:fltgrade,s:grade,x:status}"; } else { print $datamode," is not a recognized value of TIMED DATAMODE\n"; exit(0); } } elsif ( $readmode eq "CONTINUOUS" ) { if ( $datamode eq "3X3" ) { $eventdef = "{d:time,s:ccd_id,s:node_id,i:expno,s:chip,s:tdet,d:det,d:sky,s:phas,l:pha,f:energy,l:pi,s:fltgrade,s:grade, x:status}"; } elsif ( $datamode eq "33GRADED" ) { $eventdef = "{d:time,s:ccd_id,s:node_id,i:expno,s:chip,s:tdet,d:det,d:sky,l:pha,f:energy,l:pi,s:fltgrade,s:grade,x:status}"; } else { print $datamode," is not a recognized value of CONTINUOUS DATAMODE\n"; exit(0); } } else { print $readmode," is not a recognized value of READMODE\n"; exit(0); } # Now put together the acis_process_events command. $command = "acis_process_events gainfile=$gainfile eventdef=\"$eventdef\" doevtgrade=no stop=none infile=$infile outfile=$outfile acaofffile = NONE alignmentfile = NONE verbose=0"; # and run it... print "\n",$command,"\n"; system($command);