Index: /trunk/tools/eam/teleff/camstats.sh
===================================================================
--- /trunk/tools/eam/teleff/camstats.sh	(revision 41721)
+++ /trunk/tools/eam/teleff/camstats.sh	(revision 41722)
@@ -83,7 +83,7 @@
 
   # allow mag and pos histograms to have different bin sizes?
-  histogram dRs NdRs -0.5 0.5 $HISTBIN -range dx
-  histogram dDs NdDs -0.5 0.5 $HISTBIN -range dx
-  histogram dMs NdMs -0.5 0.5 $HISTBIN -range dx
+  histogram dRs NdRs {-50*$HISTBIN} {50*$HISTBIN} $HISTBIN -range dx
+  histogram dDs NdDs {-50*$HISTBIN} {50*$HISTBIN} $HISTBIN -range dx
+  histogram dMs NdMs {-50*$HISTBIN} {50*$HISTBIN} $HISTBIN -range dx
 
   NdRs[0] = 0; NdRs[-1] = 0
@@ -93,17 +93,17 @@
   $C3 = 0.0
 
-  peak -q dx NdRs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 3*$HISTBIN; vgauss dx NdRs con NdRf
-  peak -q dx NdDs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 3*$HISTBIN; vgauss dx NdDs con NdDf
-  peak -q dx NdMs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 3*$HISTBIN; vgauss dx NdMs con NdMf
-
-  section aM; lim 13 23 -0.5 0.5; box $BST1
+  peak -q dx NdRs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 2*$HISTBIN; vgauss dx NdRs con NdRf; $SigmaRA  = abs($C1)
+  peak -q dx NdDs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 2*$HISTBIN; vgauss dx NdDs con NdDf; $SigmaDec = abs($C1)
+  peak -q dx NdMs; $C0 = $peakpos; $C2 = $peaknum; $C1 = 2*$HISTBIN; vgauss dx NdMs con NdMf; $SigmaMag = abs($C1)
+
+  section aM; lim 13 23 {-50*$HISTBIN} {50*$HISTBIN}; box $BST1
   plot CAL_PSF_MAG dM -pt box -sz 0.5 -op 0.2 where keepGood
   label -x mag -y "&sd&h mag"
   
-  section aR; lim 13 23 -0.5 0.5; box $BST1
+  section aR; lim 13 23 {-50*$HISTBIN} {50*$HISTBIN}; box $BST1
   plot CAL_PSF_MAG dR -pt box -sz 0.5 -op 0.2 where keepGood
   label -x mag -y "&sd&h R.A."
   
-  section aD; lim 13 23 -0.5 0.5; box $BST1
+  section aD; lim 13 23 {-50*$HISTBIN} {50*$HISTBIN}; box $BST1
   plot CAL_PSF_MAG dD -pt box -sz 0.5 -op 0.2 where keepGood
   label -x mag -y "&sd&h Dec"
@@ -113,4 +113,5 @@
   plot dx NdMf -x line -c red -lw 2
   label -x "&sd&h mag" +y "N (15 < mag < 17)"
+  sprintf line "&ss&h (mag) = %.0f mmag" {1000*$SigmaMag}; textline -frac 0.02 0.95 -justify 5 "$line"
   
   section bR; lim dx NdRs; box $BST2
@@ -118,4 +119,5 @@
   plot dx NdRf -x line -c red -lw 2
   label -x "&sd&h R.A" +y "N (15 < mag < 17)"
+  sprintf line "&ss&h (mag) = %.0f mas" {1000*$SigmaRA}; textline -frac 0.02 0.95 -justify 5 "$line"
   
   section bD; lim dx NdDs; box $BST2
@@ -123,4 +125,5 @@
   plot dx NdDf -x line -c red -lw 2
   label -x "&sd&h Dec" +y "N (15 < mag < 17)"
+  sprintf line "&ss&h (Dec) = %.0f mas" {1000*$SigmaDec}; textline -frac 0.02 0.95 -justify 5 "$line"
 end
 
@@ -153,19 +156,23 @@
  lim magBin -0.02 1.02; box $BSTY -ticks 1110;
 
+ plot -x hist magBin fracPoss  -lw 3 -c blue70
  plot -x hist magBin fracFound -lw 3 -c red70
- plot -x hist magBin fracPoss  -lw 3 -c blue70
  plot -x hist magBin fracGood  -lw 3 -c red
 
