aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-04-16 15:15:25 +0200
committerThomas White <taw@physics.org>2015-04-20 15:50:40 +0200
commitcd62de314513feac7c98f6e01123507b7138e922 (patch)
tree190786ff8d555a0d594b41e7f9cfcb6a3dfde0d8 /scripts
parentad25f6413156d53baa367a6ae0d5287f0a6c1e90 (diff)
Improve and fix scripts/detector-shift
Because of a bug in the regexp, it did not apply the shifts to all panels.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/detector-shift147
-rwxr-xr-xscripts/plot-detector-shift15
2 files changed, 77 insertions, 85 deletions
diff --git a/scripts/detector-shift b/scripts/detector-shift
index 77634f83..5a39d8a4 100755
--- a/scripts/detector-shift
+++ b/scripts/detector-shift
@@ -13,6 +13,7 @@
import sys
import os
import re
+import matplotlib.pyplot as plt
f = open(sys.argv[1], 'r')
if len(sys.argv) > 2:
@@ -22,11 +23,9 @@ else:
have_geom = 0
# Determine the mean shifts
-total_x = 0
-total_y = 0
-total_z = 0
-n_xy = 0
-n_z = 0
+x_shifts = []
+y_shifts = []
+z_shifts = []
prog1 = re.compile("^predict_refine/det_shift\sx\s=\s([0-9\.\-]+)\sy\s=\s([0-9\.\-]+)\smm$")
prog2 = re.compile("^predict_refine/clen_shift\s=\s([0-9\.\-]+)\smm$")
@@ -41,78 +40,86 @@ while True:
if match:
xshift = float(match.group(1))
yshift = float(match.group(2))
- total_x += xshift
- total_y += yshift
- n_xy += 1
+ x_shifts.append(xshift)
+ y_shifts.append(yshift)
match = prog2.match(fline)
if match:
zshift = float(match.group(1))
- total_z += xshift
- n_z += 1
+ z_shifts.append(zshift)
-if n_xy != n_z:
- print 'Warning: number of xy shifts not equal to number of z shifts'
-
-mean_x = total_x / n_xy
-mean_y = total_y / n_xy
-mean_z = total_z / n_z
-
-print 'Mean shifts: dx = %.2f mm, dy = %.2f mm; dz = %.2f mm' % (mean_x,mean_y,mean_z)
f.close()
-if not have_geom:
- exit(0)
-
-# Apply shifts to geometry
-out = os.path.splitext(geom)[0]+'-predrefine.geom'
-print 'Applying corrections to %s, output filename %s' % (geom,out)
-g = open(geom, 'r')
-h = open(out, 'w')
-
-prog1 = re.compile("^\s*res\s+=\s+([0-9\.]+)\s")
-prog2 = re.compile("^\s*(.*)\/res\s+=\s+([0-9\.]+)\s")
-prog3 = re.compile("^\s*(.*)\/corner_x\s+=\s+([0-9\.]+)\s")
-prog4 = re.compile("^\s*(.*)\/corner_y\s+=\s+([0-9\.]+)\s")
-default_res = 0
-while True:
-
- fline = g.readline()
- if not fline:
- break
-
- match = prog1.match(fline)
- if match:
- default_res = float(match.group(1))
- print 'default res %f' % (default_res)
- h.write(fline)
- continue
-
- match = prog2.match(fline)
- if match:
- panel = match.group(1)
- panel_res = float(match.group(2))
- print 'panel res %s / %f' % (panel, panel_res)
- h.write(fline)
- continue
+if len(x_shifts) != len(z_shifts):
+ print 'Warning: number of xy shifts not equal to number of z shifts'
- match = prog3.match(fline)
- if match:
- panel = match.group(1)
- panel_cnx = float(match.group(2))
- res = default_res # FIXME!
- h.write('%s/corner_x = %f\n' % (panel,panel_cnx+(mean_x*res*1e-3)))
- continue
+mean_x = sum(x_shifts) / len(x_shifts)
+mean_y = sum(y_shifts) / len(y_shifts)
+mean_z = sum(z_shifts) / len(z_shifts)
+print 'Mean shifts: dx = %.2f mm, dy = %.2f mm; dz = %.2f mm' \
+ % (mean_x,mean_y,mean_z)
- match = prog4.match(fline)
- if match:
- panel = match.group(1)
- panel_cny = float(match.group(2))
- res = default_res # FIXME!
- h.write('%s/corner_y = %f\n' % (panel,panel_cny+(mean_y*res*1e-3)))
- continue
-
- h.write(fline)
+# Apply shifts to geometry
+if have_geom:
+
+ out = os.path.splitext(geom)[0]+'-predrefine.geom'
+ print 'Applying corrections to %s, output filename %s' % (geom,out)
+ g = open(geom, 'r')
+ h = open(out, 'w')
+
+ prog1 = re.compile("^\s*res\s+=\s+([0-9\.]+)\s")
+ prog2 = re.compile("^\s*(.*)\/res\s+=\s+([0-9\.]+)\s")
+ prog3 = re.compile("^\s*(.*)\/corner_x\s+=\s+([0-9\.\-]+)\s")
+ prog4 = re.compile("^\s*(.*)\/corner_y\s+=\s+([0-9\.\-]+)\s")
+ default_res = 0
+ while True:
+
+ fline = g.readline()
+ if not fline:
+ break
+
+ match = prog1.match(fline)
+ if match:
+ default_res = float(match.group(1))
+ print 'default res %f' % (default_res)
+ h.write(fline)
+ continue
+
+ match = prog2.match(fline)
+ if match:
+ panel = match.group(1)
+ panel_res = float(match.group(2))
+ print 'panel res %s / %f' % (panel, panel_res)
+ h.write(fline)
+ continue
+
+ match = prog3.match(fline)
+ if match:
+ panel = match.group(1)
+ panel_cnx = float(match.group(2))
+ res = default_res # FIXME!
+ h.write('%s/corner_x = %f\n' % (panel,panel_cnx+(mean_x*res*1e-3)))
+ continue
+
+ match = prog4.match(fline)
+ if match:
+ panel = match.group(1)
+ panel_cny = float(match.group(2))
+ res = default_res # FIXME!
+ h.write('%s/corner_y = %f\n' % (panel,panel_cny+(mean_y*res*1e-3)))
+ continue
+
+ h.write(fline)
+
+ g.close()
+ h.close()
+
+plt.plot(x_shifts, y_shifts, 'rx')
+plt.plot(0, 0, 'bo')
+plt.axis([-2,2,-2,2])
+plt.title('Detector shifts according to prediction refinement')
+plt.xlabel('x shift / mm')
+plt.ylabel('y shift / mm')
+plt.grid(True)
+plt.show()
-g.close()
-h.close()
diff --git a/scripts/plot-detector-shift b/scripts/plot-detector-shift
deleted file mode 100755
index a456b18c..00000000
--- a/scripts/plot-detector-shift
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-INFILE=$1
-
-grep "predict_refine/det_shift" $INFILE > plotme.dat
-echo "0 0" > plotme2.dat
-gnuplot -persist << EOF
-set xlabel "x shift / mm"
-set ylabel "y shift / mm"
-set size square
-set grid
-plot [-2:2] [-2:2] "plotme.dat" using 4:7 title "Detector shifts"
-replot "plotme2.dat" using 1:2 w p ps 4 pt 6 title "0,0"
-EOF
-rm -f plotme.dat plotme2.dat