[3] | 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 printlatt(const char fic[]); |
---|
| 59 | |
---|
| 60 | void PrintMat(long n, Vector *A); |
---|
| 61 | |
---|
| 62 | void PrintVec(long n, double *X); |
---|
| 63 | |
---|
| 64 | void recalc_S(); |
---|
| 65 | |
---|
| 66 | double Circumference(void); |
---|
| 67 | |
---|
| 68 | void GetMean(long n, double *x); |
---|
| 69 | |
---|
| 70 | bool getcod(double dP, long &lastpos); |
---|
| 71 | |
---|
| 72 | void get_twiss3(long int loc, |
---|
| 73 | Vector2 alpha[], Vector2 beta[], Vector2 nu[], |
---|
| 74 | Vector2 eta[], Vector2 etap[]); |
---|
| 75 | |
---|
| 76 | void getabn(double *alpha, double *beta, double *nu); |
---|
| 77 | |
---|
| 78 | void TraceABN(long i0, long i1, const Vector2 &alpha, const Vector2 &beta, |
---|
| 79 | const Vector2 &eta, const Vector2 &etap, const double dP); |
---|
| 80 | |
---|
| 81 | void ttwiss(const Vector2 &alpha, const Vector2 &beta, |
---|
| 82 | const Vector2 &eta, const Vector2 &etap, const double dP); |
---|
| 83 | |
---|
| 84 | void prt_sigma(void); |
---|
| 85 | |
---|
| 86 | /* 2 parameter fitting routines */ |
---|
| 87 | void FitTune(long qf, long qd, double nux, double nuy); |
---|
| 88 | |
---|
| 89 | void FitChrom(long sf, long sd, double ksix, double ksiy); |
---|
| 90 | |
---|
| 91 | void FitDisp(long q, long pos, double eta); |
---|
| 92 | |
---|
| 93 | void inibump(long coh, long cov); |
---|
| 94 | |
---|
| 95 | void getfloqs(Vector &x); |
---|
| 96 | |
---|
| 97 | void track(const char* file_name, |
---|
| 98 | double ic1, double ic2, double ic3, double ic4, double dp, |
---|
| 99 | long int nmax, long int &lastn, long int &lastpos, int floqs, |
---|
| 100 | double f_rf); |
---|
| 101 | |
---|
| 102 | struct LOC_getdynap { |
---|
| 103 | double phi, delta; |
---|
| 104 | long nturn; |
---|
| 105 | bool floqs, lost; |
---|
| 106 | } ; |
---|
| 107 | |
---|
| 108 | void track_(double r, struct LOC_getdynap *LINK); |
---|
| 109 | |
---|
| 110 | void getdynap(double &r, double phi, double delta, double eps, |
---|
| 111 | int nturn, bool floqs); |
---|
| 112 | |
---|
| 113 | void getcsAscr(void); |
---|
| 114 | |
---|
| 115 | void dynap(FILE *fp, double r, const double delta, |
---|
| 116 | const double eps, const int npoint, const int nturn, |
---|
| 117 | double x[], double y[], const bool floqs, const bool print); |
---|
| 118 | |
---|
| 119 | double get_aper(int n, double x[], double y[]); |
---|
| 120 | |
---|
| 121 | void GetTrack(const char *file_name, |
---|
| 122 | long *n, double *x, double *px, double *y, double *py); |
---|
| 123 | |
---|
| 124 | void Getj(long n, double *x, double *px, double *y, double *py); |
---|
| 125 | |
---|
| 126 | double Fract(double x); |
---|
| 127 | |
---|
| 128 | double GetArg(double x, double px, double nu); |
---|
| 129 | |
---|
| 130 | void GetPhi(long n, double *x, double *px, double *y, double *py); |
---|
| 131 | |
---|
| 132 | void Sinfft(int n, double *xr); |
---|
| 133 | |
---|
| 134 | void sin_FFT(int n, double xr[]); |
---|
| 135 | |
---|
| 136 | void sin_FFT(int n, double xr[], double xi[]); |
---|
| 137 | |
---|
| 138 | void GetInd(int n, int k, int *ind1, int *ind3); |
---|
| 139 | |
---|
| 140 | void GetInd1(int n, int k, int *ind1, int *ind3); |
---|
| 141 | |
---|
| 142 | void GetPeak(int n, double *x, int *k); |
---|
| 143 | |
---|
| 144 | void GetPeak1(int n, double *x, int *k); |
---|
| 145 | |
---|
| 146 | double Int2snu(int n, double *x, int k); |
---|
| 147 | |
---|
| 148 | double Sinc(double omega); |
---|
| 149 | |
---|
| 150 | double intsampl(int n, double *x, double nu, int k); |
---|
| 151 | |
---|
| 152 | double linint(int n, int k, double nu, double *x); |
---|
| 153 | |
---|
| 154 | struct LOC_findres { |
---|
| 155 | int n; |
---|
| 156 | double nux, nuy, f; |
---|
| 157 | int *nx, *ny; |
---|
| 158 | double eps; |
---|
| 159 | bool found; |
---|
| 160 | } ; |
---|
| 161 | |
---|
| 162 | void FndRes(struct LOC_findres *LINK); |
---|
| 163 | |
---|
| 164 | void FindRes(int n_, double nux_, double nuy_, double f_, |
---|
| 165 | int *nx_, int *ny_); |
---|
| 166 | |
---|
| 167 | void GetPeaks(int n, double *x, int nf, double *nu, double *A); |
---|
| 168 | |
---|
| 169 | void GetPeaks1(int n, double *x, int nf, double *nu, double *A); |
---|
| 170 | |
---|
| 171 | void SetTol(int Fnum, double dxrms, double dyrms, double drrms); |
---|
| 172 | |
---|
| 173 | void Scale_Tol(int Fnum, double dxrms, double dyrms, double drrms); |
---|
| 174 | |
---|
| 175 | void SetaTol(int Fnum, int Knum, double dx, double dy, double dr); |
---|
| 176 | |
---|
| 177 | void ini_aper(const double Dxmin, const double Dxmax, |
---|
| 178 | const double Dymin, const double Dymax); |
---|
| 179 | |
---|
| 180 | void set_aper(const int Fnum, const double Dxmin, const double Dxmax, |
---|
| 181 | const double Dymin, const double Dymax); |
---|
| 182 | |
---|
| 183 | void LoadApertures(const char *ChamberFileName); |
---|
| 184 | |
---|
| 185 | void LoadTolerances(const char *TolFileName); |
---|
| 186 | |
---|
| 187 | void ScaleTolerances(const char *TolFileName, const double scl); |
---|
| 188 | |
---|
| 189 | void SetKpar(int Fnum, int Knum, int Order, double k); |
---|
| 190 | |
---|
| 191 | void SetdKpar(int Fnum, int Knum, int Order, double k); |
---|
| 192 | |
---|
| 193 | void SetL(int Fnum, int Knum, double L); |
---|
| 194 | |
---|
| 195 | void SetL(int Fnum, double L); |
---|
| 196 | |
---|
| 197 | void SetKLpar(int Fnum, int Knum, int Order, double kL); |
---|
| 198 | |
---|
| 199 | void SetdKLpar(int Fnum, int Knum, int Order, double dkL); |
---|
| 200 | |
---|
| 201 | void SetdKrpar(int Fnum, int Knum, int Order, double dkrel); |
---|
| 202 | |
---|
| 203 | void Setbn(int Fnum, int order, double bn); |
---|
| 204 | |
---|
| 205 | void SetbnL(int Fnum, int order, double bnL); |
---|
| 206 | |
---|
| 207 | void Setdbn(int Fnum, int order, double dbn); |
---|
| 208 | |
---|
| 209 | void SetdbnL(int Fnum, int order, double dbnL); |
---|
| 210 | |
---|
| 211 | void Setbnr(int Fnum, int order, double bnr); |
---|
| 212 | |
---|
| 213 | void SetbnL_sys(int Fnum, int Order, double bnL_sys); |
---|
| 214 | |
---|
| 215 | void set_dbn_rel(const int type, const int n, const double dbn_rel); |
---|
| 216 | |
---|
| 217 | double GetKpar(int Fnum, int Knum, int Order); |
---|
| 218 | |
---|
| 219 | double GetL(int Fnum, int Knum); |
---|
| 220 | |
---|
| 221 | double GetKLpar(int Fnum, int Knum, int Order); |
---|
| 222 | |
---|
| 223 | void SetdKLsys(int Fnum, int Order, double dkLsys); |
---|
| 224 | |
---|
| 225 | void SetdKLrms(int Fnum, int Order, double dkLrms); |
---|
| 226 | |
---|
| 227 | void Setdkrrms(int Fnum, int Order, double dkrrms); |
---|
| 228 | |
---|
| 229 | void SetKL(int Fnum, int Order); |
---|
| 230 | |
---|
| 231 | void set_dx(const int type, const double sigma_x, const double sigma_y); |
---|
| 232 | |
---|
| 233 | void SetBpmdS(int Fnum, double dxrms, double dyrms); |
---|
| 234 | |
---|
| 235 | void codstat(double *mean, double *sigma, double *xmax, long lastpos, |
---|
| 236 | bool all); |
---|
| 237 | |
---|
| 238 | void CodStatBpm(double *mean, double *sigma, double *xmax, long lastpos, |
---|
| 239 | long bpmdis[mnp]); |
---|
| 240 | |
---|
| 241 | double Sgn (double x); |
---|
| 242 | |
---|
| 243 | double digitize(double x, double maxkick, double maxsamp); |
---|
| 244 | |
---|
| 245 | //svdarray xmemo[2]; |
---|
| 246 | |
---|
| 247 | double digitize2(long plane, long inum, double x, double maxkick, |
---|
| 248 | double maxsamp); |
---|
| 249 | |
---|
| 250 | void Dis_In(long *bpmdis, long *vcorrdis, long *hcorrdis, |
---|
| 251 | long *wvdis, long *whdis); |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | /* high level functions for reading lattice file*/ |
---|
| 255 | //void Read_Lattice(char *fic); |
---|
| 256 | //long get_bpm_number(void); |
---|
| 257 | //long get_hcorr_number(void); |
---|
| 258 | //long get_vcorr_number(void); |
---|
| 259 | //long get_qt_number(void); |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | /* tracking */ |
---|
| 263 | void GetChromTrac(long Nb, long Nbtour, double emax, double *xix, double *xiz); |
---|
| 264 | void GetTuneTrac(long Nbtour, double emax, double *nux, double *nuz); |
---|
| 265 | void Trac(double x, double px, double y, double py, double dp, double ctau, |
---|
| 266 | long nmax, long pos, long &lastn, long &lastpos, FILE *outf1); |
---|
| 267 | |
---|
| 268 | /* close orbit */ |
---|
| 269 | // simple precision |
---|
| 270 | void findcodS(double dP); |
---|
| 271 | void computeFandJS(double *x, int n, double **fjac, double *fvect); |
---|
| 272 | void Newton_RaphsonS(int ntrial, double x[], int n, double tolx); |
---|
| 273 | // double precision |
---|
| 274 | void findcod(double dP); |
---|
| 275 | void computeFandJ(int n, double *x, Vector *fjac, double *fvect); |
---|
| 276 | int Newton_Raphson(int n, Vector &x, int ntrial, double tolx); |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | /* Transport mode routine */ |
---|
| 280 | void TransTwiss(Vector2 &alpha, Vector2 &beta, Vector2 &eta, Vector2 &etap, |
---|
| 281 | Vector &codvect); |
---|
| 282 | |
---|
| 283 | /* Vacuum chamber */ |
---|
| 284 | void PrintCh(void); |
---|
| 285 | |
---|