-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalign_sepdip.madx
185 lines (164 loc) · 4.9 KB
/
align_sepdip.madx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
align_elem(RREF,EELEM,SSHIFT): macro={
stest=table(survey,EELEM,s);
value,stest;
if ( stest > 1e-9 ) {
ttt=table(survey,RREF,theta); ctt=cos(ttt);stt=sin(ttt);
xvz=stt; xvx=-ctt; zvz=ctt; zvx=stt; ! x and s directions
zzz=table(survey,EELEM,z)-table(survey,RREF,z);
xxx=table(survey,EELEM,x)-table(survey,RREF,x);
dx_EELEM=zzz*xvz+xxx*xvx;
sx_EELEM=zzz*zvz+xxx*zvx;
value,dx_EELEM,sx_EELEM;
if (dx_EELEM>0){
dx_EELEM=dx_EELEM-(SSHIFT/2000);
} else {
dx_EELEM=dx_EELEM+(SSHIFT/2000);
};
value,dx_EELEM;
select, flag=error, range=EELEM;
ealign, dx=dx_EELEM;
select, flag=error, clear;
};
};
align_slice(RREF,EELEM,NSLICE,SSHIFT): macro={
exec,align_elem(RREF,EELEM..NSLICE,SSHIFT);
};
align_group(RREF,EELEM,SSHIFT): macro={
align_group_n=0;
stest=1;
while(align_group_n<64 && stest>1e-9){
align_group_n=align_group_n+1;
exec,align_slice(RREF,EELEM,$align_group_n,SSHIFT);
};
};
align_mbxw_group(EELEM): macro={
value,EELEM;
exec,align_elem(IP1.L1, EELEM4l1,0);
exec,align_elem(IP1 , EELEM4r1,0);
exec,align_elem(IP5 , EELEM4l5,0);
exec,align_elem(IP5 , EELEM4r5,0);
};
align_mbxw: macro={
!!!!!! 4l1 cannot be passed in a macro
exec,align_mbxw_group(mbxw.a);
exec,align_mbxw_group(mbxw.b);
exec,align_mbxw_group(mbxw.c);
exec,align_mbxw_group(mbxw.d);
exec,align_mbxw_group(mbxw.e);
exec,align_mbxw_group(mbxw.f);
};
align_mbx15: macro={
exec,align_group(IP1.L1,mbxa.4l1,0);
exec,align_group(IP1,mbxa.4r1,0);
exec,align_group(IP5,mbxa.4l5,0);
exec,align_group(IP5,mbxa.4r5,0);
exec,align_group(IP1.L1,mbxb.4l1,0);
exec,align_group(IP1,mbxb.4r1,0);
exec,align_group(IP5,mbxb.4l5,0);
exec,align_group(IP5,mbxb.4r5,0);
exec,align_group(IP1.L1,mbxf.4l1,0);
exec,align_group(IP1,mbxf.4r1,0);
exec,align_group(IP5,mbxf.4l5,0);
exec,align_group(IP5,mbxf.4r5,0);
};
align_mbx2: macro={
exec,align_group(IP2,mbx.4l2,0);
exec,align_group(IP2,mbx.4r2,0);
};
align_mbx8: macro={
exec,align_group(IP8,mbx.4l8,0);
exec,align_group(IP8,mbx.4r8,0);
};
align_mbx28: macro={
exec,align_group(IP2,mbx.4l2,0);
exec,align_group(IP2,mbx.4r2,0);
exec,align_group(IP8,mbx.4l8,0);
exec,align_group(IP8,mbx.4r8,0);
};
align_mbtype(MBTYP,IPN): macro={
if (mylhcbeam == 1){
if (IPN==1){
exec,align_group(IP1.L1,MBTYP.4lIPN.b1,MBTYP_mech_sep);
} else {
exec,align_group(IPIPN,MBTYP.4lIPN.b1,MBTYP_mech_sep);
};
exec,align_group(IPIPIPN,MBTYP.4r2.b1,MBTYP_mech_sep);
};
if (mylhcbeam == 2 || mylhcbeam == 4){
if (IPN==1){
exec,align_group(IP1.L1,MBTYP.4lIPN.b2,MBTYP_mech_sep);
} else {
exec,align_group(IPIPN,MBTYP.4lIPN.b2,MBTYP_mech_sep);
};
exec,align_group(IPIPIPN,MBTYP.4r2.b2,MBTYP_mech_sep);
};
};
align_mbrd15(mbrd_mech_sep): macro={
if (mylhcbeam == 1){
exec,align_group(IP1.L1,mbrd.4l1.b1,mbrd_mech_sep);
exec,align_group(IP1,mbrd.4r1.b1,mbrd_mech_sep);
exec,align_group(IP5,mbrd.4l5.b1,mbrd_mech_sep);
exec,align_group(IP5,mbrd.4r5.b1,mbrd_mech_sep);
};
if (mylhcbeam == 2 || mylhcbeam == 4){
exec,align_group(IP1.L1,mbrd.4l1.b2,mbrd_mech_sep);
exec,align_group(IP1,mbrd.4r1.b2,mbrd_mech_sep);
exec,align_group(IP5,mbrd.4l5.b2,mbrd_mech_sep);
exec,align_group(IP5,mbrd.4r5.b2,mbrd_mech_sep);
};
};
align_mbrc28: macro={
if (mylhcbeam == 1){
exec,align_group(IP2,mbrc.4l2.b1,mbrc_mech_sep);
exec,align_group(IP2,mbrc.4r2.b1,mbrc_mech_sep);
exec,align_group(IP8,mbrc.4l8.b1,mbrc_mech_sep);
exec,align_group(IP8,mbrc.4r8.b1,mbrc_mech_sep);
};
if (mylhcbeam == 2 || mylhcbeam == 4){
exec,align_group(IP2,mbrc.4l2.b2,mbrc_mech_sep);
exec,align_group(IP2,mbrc.4r2.b2,mbrc_mech_sep);
exec,align_group(IP8,mbrc.4l8.b2,mbrc_mech_sep);
exec,align_group(IP8,mbrc.4r8.b2,mbrc_mech_sep);
};
};
align_mbrc15: macro={
if (mylhcbeam == 1){
exec,align_group(IP1.L1,mbrc.4l1.b1,mbrc_mech_sep);
exec,align_group(IP1,mbrc.4r1.b1,mbrc_mech_sep);
exec,align_group(IP5,mbrc.4l5.b1,mbrc_mech_sep);
exec,align_group(IP5,mbrc.4r5.b1,mbrc_mech_sep);
};
if (mylhcbeam == 2 || mylhcbeam == 4){
exec,align_group(IP1.L1,mbrc.4l1.b2,mbrc_mech_sep);
exec,align_group(IP1,mbrc.4r1.b2,mbrc_mech_sep);
exec,align_group(IP5,mbrc.4l5.b2,mbrc_mech_sep);
exec,align_group(IP5,mbrc.4r5.b2,mbrc_mech_sep);
};
};
align_mbrb: macro={
if (mylhcbeam == 1){
exec,align_group(IP4,mbrb.5l4.b1,mbrb_mech_sep);
exec,align_group(IP4,mbrb.5r4.b1,mbrb_mech_sep);
};
if (mylhcbeam == 2 || mylhcbeam == 4){
exec,align_group(IP4,mbrb.5l4.b2,mbrb_mech_sep);
exec,align_group(IP4,mbrb.5r4.b2,mbrb_mech_sep);
};
};
align_mbrs: macro={
if (mylhcbeam == 1){
exec,align_group(IP4,mbrs.5l4.b1,mbrs_mech_sep);
exec,align_group(IP4,mbrs.5r4.b1,mbrs_mech_sep);
};
if (mylhcbeam == 2 || mylhcbeam == 4){
exec,align_group(IP4,mbrs.5l4.b2,mbrs_mech_sep);
exec,align_group(IP4,mbrs.5r4.b2,mbrs_mech_sep);
};
};
print,text="Running survey for aligment calculations...";
survey;
mbrc_mech_sep=188;
mbrd_mech_sep=186;
mbrs_mech_sep=420-414;
mbrb_mech_sep=420-194;
value,mbrc_mech_sep,mbrd_mech_sep,mbrs_mech_sep,mbrb_mech_sep;