# Linear Optics Calibration in a Storage Ring Based on Machine Learning
## 2 Materials and Methods  
### Theory of Linear Optics Calibration  
#### 2.1.1 Classical Theory  
If the linear optics of a storage ring are known, its orbit response matrix can be easily obtained for either a model or a real machine. LOCO is an inverse procedure. The linear optics in the storage ring are calibrated by the orbit response matrix. The beta functions, magnetic gradients, BPM gains and coupling, and corrector gains and coupling of the real storage ring are accurately reproduced by minimizing the difference between the model and the measured response matrix. In this way, calibration errors are found, and optical functions are corrected. [PERSON] first proposed the LOCO method to correct the optical parameters of the NSLS VUV ring and ALS storage ring in the 1990s [20]. Since then, LOCO has been used at many accelerators worldwide to control accelerator optics during machine development and to maintain optimal conditions for standard machine operation. In 2002, [PERSON] and [PERSON] ported LOCO to MATLAB with a graphical user interface to facilitate data analysis [21]. In recent years, LOCO has become a powerful tool for optical corrections of storage ring optics in modern light sources around the world [22]. In SSRF, MATLAB-based LOCO is also used for optical corrections [23]. There are 138 BPM in the storage ring of the SSRF, and each BPM measures one track position. Therefore, we can define a vector \(\Delta\mathbf{u}\) to represent the closed orbit distortion with the unit of meter and the dimension of 138, \(\Delta\mathbf{u}=(u_{1},u_{2},\cdots,u_{m},\cdots,u_{138})^{T}\) where \(u\) represents the closed orbit distortion in the horizontal or vertical direction at the BPM. Then, we define a vector \(\mathbf{\Theta}\) to represent the strength change in the correctors with the unit of radian and the dimension 80, \(\mathbf{\Theta}=(\theta_{1},\theta_{2},\cdots,\theta_{n},\cdots,\theta_{80})^{T}\), where \(\theta\) represents the strength change in the correctors in the horizontal or vertical direction. The relationship between closed orbit distortion and the strength change in the correctors is given by \(\Delta\mathbf{u}=\mathbf{R}\mathbf{\Theta}\), where \(\mathbf{R}\) is an orbit response matrix with 138 rows and 80 columns. In practice, the orbit response matrix is often obtained by experiment rather than calculated from the formula. The difference between the model and the measured response matrix is given by \(\Delta\mathbf{R}=\mathbf{R}_{model}-\mathbf{R}_{meas}\), where \(\mathbf{R}_{model}\) is the model matrix and \(\mathbf{R}_{meas}\) is the measurement matrix. \(\Delta\mathbf{R}\) is sensitive to BPM gains and their coupling in the \(x\) and \(y\) plane, corrector gains and coupling, bending magnet rotation, quadrupole strength and rotation, sextupole transverse offset, and so on. LOCO is one such tool, based on orbit response matrix analysis, which uses the sensitivity of the orbit response matrix to these magnet errors to adjust linear optics. Its goal is to minimize \(\Delta\mathbf{R}\) by changing the above sensitive machine parameters \(\Delta\mathbf{W}\). The linear relationship between \(\Delta\mathbf{R}\) and \(\Delta\mathbf{W}\) is given by \(\Delta\mathbf{R}=-\)J\(\Delta\mathbf{W}\) where \(\mathbf{J}\) (11,040 \(\times\)\(N\)) is called the Jacobian matrix [20]. In practice, \(\Delta\mathbf{R}\) also needs to be divided by the measured rms noise levels for the BPM. Through singular value decomposition and multiple iterations, the fitting parameter \(\Delta\mathbf{W}\) that can minimize the difference between the orbit response matrix of the model and the measured matrix is obtained. Finally, the calibration model of the machine is obtained, and the linear optics are corrected. The theoretical part is described above, but there are some differences in practice at SSRF. As mentioned in the introduction, there are many magnets in the SSRF storage ring, which causes many fitting parameters.