From 1105a60bcb2a1646e4de9b5a05760aba171e6205 Mon Sep 17 00:00:00 2001
From: Claudio Scafuri <claudio.scafuri@elettra.eu>
Date: Tue, 21 Jan 2025 17:20:40 +0100
Subject: [PATCH] added

---
 elettra2track.py | 47 +++++++++++++++++++++++++++++
 shiftrotate.py   | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
 create mode 100755 elettra2track.py
 create mode 100755 shiftrotate.py

diff --git a/elettra2track.py b/elettra2track.py
new file mode 100755
index 0000000..7353035
--- /dev/null
+++ b/elettra2track.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python3
+import os
+import at
+import matplotlib.pylab as mp
+import numpy as np
+lattfile = "~/src/gitlab/dt/machine/lattice/elettra2/srElettra2_9_4_beta.mat"
+#lattfile = "~/src/gitlab/dt/machine/lattice/elettra2/srElettra2_9_4_beta_test_digital_twins.mat"
+#lattfile = "~/esrf_visit/last.mat"
+lattfile = os.path.expanduser(lattfile)
+ring=at.load_lattice(lattfile, energy=2.4e9)
+
+
+refpts = range(len(ring) + 1)
+ring.radiation_off()
+
+elemdata0, ringdata,elemdata=at.linopt6(ring,refpts,0.00)
+[chromH,chromV]=ring.get_chrom()
+[tuneH,tuneV] = ring.get_tune()
+s_pos = elemdata['s_pos']
+#--- lionop needs radiation off
+ring.radiation_on()
+ring.rf_voltage=2e6
+#elemdata0, tune, chrom, elemdata=at.linopt(ring,refpts)
+incoord = np.array([0.0001,0.00, 0.0002, 0.0, 0.0,0.0])
+mrefpts=[3]
+nt = 10000
+coord = at.lattice_pass(ring,incoord,nt,mrefpts)
+
+h_traj=coord[0, 0, :, :] # get X
+v_traj=coord[3, 0, :, :] # get Y
+
+plotbase = (np.array([np.arange(0,nt)]))
+mp.figure()
+mp.plot(plotbase,h_traj,'.')
+mp.xlabel('n')
+mp.ylabel('x')
+mp.title('traj_x' )
+mp.figure()
+mp.plot(plotbase,v_traj,'.')
+mp.xlabel('n')
+mp.ylabel('y')
+mp.title('traj_y' )
+
+mp.xlabel('s [m]')
+mp.ylabel('m')
+mp.title('traj_x' )
+mp.show()
diff --git a/shiftrotate.py b/shiftrotate.py
new file mode 100755
index 0000000..4bb6551
--- /dev/null
+++ b/shiftrotate.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python3
+
+import at
+import math
+
+#--------- test shift ---------------
+
+#function for extracting shift elemnts that is alignemnt errors
+
+
+
+def get_elem_shift(elem):
+	#if thre is no T1 and T2????
+	dx2=elem.T2[0]
+	dy2=elem.T2[2] 
+	dx1=elem.T1[0]
+	dy1=elem.T1[2]
+	
+	#check coherency
+	if dx1+dx2 != 0.0 or dy1+dy2 !=0.0:
+		print(elem.FamName,"incoherent T1 and T2 vectors")
+	return dx2,dy2
+
+	
+QF = at.Quadrupole('QF:', 1.0, 0.2) #create a Quadrupole
+
+dx=0.1 # horizontal shift [m] positive to the left
+dy=0.2 # vertical shift [m] positive up
+at.shift_elem(QF,dx,dy,relative=False) #use absolute shift
+# now check T1 and T2 matrices
+
+t1=QF.T1
+t2=QF.T2
+
+print ("T1", t1)
+print("T2", t2)
+
+print(t1[0],t1[2])
+
+print(t2[0],t2[2])
+
+a,b=get_elem_shift(QF)
+print("dx",a,"dy",b)
+QF.T1[2]*=0.00001
+a2,b2=get_elem_shift(QF)
+print("dx",a2,"dy",b2)
+at.shift_elem(QF,0.0,0.0,relative=False)
+
+a3,b3=get_elem_shift(QF)
+
+#----------- test rotations -------------------------
+
+
+print("rotations")
+SD = at.Sextupole('SD', 1.0, 0.2) #create a Quadrupole
+at.shift_elem(SD,0,0)
+a,b=get_elem_shift(SD)
+#print("dx",a,"dy",b)
+tilt = math.asin(0.01)  # rotation around s-axis
+pitch = math.asin(0.02) # rotation around x-axis
+yaw = math.asin(0.03)   # rotation around y-axis
+at.rotate_elem(SD,tilt,pitch,yaw,relative=False)
+a2,b2=get_elem_shift(SD)
+print("dx",a2,"dy",b2)
+
+
+
+# ALAERT: rotations modify also T1 and T2 that is shift! Where is the rotation centre???? NOT CLEAR
+
+
+
+
+
+
+
+
+
-- 
GitLab