#! /bin/sh # This is the LHEA perl script: /cvmfs/extras-fp7.egi.eu/extras/heasoft/swift/x86_64-unknown-linux-gnu-libc2.19-0/bin/uvotapercorr # The purpose of this special block is to make this script work with # the user's local perl, regardless of where that perl is installed. # The variable LHEAPERL is set by the initialization script to # point to the local perl installation. #------------------------------------------------------------------------------- eval ' if [ "x$LHEAPERL" = x ]; then echo "Please run standard LHEA initialization before attempting to run /cvmfs/extras-fp7.egi.eu/extras/heasoft/swift/x86_64-unknown-linux-gnu-libc2.19-0/bin/uvotapercorr." exit 3 elif [ "$LHEAPERL" = noperl ]; then echo "During LHEA initialization, no acceptable version of Perl was found." echo "Cannot execute script /cvmfs/extras-fp7.egi.eu/extras/heasoft/swift/x86_64-unknown-linux-gnu-libc2.19-0/bin/uvotapercorr." exit 3 elif [ `$LHEAPERL -v < /dev/null 2> /dev/null | grep -ic "perl"` -eq 0 ]; then echo "LHEAPERL variable does not point to a usable perl." exit 3 else # Force Perl into 32-bit mode (to match the binaries) if necessary: if [ "x$HD_BUILD_ARCH_32_BIT" = xyes ]; then if [ `$LHEAPERL -V 2> /dev/null | grep -ic "USE_64_BIT"` -ne 0 ]; then VERSIONER_PERL_PREFER_32_BIT=yes export VERSIONER_PERL_PREFER_32_BIT fi fi exec $LHEAPERL -x $0 ${1+"$@"} fi ' if(0); # Do not delete anything above this comment from an installed LHEA script! #------------------------------------------------------------------------------- #!perl # $Source: /headas/headas/swift/uvot/tasks/uvotapercorr/uvotapercorr,v $ # $Revision: 1.7 $ # $Date: 2010/12/08 14:41:10 $ # # $Log: uvotapercorr,v $ # Revision 1.7 2010/12/08 14:41:10 rwiegand # Motivated by requirement for uvotdetect to support LSS correction, modified # photometry module so that each correction uses the generic names for the # input (UNCORR_RATE) and output (CORR_RATE). # # Revision 1.6 2009/07/22 00:42:19 rwiegand # Needed to print out messages formatted in library and update PIL file # in finalize. # # Revision 1.5 2009/07/21 23:25:49 rwiegand # Updated to use UVOT::Calibration and UVOT::Source support for # aperture correction. New default value fwhmsig=-1 indicates to # use recommended value. # use strict; package UVOT::AperCorr; use base qw(Task::HEAdas); use Task qw(:codes); use SimpleFITS; use UVOT::Calibration; use UVOT::Source; { my $task = __PACKAGE__->new(version => '2.0'); $task->run; exit($task->{code}); } sub execute { my ($self) = @_; foreach my $step (qw( initialize loadCalibration applyCalibration )) { $self->$step; last if not $self->isValid; } $self->finalize; } sub initialize { my ($self) = @_; $self->pilOptions( options => [ qw( cntrate=real ratesig=real aperad=real fwhmsig=real filter=string psffile=file chatter=int ) ], get => 1, ); my $args = $self->args; if ($self->chatter(3)) { $self->report(join("\n\t", "Got parameters:", "cntrate = $args->{cntrate}", "ratesig = $args->{ratesig}", " aperad = $args->{aperad}", "fwhmsig = $args->{fwhmsig}", " filter = $args->{filter}", "psffile = $args->{psffile}", "chatter = $args->{chatter}")); } # fudge in the absence of a WHITE filter PSF calibration: use the B filter my $filter = uc($args->{filter}); if ($filter eq 'WHITE') { $filter = 'B'; $self->warning("There is no PSF calibration for the WHITE filter." . "\nUsing the B filter calibration instead."); } $self->{FILTER} = $filter; } sub loadCalibration { my ($self) = @_; my $args = $self->args; # set up default header my %header = ( TELESCOP => 'SWIFT', INSTRUME => 'UVOTA', FILTER => $self->{FILTER}, ); my %reef; UVOT::Calibration::loadEncircledEnergy($self, \%reef, PAR => $args->{psffile}, HEADER => \%header, ); $self->{REEF} = \%reef; UVOT::Calibration::primeEncircledEnergy($self, $self->{REEF}, $self->{FILTER}); } sub applyCalibration { my ($self) = @_; my $args = $self->args; if ($args->{fwhmsig} < 0) { $args->{fwhmsig} = UVOT::Calibration::DEFAULT_FWHM_UNCERTAINTY_percent; } my %tmp = ( RATE => $args->{cntrate}, RATE_ERR => $args->{ratesig}, APERTURE_RADIUS_arcsec => $args->{aperad}, FWHM_UNCERTAINTY_percent => $args->{fwhmsig}, FILTER => $self->{FILTER}, ); UVOT::Source::applyEncircledEnergy($self, $self->{REEF}, \%tmp); $self->{DATA} = \%tmp; } sub finalize { my ($self) = @_; my $result = $self->{DATA}; return if not ref($result); if (my $aref = $result->{ERRORS}) { foreach my $item (@$aref) { $self->error(BAD_EXECUTE, $item); } } if (my $aref = $result->{WARNINGS}) { foreach my $item (@$aref) { $self->warning($item); } } if (my $aref = $result->{NOTES} and $self->chatter(3)) { foreach my $item (@$aref) { $self->report($item) if $self->chatter; } } if (defined($result->{CORR_RATE}) and defined($result->{CORR_RATE_ERR})) { my $cntrate = $result->{CORR_RATE}; my $raterr = $result->{CORR_RATE_ERR}; $self->report( sprintf('Corrected count rate = %.4f +/- %.4f c/s' . ' (includes systematics of %.1f%%)', $cntrate, $raterr, 100 * $result->{FWHM_ERR_SYS}) ); HEACORE::PIL::PILPutReal(aperate => int($cntrate * 1e5) / 1e5); HEACORE::PIL::PILPutReal(apersig => int($raterr * 1e5) / 1e5); } else { $self->error(BAD_EXECUTE, 'no results'); } }