Commit e7cc9082 authored by bliss administrator's avatar bliss administrator
Browse files

New version using XtalManager from monochromator GIT repository

parent da800a3d
......@@ -15,7 +15,7 @@ from bliss.shell.standard import umv, umvr, mv, plotselect
from bliss.config.settings import ParametersWardrobe
from id19.mono.monochromator import MonochromatorBase
from monochromator.monochromator import XtalManager
from enum import Enum
......@@ -25,20 +25,16 @@ class MonoMode(Enum):
LL50 = 2
LL24 = 3
OUT = 4
MM = 5
MM50 = 5
class Id19Mono(MonochromatorBase):
class Id19Mono():
def __init__(self, name, config):
# init logging
self.name = name
global_map.register(self, tag=self.name)
log_info(self,"__init__() entering")
# Initialise the MonchramatorBase class
super().__init__(name, config)
self.config = config
self.X2_safe_position = self.config["X2_safe_position"]
......@@ -52,6 +48,7 @@ class Id19Mono(MonochromatorBase):
self.diode_pos = self.config["diode_pos"]
self.diode_cnt = self.config["diode_cnt"]
self.beam_shutter = self.config["beam_shutter"]
self.frontend = self.config["frontend"]
# modes
......@@ -86,7 +83,9 @@ class Id19Mono(MonochromatorBase):
self._mode = self.parameters.mode
self._energy = self.parameters.energy
self.set_crystal(self.parameters.xtal_name)
self.mono_xtals = self.config["xtals"]
self.mono_xtals.xtal_sel = self.parameters.xtal_name
#
# mode handling
......@@ -124,8 +123,19 @@ class Id19Mono(MonochromatorBase):
self.Z1, mono_mode["Z1_pos"],
self.Z2, (mono_mode["beam_offset"]+ mono_mode["Z1_pos"]))
# choose the correct xtal for the mode
if req_mode == MonoMode.MM50:
self.parameters.xtal_name = 'W_B4C'
else:
self.parameters.xtal_name = 'Si111'
self.mono_xtals.xtal_sel = self.parameters.xtal_name
print (f"Set xtal to {self.mono_xtals.xtal_sel}")
print ("Move diode in")
self.diode_pos.IN()
if req_mode == MonoMode.LL24:
self.diode_pos.IN24()
else:
self.diode_pos.IN50()
self._mode = req_mode
......@@ -217,7 +227,7 @@ class Id19Mono(MonochromatorBase):
if self.is_aprox(theta_angle, 0 , 0.01):
print ("Theta angle < 0.01, cannot calculte energy!")
else:
energy = self.bragg2energy(theta_angle)
energy = self.mono_xtals.bragg2energy(theta_angle)
print ("\nEnergy from theta angle: %g keV" % energy)
print ("Last applied energy : %g kev \n" % self.parameters.energy)
......@@ -249,8 +259,8 @@ class Id19Mono(MonochromatorBase):
if self._mode == MonoMode.UNDEFINED or self._mode == MonoMode.OUT:
raise RuntimeError("No operation mode applied. The monochromator is not pre-positioned")
if self._mode == MonoMode.MM:
raise RuntimeError("The multilayer mode is not yet implemented")
#if self._mode == MonoMode.MM50:
# raise RuntimeError("The multilayer mode is not yet implemented")
# check energy range
e_min = self.modes[self._mode]['min_energy']
......@@ -264,7 +274,7 @@ class Id19Mono(MonochromatorBase):
# Towers distance (X2_pos) is calculated from theorical angle (in
# degrees) depending on energy.
# NB : angle_to_distance() needs to know the beam_offset to calculate distance.
theta_angle = self.energy2bragg(energy)
theta_angle = self.mono_xtals.energy2bragg(energy)
X2_pos = self.angle_to_distance(theta_angle)
# calculate theta angles
......@@ -272,9 +282,9 @@ class Id19Mono(MonochromatorBase):
THY1_pos = theta_angle + self.laue_THY1_offset
THY2_pos = theta_angle + self.laue_THY2_offset
else:
if self._mode == MonoMode.BB50:
THY1_pos = theta_angle
THY2_pos = theta_angle
#if self._mode == MonoMode.BB50:
THY1_pos = theta_angle
THY2_pos = theta_angle
# check beam size
self.check_beam_size(theta_angle)
......@@ -363,20 +373,7 @@ class Id19Mono(MonochromatorBase):
X2_pos = self.X2_safe_position
else:
X2_pos = X2_calc
# Check the current positions, and the calculated positions,
# do we need to move the crystals to 0?
#if self.is_aprox(self.X2.position, self.X2_safe_position, 0.01) and X2_pos >= self.X2_safe_position:
#crystals_to_be_moved = False
#else:
#if self.is_aprox(self.THY1.position, 0 , 0.01) and self.is_aprox(self.THY2.position, 0 , 0.01):
#crystals_to_be_moved = False
#else:
#if relative == True:
#crystals_to_be_moved = False
# print calculated positions
print("\n---------------------------------------------------------")
print("mono mode : %s " % self.modes[self.parameters.mode]["description"])
......@@ -400,12 +397,6 @@ class Id19Mono(MonochromatorBase):
print ("Close beam shutter")
self.beam_shutter.close()
# move crystals to 0 when necessary
#if crystals_to_be_moved == True:
#umv(self.THY1, 0.0,
#self.THY2, 0.0)
#self._energy = 0
# For security move Y2 to the middle and move it back after the X2 movement
# Only do this if X2 > 330 !!!!!!!!
move_y2 = False
......@@ -502,7 +493,7 @@ class Id19Mono(MonochromatorBase):
theta_angle = self.get_theta()
old_e = self.bragg2energy(theta_angle) * 1000 # conversion to eV
old_e = self.mono_xtals.bragg2energy(theta_angle) * 1000 # conversion to eV
new_e = (old_e + delta_energy) / 1000 # in keV
print ("Old energy = %g \t new energy = %g" % ((old_e/1000), new_e) )
......@@ -513,11 +504,17 @@ class Id19Mono(MonochromatorBase):
#
def tune(self):
ct_diode = 0.01
# Crystal 1 rocking curve: (almost paul t1 with resolution 0.0002 deg)
# Crystal 1 rocking curve:
plotselect (self.diode_cnt)
dscan (self.THY1, -0.05, 0.05, 500, ct_diode, save=False)
#dscan (self.THY1, -0.06, 0.01, 500, ct_diode, save=False) #Bragg scan
#dscan (self.THY1, -0.01, 0.06, 500, ct_diode, save=False) #Laue50 scan
if self._mode == MonoMode.BB50:
dscan (self.THY1, -0.06, 0.01, 500, ct_diode, save=False) #Bragg scan
else:
if self._mode == MonoMode.LL50:
dscan (self.THY1, -0.01, 0.06, 500, ct_diode, save=False) #Laue50 scan
else:
dscan (self.THY1, -0.05, 0.05, 500, ct_diode, save=False) #default
goto_peak()
time.sleep(2)
......@@ -531,7 +528,6 @@ class Id19Mono(MonochromatorBase):
umvr (self.THY1, 0.0003)
time.sleep(2)
#ct(1)
def angle_to_distance(self, angle):
......@@ -565,6 +561,7 @@ class Id19Mono(MonochromatorBase):
def remove(self):
# close FE
print ("Close FrontEnd")
self.frontend.close()
# remove diode
print ("Remove diode")
......@@ -612,21 +609,6 @@ class Id19Mono(MonochromatorBase):
if self.X2.position < self.X2_safe_position:
umv(self.X2, self.X2_safe_position + 10) # with a little margin
#
# calculate Si111 fixed exit double crystal mono parameters with
# <angle> in deg
#
#def angle_to_energy(self, angle):
#return(self.get_calculated_dspacing() / math.sin(math.radians(angle)))
#def energy_to_angle(self, energy):
#return(math.degrees(math.asin(self.get_calculated_dspacing() / energy)))
#def get_calculated_dspacing(self):
#hc_over_e = 12.398420
#return 1/(2*3.1356/hc_over_e)
def get_theta (self):
if self._mode == MonoMode.LL50 or self._mode == MonoMode.LL24:
......@@ -643,7 +625,7 @@ class Id19Mono(MonochromatorBase):
@property
def energy(self):
return self.bragg2energy(self.get_theta())
return self.mono_xtals.bragg2energy(self.get_theta())
@property
def lamda(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment