#! /usr1/local/bin/perl5 $version ="1.12"; $date ="2001-01-22"; $author = "kaa"; # v1.11 CIAO v2 compatibility. Now also checks $ASCDS_BIN for the pset # executable. Uses the CALDB location for QEU files. # v1.12 For CIAO v2 don't change the QEU parameters because they are set # to use the CALDB. # This script checks the observation date of the input event file and updates # the ardlib.par file to use the correct QE map file. It also sets up the # aspect histogram file if it doesn't already exist. # Get and parse the command line option if ($ARGV[0]=~/-(\S+)/){ $option=$1; if($option=~/h/){$help =1;} shift(@ARGV); } if($help){ print "\n acisarfprep version $version $date $author\n\n"; print "usage: acisarfprep [-h] input_event_file [aspect_file]\n\n"; print "For CIAO v1 this script checks the observation date of the\n"; print "input event file, uses that to find the correct QE map file,\n"; print "then updates the ardlib.par file so the correct map is used\n"; print "when mkarf is run. For CIAO v2 the ardlib.par file uses the\n"; print "CALDB so this is not necessary\n"; print "If the aspect file is given then the script also creates the \n"; print "aspect histogram file if it does not already exist.\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 != 1) { print "\n usage : acisgaincorr [-h] input_event_file [aspect_file]\n"; print " type acisgaincorr -h to get more information\n\n"; exit(0); } $infile = $ARGV[0]; if (@ARGV == 2) { $aspect = $ARGV[1]; } else { $aspect = "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 QE map file to use. if($year == 2000) { if( ($month == 1 && $day > 29) || $month > 1 ) { print "Detector temperature is -120 C\n"; $qemapfile = 'acisD2000-01-29qeuN0001.fits'; } else { print "Detector temperature is -110 C\n"; $qemapfile = 'acisD1999-09-16qeuN0002.fits'; } } elsif($year == 1999) { if ( ($month == 9 && $day > 16) || $month > 10 ) { print "Detector temperature is -110 C\n"; $qemapfile = 'acisD1999-09-16qeuN0002.fits'; } elsif ( ($month == 8 && $day > 23) || ($month == 9 && $day <= 16) ) { print "Detector temperature is -100 C and CTI is changing rapidly\n"; $qemapfile = 'acisD1996-11-01qeuN0001.fits'; } elsif ( $month == 8 && $day > 11 && $day <= 23 ) { print "Detector temperature is -100 C\n"; $qemapfile = 'acisD1996-11-01qeuN0001.fits'; } else { print "Detector temperature is -90 C\n"; $qemapfile = 'acisD1996-11-01qeuN0001.fits'; } } # If the QEU map file exists then go ahead and change the ardlib parameters # if this is CIAO v1 (which is identified by the non-existence of the # ATOMDB environment variable). if ( $qemapfile ne "none" && $ENV{'ATOMDB'} !~/\S/ ) { # Get the location of the Chandra data and put together the full path for # the QE map file. $caldir = $ENV{'CALDB'} . "/data/chandra/acis/bcf/qe/"; $qemapfile = $caldir . $qemapfile; # Now set the ardlib.par parameters for each chip. Note that we force the # use of the CIAO pset since the FTOOLS version doesn't seem to work right # in this case. Note that pset location moved between CIAO v1 and CIAO v2 # so have to try both cases. $psetcom = $ENV{'ASCDS_IMAGER_PATH'} . "/pset"; if ( !(-f $psetcom) ) { $psetcom = $ENV{'ASCDS_BIN'} . "/pset"; } $chip = 0; while ( $chip < 10 ) { $command = $psetcom . " ardlib AXAF_ACIS" . $chip . "_QEU_FILE = $qemapfile\[" . ($chip+1) . "\]"; print $command,"\n"; system($command); ++$chip; } print "\n ardlib.par modified\n\n"; } if ( $aspect eq "none" ) { exit(0); } # Now do the aspect histogram part of the set-up. First get the root part # of the aspect file name and construct the names for the corrected aspect # file and the aspect histogram file. $aspectroot = substr($aspect,0,length($aspect)-5); $aspectsim = $aspectroot . "_sim.fits"; $aspecthist = $aspectroot . "_hist.fits"; # If the aspect histogram file exists then we are done. if ( -f $aspecthist ) { print "Aspect histogram file already exists so we are done.\n"; exit(0); } # It doesn't so check whether the corrected aspect file exists. If it doesn't # then we need to construct it. if ( !(-f $aspectsim) ) { # First construct a GTI table from the event file $command = "fextract infile=$infile+2 outfile=temp.gti"; print $command,"\n"; system($command) && die "Failed to extract GTI extension from event file\n"; # now run the apply sim program $command = "asp_apply_sim infile=$aspect\[\@temp.gti\] outfile=$aspectsim"; print $command,"\n"; print "this may take a while...\n"; system($command) && die "Failed to run asp_apply_sim\n"; # tidy up the temporary file $command = "rm -f temp.gti"; system($command); } # finally make the actual aspect histogram file. $command = "asphist infile=$aspectsim outfile=$aspecthist gtifile=$infile dtffile= "; print $command,"\n"; system($command) && die "Failed to run asphist\n";