package Subs::XrtPhasCorr;
##############################################################################
#
# DESCRIPTION: Produce XRT Phas Corr in PC mode
#
# HISTORY: $Log: XrtPhasCorr.pm,v $
# HISTORY: Revision 1.4 2012/01/12 06:52:03 apsop
# HISTORY: Changes going to proc3.15.03
# HISTORY:
#
# VERSION: 0.0
#
##############################################################################
use Subs::Sub;
@ISA = ("Subs::Sub");
use strict;
sub new {
my $proto=shift;
my $self=$proto->SUPER::new();
$self->{DESCRIPTION}="Make XRT GRB PHAS Correction in PC mode";
return $self;
}
##################
# METHODS:
##################
sub body {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
#########################
# make xrt phas correction
#########################
$self->make_xrt_phas_corr();
} # end of body method
###################################################################
# make xrt phas correction
###################################################################
sub make_xrt_phas_corr {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
###############################################################
# check if input event files exist and are only in PC mode
###############################################################
my @unfiltered_xpcw = $filename->get('unfiltered', 'x', 'pcw*', '*');
my @xrtcal_xpcw = $filename->get('xrtcal', 'x', 'pcw*','*' );
my @infile = ( @unfiltered_xpcw, @xrtcal_xpcw );
my @outfile = ();
foreach my $in (@infile){
push(@outfile,"$in.out");
}
if(not @infile){
$log->error(1, "no input files for xrtphascorr");
return ;
}
$log->entry("Run xrtphascorr input=@infile out=@outfile");
###########################################
# run xrtphascorr
###########################################
my $xrtphascorr=Util::HEAdas->new("xrtphascorr");
my ($in,$out);
foreach $in (@infile){
$out = "$in.out";
$xrtphascorr->params({
infile => $in,
outfile => $out,
phasconffile => 'CALDB',
clobber => 'no',
history => 'yes',
chatter => 2
});
$xrtphascorr->run();
if( $xrtphascorr->had_error() ){
if(-f "$out"){
$log->entry("Remove $out file");
unlink "$out";
}
} else {
unlink $in;
rename $out, $in;
}
} #for
} #end of make_xrt_phas_corr method