Files
sf-op/script/Alignment/Gun_solenoid_alignment.py
2016-07-06 10:46:20 +02:00

125 lines
3.2 KiB
Python
Executable File

# Tool to align the solenoid on the gun.
# S. Bettoni, A. Gobbo, D. Voulot
# 06/06/2016
#Code ok with the GUI
# Procedure:
# switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
# change the current of the gun soleoid
# look at the centroid position (BPM or screen) downstream of the gun.
import datetime
from camtool import CamTool
#run("camtool")
if get_context().source == CommandSource.ui:
I1 = 95.0
I2 = 100.0
dI = 1.0
settling_time = 0.1
plot_image = False
number_images = 1
use_background = True
multiple_background = True
number_backgrounds = 5
zero_solenoids=False
do_elog = False
centroid_excursion_plot = True
else:
centroid_excursion_plot = False
LASER_SETTLING_TIME = 0.1
print "Parameters: ", I1, I2, dI, settling_time, plot_image, number_images, use_background, multiple_background, number_backgrounds
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
add_device(CamTool("camtool") , True)
camtool.enableBackground (use_background)
if use_background and not multiple_background:
laser_off()
camtool.captureBackground(number_backgrounds)
multiple_background = multiple_background and use_background
com_x =camtool.com_x
com_y = camtool.com_y
def ccr(mag):
n = 1
while n > 0:
sleep(0.5)
n = caget(mag + ":I-COMP")
def laser_on():
print "Laser On"
#caput("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", 0)
time.sleep(LASER_SETTLING_TIME)
def laser_off():
print "Laser Off"
#caput("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", 1)
time.sleep(LASER_SETTLING_TIME)
# Switch off magnets
mag = [ "SINEG01-MCRX120","SINEG01-MCRY120",
"SINEG01-MQUA140",
"SINEG01-MQUA150",
"SINEG01-MCRX160","SINEG01-MCRY160",
"SINEG01-MCRX180","SINEG01-MCRY180",
"SINEG01-MCRX200","SINEG01-MCRY200",
"SINEG01-MCRX220","SINEG01-MCRY220",
"SINEG01-MQUA310",
"SINEG01-MQUA320" ]
if zero_solenoids:
for m in mag:
caput(m + ":I-SET", 0.0)
for m in mag:
ccr(m)
# add here gun phase setting see wiki page
def br():
if multiple_background:
camtool.captureBackground(number_backgrounds)
laser_on()
camtool.update()
def ar():
if multiple_background:
laser_off()
r = None
if not multiple_background:
laser_on()
try:
sensors = [com_x, com_y, camtool.image] if plot_image else [com_x, com_y]
r = lscan(gun_solenoid, sensors , I1, I2, dI, settling_time, before_read = br, after_read = ar)
finally:
laser_off()
# take the result of the scan and generate convex hull plot
if centroid_excursion_plot:
(hx,hy)=add_convex_hull_plot ("Centroid excursion", r.getReadable(0),r.getReadable(1), plot_name)
else:
(hx,hy)= convex_hull(x=r.getReadable(0), y=r.getReadable(1))
hx.append(hx[0]); hy.append(hy[0])
# save the entry in the logbook
if do_elog:
msg = str(r)
msg = msg + "\nFile: " + get_context().path
msg = msg + "\n\n" + r.print()
elog("Gun solenoid current scan", msg , get_plot_snapshots())
set_return([r, hx,hy])