#! /bin/sh # This is the LHEA perl script: /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/hxtlcurv # 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/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/hxtlcurv." 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/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/hxtlcurv." 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! #------------------------------------------------------------------------------- #!/usr1/local/bin/perl5 $rcsId = '$Id: hxtlcurv,v 3.8 2013/01/24 21:41:30 irby Exp $x' ; print "\nhxtlcurv> using perl v. $]\n" ; # # This script produces deadtime-corrected, background-subtracted # HEXTE light curves. # # Richard Bentley, UCSD/CASS, rbentley@mamacass.ucsd.edu # D. Gruber 12/97 - changed from hxtdeadlc to more modern hxtdead # D. Gruber 2/98 - added -p option (do pha) # D. Gruber 2/98 - added -g option (apply external GTI or file to extractor) # D. Gruber 10/98 - abandoned independent background estimates. Using finterp. # D. Gruber 12/98 - added selection for columns in archive data, fixed bug # in background estimation for short (<8s) time bins. # D. Gruber 2/99 - force full energy range for all pha accumulations # D. Gruber 2/99 - allow detector subset for live-time correction # D. Gruber 9/99 - change -v reporting from rcs Id to a hard-wired number use Getopt::Std; #============================================================# # # See if there are any flags: # getopts('i:k:r:b:g:t:l:u:c:d:e:phv'); if (defined $opt_v) { # rcs version string # chop($rcsId) ; # print "hxtlcurv> rcs version string $rcsId\n" ; print "hxtlcurv> version 4.0\n" ; exit() ; } if (defined $opt_h) { # help flag print < Input file provided was: $opt_i\n" ; $infile = $opt_i ; } else #otherwise get user input or whatever was used last by fselect { @infile2=&runcom('pget fselect infile'); chop($infile2[0]); print "hxtlcurv> Enter HEXTE FITS file:[$infile2[0]]"; ($infile = ); if($infile =~ /^./){ # if file name starts with any character . . . chop($infile);} # get rid of newline else{ # user didn't enter a name, so use the one from fselect $infile = $infile2[0]; } } # # See if the input file is event list. # $keyword = "DATAMODE" ; @resultf=&runcom('fkeyprint infile="'.$infile.'" keynam="'.$keyword.'" exact=yes'); @temp_array = grep(/^DATAMODE= /,@resultf) ; # get the right line @temp = split (/\s+/,$temp_array[0]); # split into 'words' $datamode = $temp[1] ; # this should be the datamode string print "hxtlcurv> DATAMODE: $datamode\n" ; # # Check for valid rates file: # if (defined $opt_r) { print "hxtlcurv> rates file provided was: $opt_r\n" ; $engvalf = $opt_r ; } else #otherwise get user input or whatever was used last by hxtdead { @engvalftmp=&runcom('pget hxtdead engvalf'); chop($engvalftmp[0]); print "hxtlcurv> Enter HEXTE rates file:[$engvalftmp[0]]"; ($engvalf = ); if($engvalf =~ /^./){ # if file name starts with any character . . . chop($engvalf);} # get rid of newline else{ # user didn't enter a name, so use the one from hxtdead $engvalf = $engvalftmp[0]; } } # # Check for coefficients file: # if (defined $opt_k) { print "hxtlcurv> coefficients file provided was: $opt_k\n" ; $calvalf = $opt_k ; } else #otherwise get user input or whatever was used last by hxtdead { @calvalftmp=&runcom('pget hxtdead calvalf'); chop($calvalftmp[0]); print "hxtlcurv> Enter HEXTE coefficients file:[$calvalftmp[0]]"; ($calvalf = ); if($calvalf =~ /^./){ # if file name starts with any character . . . chop($calvalf);} # get rid of newline else{ # user didn't enter a name, so use the one from hxtdead $calvalf = $calvalftmp[0]; } } # # chatter level for hxtdead # $chatter = 5; if(defined $opt_c) { $chatter = $opt_c;} # subset for dead time correction $detset = "0123"; if(defined $opt_e) { $detset = $opt_e;} print "hxtlcurv> dead time set: $detset \n" ; # # Check for valid bin period argument: # if (defined $opt_b) # if user-specified bin period { print "hxtlcurv> bin size specified was: $opt_b sec\n" ; $binsz = $opt_b ; } else # dwell not specified, so set to default value of 16s { $binsz = 16 ; print "hxtlcurv> dwell period set to default value of 16s\n" ; } if ($binsz > 16 ) { print "hxtlcurv>\007 ERROR - Bin size $binsz invalid. Must be 16 or less\n" ; exit() ; } # # make source- and bkg-selected files, if needed # ($nzif = $infile) =~ s/\.gz// ; #get file name w/o directory ($datf = $nzif) =~ s#.*/## ; #get file name w/o directory $srcf = $datf . "_src" ; $bkgf = $datf . "_bkg" ; if ( ! -e $srcf || ! -e $bkgf ) { # if either src or bkg missing, run hxtback to make them # @args = ("hxtback", "-i", "$infile", "-b") ; @args = ("hxtback -i $infile -b") ; printf "hxtlcurv> running %s\n", "@args" ; $rc = 0xffff & system @args ; print "hxtlcurv> done running hxtback\n" ; } # (big section for jammed files has been deleted) $srcfext = $srcf ; $bkgfext = $bkgf ; # run the extract programs # First, check for a GTI file: if (defined $opt_g) { $extgti = $opt_g ; } else { $extgti='-' ; } print "hxtlcurv> extgti: $extgti\n" ; # Next, check for a timeint file: if (defined $opt_t) { $timeint = '@'.$opt_t ; } else { $timeint='INDEF' ; } print "hxtlcurv> timeint: $timeint\n" ; # # check for lower and upper energy limits: # if (defined $opt_l) { $chmin = $opt_l ; } else { $chmin='INDEF' ; } print "hxtlcurv> chmin: $chmin\n" ; if (defined $opt_u) { $chmax = $opt_u ; } else { $chmax='INDEF' ; } print "hxtlcurv> chmax: $chmax\n" ; if (defined $opt_p) { if ( $chmin == 'INDEF' && $chmax == 'INDEF' ) { $extract = 'ONCE'; $prmode = 'BOTH' ; } else { $extract = 'TWICE'; $prmode = 'LIGHTCURVE'; } } else { $prmode = 'LIGHTCURVE' ; $extract = 'ONCE'; } print "hxtlcurv> prmode: $prmode\n" ; print "hxtlcurv> extract: $extract\n" ; # # run s{a,e}extrct: # # # See if the file contains event data # print "hxtlcurv> run fkeyprint to get HDUCLAS1\n" ; @temp = &runcom('fkeyprint infile="'.$infile.'"+1 keynam=HDUCLAS1 | grep HDUCLAS1=') ; #print "hxtlcurv> temp: $temp[0]\n" ; @tokens = split /\s+'/, $temp[0] ; $dtype = $tokens[1] ; print "hxtlcurv> dtype: $dtype\n" ; #$binsz = 2 * $dwell ; if ($dtype eq 'EVENTS') { @args = ("seextrct infile=$srcfext outroot = $srcfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME columns=Event binsz=$binsz timeint=$timeint chmin=$chmin chmax=$chmax printmode=$prmode lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running seextrct on source\n" ; } else { printf "hxtlcurv> seextrct unsuccessful; status 0x%#04x\n", $rc ; } if ( $extract eq 'TWICE' ) { @args = ("seextrct infile=$srcfext outroot = $srcfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME columns=Event binsz=$binsz timeint=$timeint chmin=INDEF chmax=INDEF printmode=SPECTRUM lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running seextrct on src spectrum\n" ; } else { printf "hxtlcurv> seextrct unsuccessful; status 0x%#04x\n", $rc ; } } @args = ("seextrct infile=$bkgfext outroot = $bkgfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME columns=Event binsz=16.0 timeint=$timeint chmin=$chmin chmax=$chmax printmode=$prmode lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running seextrct on background\n" ; } else { printf "hxtlcurv> seextrct unsuccessful; status 0x%#04x\n", $rc ; } if ( $extract eq 'TWICE' ) { @args = ("seextrct infile=$bkgfext outroot = $bkgfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME columns=Event binsz=16.0 timeint=$timeint chmin=INDEF chmax=INDEF printmode=SPECTRUM lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running seextrct on bkg spectrum\n" ; } else { printf "hxtlcurv> seextrct unsuccessful; status 0x%#04x\n", $rc ; } } } elsif ( $dtype eq "ARRAY" ) { # # column list for archive data files # if (defined $opt_d) { $col_list = $opt_d ; } else { $col_list = "SpecDet0 SpecDet1 SpecDet2 SpecDet3" ; } print "hxtlcurv> Columns: $col_list\n" ; # @args = ("saextrct infile=$bkgfext outroot = $bkgfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME accumulate=ONE columns=\'$col_list\' binsz=16. timeint=$timeint chmin=$chmin chmax=$chmax printmode=$prmode lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running saextrct on background\n" ; } else { printf "hxtlcurv> saextrct unsuccessful; status 0x%#04x\n", $rc ; } if ( $extract eq 'TWICE' ) { @args = ("saextrct infile=$bkgfext outroot = $bkgfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME accumulate=ONE columns=\'$col_list\' binsz=16. timeint=$timeint chmin=INDEF chmax=INDEF printmode=SPECTRUM lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running saextrct on bkg spectrum\n" ; } else { printf "hxtlcurv> saextrct unsuccessful; status 0x%#04x\n", $rc ; } } @args = ("saextrct infile=$srcfext outroot = $srcfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME accumulate=ONE columns=\'$col_list\' binsz=$binsz timeint=$timeint chmin=$chmin chmax=$chmax printmode=$prmode lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running saextrct on source\n" ; } else { printf "hxtlcurv> saextrct unsuccessful; status 0x%#04x\n", $rc ; } if ( $extract eq 'TWICE' ) { @args = ("saextrct infile=$srcfext outroot = $srcfext gtiorfile=APPLY gtiandfile=$extgti timecol=TIME accumulate=ONE columns=\'$col_list\' binsz=16. timeint=$timeint chmin=INDEF chmax=INDEF printmode=SPECTRUM lcmode=RATE spmode=SUM timemin=INDEF timemax=INDEF chint=INDEF chbin=INDEF") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running saextrct on src spectrum\n" ; } else { printf "hxtlcurv> saextrct unsuccessful; status 0x%#04x\n", $rc ; } } } else { print "hxtlcurv> HDUCLAS1 keyword has value $dtype, neither EVENTS nor ARRAY. stopping\n" ; } # # dead-time correct # $srcfextlc = $srcfext . ".lc" ; @args = ("hxtdead $calvalf $engvalf $srcf $srcfextlc chatter=$chatter detectors=$detset") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running hxtdead on source light curve\n" ; } else { printf "hxtlcurv> hxtdead unsuccessful on lc; status 0x%#04x\n", $rc ; } if (defined $opt_p) { $srcfextpha = $srcfext . ".pha" ; @args = ("hxtdead $calvalf $engvalf $srcf $srcfextpha chatter=$chatter detectors=$detset") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running hxtdead on source pha\n" ; } else { printf "hxtlcurv> hxtdead unsuccessful; status 0x%#04x\n", $rc ; } } $bkgfextlc = $bkgfext . ".lc" ; @args = ("hxtdead $calvalf $engvalf $bkgf $bkgfextlc chatter=$chatter detectors=$detset") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running hxtdead on background\n" ; } else { printf "hxtlcurv> hxtdead unsuccessful; status 0x%#04x\n", $rc ; } if (defined $opt_p) { $bkgfextpha = $bkgfext . ".pha" ; @args = ("hxtdead $calvalf $engvalf $bkgf $bkgfextpha chatter=$chatter detectors=$detset") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) {printf "hxtlcurv> back from running hxtdead on bkg pha\n" ;} else {printf "hxtlcurv> hxtdead unsuccessful; status 0x%#04x\n", $rc ;} } # now make a bkg light curve interpolated to times of src light curve $bkg_intrplc = 'bkg_intrp.lc'; @args = ("finterp infile1=$srcfextlc+1 infile2=$bkgfextlc+1 outfile=$bkg_intrplc incol=rate order=1 extrap=REPEAT"); printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) {printf "hxtlcurv> back from running finterp on src\n" ;} else {printf "hxtlcurv> finterp unsuccessful; status 0x%#04x\n", $rc ;} # # produce the bg-subtracted light curve # $infilelc = $datf . ".lc" ; @args = ("lcmath infile=$srcfextlc bgfile=$bkg_intrplc outfile=$infilelc multi = 1.0 multb = 1.0 addsubr=no docor=no err_mode=5") ; printf "hxtlcurv> running:\n%s\n", "@args" ; $rc = 0xffff & system @args ; if ($rc == 0) { printf "hxtlcurv> back from running lcmath\n" ; } else { printf "hxtlcurv> lcmath unsuccessful; status 0x%#04x\n", $rc ; } unlink("idflist.tmp") ; #clean up after lcmath unlink($bkg_intrplc) ; #clean up after lcmath # #clean up # $srcflc = $srcf . ".lc" ; $bkgflc = $bkgf . ".lc" ; print "hxtlcurv> produced light curve files $srcflc $bkgflc and $infilelc\n" ;