package Subs::NFILightCurves;
##############################################################################
#
# DESCRIPTION: This subroutine runs extracts light curves from event data
#
# HISTORY:
# HISTORY: $Log: NFILightCurves.pm,v $
# HISTORY: Revision 1.5 2004/05/06 20:02:34 dah
# HISTORY: Add version number back into the header comments.
# HISTORY:
# HISTORY: Revision 1.4 2004/04/16 20:21:18 dah
# HISTORY: Begin using embedded history records
# HISTORY:
#
# VERSION: 0.0
#
#
##############################################################################
use Subs::LightCurves;
@ISA = ("Subs::LightCurves");
use strict;
sub new {
my $proto=shift;
my $self=$proto->SUPER::new();
$self->{DESCRIPTION}="Extracting and plotting NFI light curves";
return $self;
}
##################
# METHODS:
##################
#############################################################################
#
#############################################################################
sub extract_lightcurves {
my $self=shift;
my $log =$self->log();
my $filename=$self->filename();
my $procpar =$self->procpar();
my $jobpar =$self->jobpar();
$log->entry("Extracting NFI light curves from event data");
###########################
# fire up the extractor
###########################
my $extractor = Util::Extractor->new();
$extractor->verbose(2);
################################################
# get the mean number of counts we should have
# in each lightcurve bin
################################################
my $counts_per_bin = $procpar->read("meanperlcbin");
########################################
# loop over instruments
########################################
my $inst;
for $inst ("xrt", "uvot") {
$log->entry("Extracting $inst light curves");
################################################
# determine the modes we should look at
################################################
my @modes=();
if($inst eq "xrt") { @modes=('pc*', 'lr*', 'wt*') }
########################
# loop over modes
########################
my $mode;
foreach $mode (@modes) {
$log->entry("Mode $mode");
$extractor->instrument($inst, $mode);
######################################
# get the input and output file names
######################################
my $curve = $filename->get("lightcurve", $inst, $mode, 001);
unlink $curve;
my @evts = $filename->get("event", $inst, $mode, "*");
unless(@evts) {
$log->entry("No event files");
next;
}
my $list = Util::EventFileList->new(@evts);
$log->entry("Extracting $curve from @evts");
###################################
# calculate the bin size
###################################
my $nevents = $list->nevents();
my $exposure = $list->sum_keywords("ONTIME");
my $binsize= $exposure/$nevents * $counts_per_bin;
$log->entry("nevents=$nevents exposure=$exposure s ".
"bin size $binsize s");
##############################
# run the extractor
##############################
$extractor->infiles(@evts)
->bin_size($binsize, 0.5)
->outfile($curve, "lightcurve");
################################################
# this is a cludge since XRT bright mode files
# currently lack TLMAX for PHA/PI 2002-10-22
# This code should be removed when the problem
# is fixed.
################################################
my $phamax = $extractor->{PARAMS}->{phamax};
my $fits = Util::FITSfile->new($extractor->{SAMPLE_INPUT},
"EVENTS");
unless(defined $fits->keyword($phamax)) {
$log->error(1, "Event file does not have $phamax keyword");
$log->entry("Setting $phamax to 4096");
foreach (@evts) {
Util::FITSfile->new($_, "EVENTS")
->keyword($phamax, 4096);
}
}
$extractor->run();
} # end of loop over modes
} # end of loop over instruments
} # end of extract_lightcurves method
#############################################################################
#
#############################################################################
sub list_lightcurves {
my $self = shift;
my $filename = $self->filename();
return ($filename->get("lightcurve", "x", "*", "*"),
$filename->get("lightcurve", "u", "*", "*") );
}