- subset tmp = fracGood  where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightGood  = $MEDIAN
  subset tmp = fracPoss  where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightPoss  = $MEDIAN
  subset tmp = fracFound where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightFound = $MEDIAN
-
- line -c red  -lt dot -lw 2 100 $FracBrightGood to 0 $FracBrightGood
- line -c blue -lt dot -lw 2 100 $FracBrightPoss to 0 $FracBrightPoss
+ subset tmp = fracGood  where (magBin > 15) && (magBin < 20); vstat -q tmp; $FracBrightGood  = $MEDIAN
+
+ line -c blue70 -lt dot -lw 2 100 $FracBrightPoss  to 0 $FracBrightPoss
+ line -c red70  -lt dot -lw 2 100 $FracBrightFound to 0 $FracBrightFound
+ line -c red    -lt dot -lw 2 100 $FracBrightGood  to 0 $FracBrightGood
 
  fprintf "%.1f-pct of all bright sources were detected unmasked" {100*$FracBrightGood} 
  fprintf "%.1f-pct of unmasked bright sources were found" {100*$FracBrightFound / $FracBrightPoss}
  fprintf "%.1f-pct of unmasked bright sources were detected unmasked" {100*$FracBrightGood / $FracBrightPoss}
+
  fprintf "mag limit %.1f" $MagLim
+ sprintf line "mag limit: %.1f" $MagLim
+ textline -frac 0.95 0.95 -justify 3 "$line"
 
  label -x mag -y "detected fraction"
@@ -181,14 +188,42 @@
  label +y "detected number"
 
+ vstat -q numTotal; $Ntotal = $TOTAL
  vstat -q numFound; $Nfound = $TOTAL
  vstat -q numGood;  $Ngood  = $TOTAL
  
- fprintf "%d total sources detected, %d unmasked" $Nfound $Ngood
-
- $Xlegend = 0.02; $dXlegend = 0.03
- $Ylegend = 0.95; $dYlegend = 0.02
- line -frac $Xlegend $Ylegend to {$Xlegend + $dXlegend} $Ylegend -c blue  -lw 3; textline -frac -justify 5 {$Xlegend + $dXlegend + 0.01} $Ylegend "unmasked source positions (psfqf > 0.85)"; $Ylegend -= $dYlegend
- line -frac $Xlegend $Ylegend to {$Xlegend + $dXlegend} $Ylegend -c red70 -lw 3; textline -frac -justify 5 {$Xlegend + $dXlegend + 0.01} $Ylegend "all sources detected"                    ; $Ylegend -= $dYlegend
- line -frac $Xlegend $Ylegend to {$Xlegend + $dXlegend} $Ylegend -c red   -lw 3; textline -frac -justify 5 {$Xlegend + $dXlegend + 0.01} $Ylegend "sources detected with psfqf > 0.85"
+ fprintf "%d of %d total sources detected, %d unmasked" $Nfound $Ntotal $Ngood
+
+ legend.init 0.02 0.95 0.03 0.02
+ sprintf line "unmasked source positions (psfqf > 0.85) [%.1f pct]" {100*$FracBrightPoss};  legend.line blue  3 solid "$line"
+ sprintf line "all sources detected [%.1f pct]"                     {100*$FracBrightFound}; legend.line red70 3 solid "$line"
+ sprintf line "sources detected with psfqf > 0.85 [%.1f pct]"	    {100*$FracBrightGood};  legend.line red   3 solid "$line"
+end
+
+macro legend.init
+ if ($0 != 5)
+  echo "USAGE: legend.init (X) (Y) (dX) (dY)"
+  break
+ end
+ 
+ $legend:X = $1; $legend:dX = $3
+ $legend:Y = $2; $legend:dY = $4
+end
+
+macro legend.line
+ if ($0 != 5)
+  echo "USAGE: legend.init (color) (lweight) (ltype) (label)"
+  break
+ end
+
+ local color myline mylt mylw
+ 
+ $color  = $1
+ $mylt   = $2
+ $mylw   = $3
+ $myline = $4
+
+ line -frac $legend:X $legend:Y to {$legend:X + $legend:dX} $legend:Y -c $color -lw $mylw -lt $mylt
+ textline -frac -justify 5 {$legend:X + $legend:dX + 0.01} $legend:Y "$myline"
+ $legend:Y -= $legend:dY
 end
 
