1 | /* Tracy-2 |
---|
2 | |
---|
3 | J. Bengtsson, CBP, LBL 1990 - 1994 Pascal version |
---|
4 | SLS, PSI 1995 - 1997 |
---|
5 | M. Boege SLS, PSI 1998 C translation |
---|
6 | L. Nadolski SOLEIL 2002 Link to NAFF, Radia field maps |
---|
7 | J. Bengtsson NSLS-II, BNL 2004 - |
---|
8 | |
---|
9 | */ |
---|
10 | |
---|
11 | #include "time.h" |
---|
12 | #include <sys/time.h> |
---|
13 | |
---|
14 | /* For tune fitting */ |
---|
15 | #define nueps 1e-6 //precision |
---|
16 | #define nudkL 0.01 //step |
---|
17 | #define nuimax 10 // maximum number of iterations |
---|
18 | |
---|
19 | /* For chromaticity fitting */ |
---|
20 | #define ksieps 1e-5 |
---|
21 | #define ksidkpL 0.01 |
---|
22 | #define ksiimax 10 |
---|
23 | |
---|
24 | /* For dispersion fitting */ |
---|
25 | #define dispeps 1e-10 |
---|
26 | #define dispdkL 0.001 |
---|
27 | #define dispimax 10 |
---|
28 | #define npeakmax 10 |
---|
29 | |
---|
30 | // Dynamical aperture |
---|
31 | #define px_0 0.0 |
---|
32 | #define py_0 0.0 |
---|
33 | |
---|
34 | /* 80% sigma coupling */ |
---|
35 | #define sigma_eps sqrt((25.0/16.0-1.0)/(25.0/16.0+1.0)) |
---|
36 | |
---|
37 | #define writetrack true /*protocol from tracking*/ |
---|
38 | |
---|
39 | // getfloq |
---|
40 | #define nfloq 4 |
---|
41 | |
---|
42 | // inibump |
---|
43 | #define dnux 0.02 |
---|
44 | #define dnuy 0.01 |
---|
45 | |
---|
46 | // TraceABN |
---|
47 | #define ntrace 4 |
---|
48 | |
---|
49 | typedef long ipeakbuf[npeakmax]; |
---|
50 | typedef double peakbuf[npeakmax]; |
---|
51 | |
---|
52 | double int_curly_H(long int n); |
---|
53 | |
---|
54 | void rm_mean(long int n, double x[]); |
---|
55 | |
---|
56 | void printglob(void); |
---|
57 | |
---|
58 | void printglob2file(const char fic[]); |
---|
59 | |
---|
60 | void printlatt(const char fic[]); |
---|
61 | |
---|
62 | void PrintMat(long n, Vector *A); |
---|
63 | |
---|
64 | void PrintVec(long n, double *X); |
---|
65 | |
---|
66 | void recalc_S(); |
---|
67 | |
---|
68 | double Circumference(void); |
---|
69 | |
---|
70 | void GetMean(long n, double *x); |
---|
71 | |
---|
72 | bool getcod(double dP, long &lastpos); |
---|
73 | |
---|
74 | void get_twiss3(long int loc, |
---|
75 | Vector2 alpha[], Vector2 beta[], Vector2 nu[], |
---|
76 | Vector2 eta[], Vector2 etap[]); |
---|
77 | |
---|
78 | void getabn(double *alpha, double *beta, double *nu); |
---|
79 | |
---|
80 | void TraceABN(long i0, long i1, const Vector2 &alpha, const Vector2 &beta, |
---|
81 | const Vector2 &eta, const Vector2 &etap, const double dP); |
---|
82 | |
---|
83 | void ttwiss(const Vector2 &alpha, const Vector2 &beta, |
---|
84 | const Vector2 &eta, const Vector2 &etap, const double dP); |
---|
85 | |
---|
86 | void prt_sigma(void); |
---|
87 | |
---|
88 | /* 2 parameter fitting routines */ |
---|
89 | void FitTune(long qf, long qd, double nux, double nuy); |
---|
90 | |
---|
91 | void FitChrom(long sf, long sd, double ksix, double ksiy); |
---|
92 | |
---|
93 | void FitDisp(long q, long pos, double eta); |
---|
94 | |
---|
95 | void inibump(long coh, long cov); |
---|
96 | |
---|
97 | void getfloqs(Vector &x); |
---|
98 | |
---|
99 | void track(const char* file_name, |
---|
100 | double ic1, double ic2, double ic3, double ic4, double dp, |
---|
101 | long int nmax, long int &lastn, long int &lastpos, int floqs, |
---|
102 | double f_rf); |
---|
103 | |
---|
104 | struct LOC_getdynap { |
---|
105 | double phi, delta; |
---|
106 | long nturn; |
---|
107 | bool floqs, lost; |
---|
108 | } ; |
---|
109 | |
---|
110 | void track_(double r, struct LOC_getdynap *LINK); |
---|
111 | |
---|
112 | void getdynap(double &r, double phi, double delta, double eps, |
---|
113 | int nturn, bool floqs); |
---|
114 | |
---|
115 | void getcsAscr(void); |
---|
116 | |
---|
117 | void dynap(FILE *fp, double r, const double delta, |
---|
118 | const double eps, const int npoint, const int nturn, |
---|
119 | double x[], double y[], const bool floqs, const bool print); |
---|
120 | |
---|
121 | double get_aper(int n, double x[], double y[]); |
---|
122 | |
---|
123 | void GetTrack(const char *file_name, |
---|
124 | long *n, double *x, double *px, double *y, double *py); |
---|
125 | |
---|
126 | void Getj(long n, double *x, double *px, double *y, double *py); |
---|
127 | |
---|
128 | double Fract(double x); |
---|
129 | |
---|
130 | double GetArg(double x, double px, double nu); |
---|
131 | |
---|
132 | void GetPhi(long n, double *x, double *px, double *y, double *py); |
---|
133 | |
---|
134 | void Sinfft(int n, double *xr); |
---|
135 | |
---|
136 | void sin_FFT(int n, double xr[]); |
---|
137 | |
---|
138 | void sin_FFT(int n, double xr[], double xi[]); |
---|
139 | |
---|
140 | void GetInd(int n, int k, int *ind1, int *ind3); |
---|
141 | |
---|
142 | void GetInd1(int n, int k, int *ind1, int *ind3); |
---|
143 | |
---|
144 | void GetPeak(int n, double *x, int *k); |
---|
145 | |
---|
146 | void GetPeak1(int n, double *x, int *k); |
---|
147 | |
---|
148 | double Int2snu(int n, double *x, int k); |
---|
149 | |
---|
150 | double Sinc(double omega); |
---|
151 | |
---|
152 | double intsampl(int n, double *x, double nu, int k); |
---|
153 | |
---|
154 | double linint(int n, int k, double nu, double *x); |
---|
155 | |
---|
156 | struct LOC_findres { |
---|
157 | int n; |
---|
158 | double nux, nuy, f; |
---|
159 | int *nx, *ny; |
---|
160 | double eps; |
---|
161 | bool found; |
---|
162 | } ; |
---|
163 | |
---|
164 | void FndRes(struct LOC_findres *LINK); |
---|
165 | |
---|
166 | void FindRes(int n_, double nux_, double nuy_, double f_, |
---|
167 | int *nx_, int *ny_); |
---|
168 | |
---|
169 | void GetPeaks(int n, double *x, int nf, double *nu, double *A); |
---|
170 | |
---|
171 | void GetPeaks1(int n, double *x, int nf, double *nu, double *A); |
---|
172 | |
---|
173 | void SetTol(int Fnum, double dxrms, double dyrms, double drrms); |
---|
174 | |
---|
175 | void Scale_Tol(int Fnum, double dxrms, double dyrms, double drrms); |
---|
176 | |
---|
177 | void SetaTol(int Fnum, int Knum, double dx, double dy, double dr); |
---|
178 | |
---|
179 | void ini_aper(const double Dxmin, const double Dxmax, |
---|
180 | const double Dymin, const double Dymax); |
---|
181 | |
---|
182 | void set_aper(const int Fnum, const double Dxmin, const double Dxmax, |
---|
183 | const double Dymin, const double Dymax); |
---|
184 | |
---|
185 | void LoadApertures(const char *ChamberFileName); |
---|
186 | |
---|
187 | void LoadTolerances(const char *TolFileName); |
---|
188 | |
---|
189 | void ScaleTolerances(const char *TolFileName, const double scl); |
---|
190 | |
---|
191 | void SetKpar(int Fnum, int Knum, int Order, double k); |
---|
192 | |
---|
193 | void SetdKpar(int Fnum, int Knum, int Order, double k); |
---|
194 | |
---|
195 | void SetL(int Fnum, int Knum, double L); |
---|
196 | |
---|
197 | void SetL(int Fnum, double L); |
---|
198 | |
---|
199 | void SetKLpar(int Fnum, int Knum, int Order, double kL); |
---|
200 | |
---|
201 | void SetdKLpar(int Fnum, int Knum, int Order, double dkL); |
---|
202 | |
---|
203 | void SetdKrpar(int Fnum, int Knum, int Order, double dkrel); |
---|
204 | |
---|
205 | void Setbn(int Fnum, int order, double bn); |
---|
206 | |
---|
207 | void SetbnL(int Fnum, int order, double bnL); |
---|
208 | |
---|
209 | void Setdbn(int Fnum, int order, double dbn); |
---|
210 | |
---|
211 | void SetdbnL(int Fnum, int order, double dbnL); |
---|
212 | |
---|
213 | void Setbnr(int Fnum, int order, double bnr); |
---|
214 | |
---|
215 | void SetbnL_sys(int Fnum, int Order, double bnL_sys); |
---|
216 | |
---|
217 | void set_dbn_rel(const int type, const int n, const double dbn_rel); |
---|
218 | |
---|
219 | double GetKpar(int Fnum, int Knum, int Order); |
---|
220 | |
---|
221 | double GetL(int Fnum, int Knum); |
---|
222 | |
---|
223 | double GetKLpar(int Fnum, int Knum, int Order); |
---|
224 | |
---|
225 | void SetdKLsys(int Fnum, int Order, double dkLsys); |
---|
226 | |
---|
227 | void SetdKLrms(int Fnum, int Order, double dkLrms); |
---|
228 | |
---|
229 | void Setdkrrms(int Fnum, int Order, double dkrrms); |
---|
230 | |
---|
231 | void SetKL(int Fnum, int Order); |
---|
232 | |
---|
233 | void set_dx(const int type, const double sigma_x, const double sigma_y); |
---|
234 | |
---|
235 | void SetBpmdS(int Fnum, double dxrms, double dyrms); |
---|
236 | |
---|
237 | void codstat(double *mean, double *sigma, double *xmax, long lastpos, |
---|
238 | bool all); |
---|
239 | |
---|
240 | void CodStatBpm(double *mean, double *sigma, double *xmax, long lastpos, |
---|
241 | long bpmdis[mnp]); |
---|
242 | |
---|
243 | double Sgn (double x); |
---|
244 | |
---|
245 | double digitize(double x, double maxkick, double maxsamp); |
---|
246 | |
---|
247 | //svdarray xmemo[2]; |
---|
248 | |
---|
249 | double digitize2(long plane, long inum, double x, double maxkick, |
---|
250 | double maxsamp); |
---|
251 | |
---|
252 | void Dis_In(long *bpmdis, long *vcorrdis, long *hcorrdis, |
---|
253 | long *wvdis, long *whdis); |
---|
254 | |
---|
255 | |
---|
256 | /* high level functions for reading lattice file*/ |
---|
257 | //void Read_Lattice(char *fic); |
---|
258 | //long get_bpm_number(void); |
---|
259 | //long get_hcorr_number(void); |
---|
260 | //long get_vcorr_number(void); |
---|
261 | //long get_qt_number(void); |
---|
262 | |
---|
263 | |
---|
264 | /* tracking */ |
---|
265 | void GetChromTrac(long Nb, long Nbtour, double emax, double *xix, double *xiz); |
---|
266 | void GetTuneTrac(long Nbtour, double emax, double *nux, double *nuz); |
---|
267 | void Trac(double x, double px, double y, double py, double dp, double ctau, |
---|
268 | long nmax, long pos, long &lastn, long &lastpos, FILE *outf1); |
---|
269 | |
---|
270 | /* close orbit */ |
---|
271 | // simple precision |
---|
272 | void findcodS(double dP); |
---|
273 | void computeFandJS(double *x, int n, double **fjac, double *fvect); |
---|
274 | void Newton_RaphsonS(int ntrial, double x[], int n, double tolx); |
---|
275 | // double precision |
---|
276 | void findcod(double dP); |
---|
277 | void computeFandJ(int n, double *x, Vector *fjac, double *fvect); |
---|
278 | int Newton_Raphson(int n, Vector &x, int ntrial, double tolx); |
---|
279 | |
---|
280 | |
---|
281 | /* Transport mode routine */ |
---|
282 | void TransTwiss(Vector2 &alpha, Vector2 &beta, Vector2 &eta, Vector2 &etap, |
---|
283 | Vector &codvect); |
---|
284 | |
---|
285 | /* Vacuum chamber */ |
---|
286 | void PrintCh(void); |
---|
287 | |
---|