aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/chandra_bkg_rescale.sh
diff options
context:
space:
mode:
authorWeitian LI <liweitianux@gmail.com>2014-06-18 22:20:59 +0800
committerWeitian LI <liweitianux@gmail.com>2014-06-18 22:20:59 +0800
commite3923265d0d6949407a83726e9a9bd5d97079221 (patch)
tree9afd8520595f4cf80815b9bccfc3dcf2879ebe47 /scripts/chandra_bkg_rescale.sh
downloadchandra-acis-analysis-e3923265d0d6949407a83726e9a9bd5d97079221.tar.bz2
Initial commit
Added files: * mass_profile: developed by Junhua GU, modified by Weitian LI * opt_utilities: developed by Junhua GU * tools/cosmo_calc: originated from 'calc_distance', modified * scripts: scripts used to process Chandra ACIS data * files: useful files used in processing * HOWTO_chandra_acis_process.txt * README.md
Diffstat (limited to 'scripts/chandra_bkg_rescale.sh')
-rwxr-xr-xscripts/chandra_bkg_rescale.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/chandra_bkg_rescale.sh b/scripts/chandra_bkg_rescale.sh
new file mode 100755
index 0000000..ae13af1
--- /dev/null
+++ b/scripts/chandra_bkg_rescale.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+#
+# background rescale, by adjusting `BACKSCAL'
+# according to the photon flux values in `9.5-12.0 keV'
+#
+# LIweitiaNux <liweitianux@gmail.com>
+# August 14, 2012
+
+## background rescale (BACKSCAL) {{{
+# rescale background according to particle background
+# energy range: 9.5-12.0 keV (channel: 651-822)
+CH_LOW=651
+CH_HI=822
+pb_flux() {
+ punlearn dmstat
+ COUNTS=`dmstat "$1[channel=${CH_LOW}:${CH_HI}][cols COUNTS]" | grep -i 'sum:' | awk '{ print $2 }'`
+ punlearn dmkeypar
+ EXPTIME=`dmkeypar $1 EXPOSURE echo=yes`
+ BACK=`dmkeypar $1 BACKSCAL echo=yes`
+ # fix `scientific notation' bug for `bc'
+ EXPTIME_B=`echo ${EXPTIME} | sed 's/[eE]/\*10\^/' | sed 's/+//'`
+ BACK_B=`echo "( ${BACK} )" | sed 's/[eE]/\*10\^/' | sed 's/+//'`
+ PB_FLUX=`echo "scale = 16; ${COUNTS} / ${EXPTIME_B} / ${BACK_B}" | bc -l`
+ echo ${PB_FLUX}
+}
+
+bkg_rescale() {
+ # $1: src spectrum, $2: back spectrum
+ PBFLUX_SRC=`pb_flux $1`
+ PBFLUX_BKG=`pb_flux $2`
+ BACK_OLD=`dmkeypar $2 BACKSCAL echo=yes`
+ BACK_OLD_B=`echo "( ${BACK_OLD} )" | sed 's/[eE]/\*10\^/' | sed 's/+//'`
+ BACK_NEW=`echo "scale = 16; ${BACK_OLD_B} * ${PBFLUX_BKG} / ${PBFLUX_SRC}" | bc -l`
+ printf "\`$2': BACKSCAL:\n"
+ printf " ${BACK_OLD} --> ${BACK_NEW}\n"
+ punlearn dmhedit
+ dmhedit infile=$2 filelist=none operation=add \
+ key=BACKSCAL value=${BACK_NEW} comment="old value: ${BACK_OLD}"
+}
+## bkg rescale }}}
+
+if [ $# -ne 2 ]; then
+ printf "usage:\n"
+ printf " `basename $0` <src_spec> <bkg_spec>\n"
+ printf "\nNOTE:\n"
+ printf "<bkg_spec> is the spectrum to be adjusted\n"
+ exit 1
+fi
+
+# perform `bkg_rescale'
+bkg_rescale "$1" "$2"
+
+exit 0
+