!========================
!= MATCHING FOR GENESIS =
!========================

!======================
!= Undulator matching =
!======================

! Run setup for undulator matching
!==================================
&run_setup
	lattice = dba.lte
	default_order = 3
	use_beamline = DBA11
	p_central_mev = 2530
&end

&run_control n_steps = 1 
&end



! Setup of the optimization settings
!====================================
&optimization_setup
        n_evaluations = 1000
        n_passes = 100
        n_restarts = 10
        target = 1e-3
        tolerance = 1e-3
		include_simplex_1d_scans = 1
&end


!===================================================================
!2pi unit 


&optimization_term
 term = "M1#2.nux M1#1.nux - abs 0.5 - sqr ", weight=1.0
&end

&optimization_term
 term = "M1#2.nuy M1#1.nuy - abs 0.5 - sqr ", weight=1.0
&end




! Setup of the used correctors
!==============================

! First set: The two quads in the modulator section
!====================================================

&optimization_variable
        name = Q1, item = K1, lower_limit = -50, upper_limit = 50, step_size = 1e-5
&end

&optimization_variable
        name = Q2, item = K1, lower_limit = -50, upper_limit = 50, step_size = 1e-5
&end

&optimization_variable
        name = Q3, item = K1, lower_limit = -50, upper_limit = 50, step_size = 1e-5
&end

&optimization_variable
        name = Q4, item = K1, lower_limit = -50, upper_limit = 50, step_size = 1e-5
&end

&optimization_variable
        name = Q5, item = K1, lower_limit = -50, upper_limit = 50, step_size = 1e-5
&end

&optimization_variable
        name = Q6, item = K1, lower_limit = -50, upper_limit = 50, step_size = 1e-5
&end

&optimization_variable
        name = D1, item = L, lower_limit = 0, upper_limit = 50, step_size = 1e-3
&end

 
! Beam setup
!============
! Elegant needs a one-particle-bunch for optimization...
!========================================================
&bunched_beam
	n_particles_per_bunch =  1
&end

! Execution of optimization
!===========================
&optimize 
	summarize_setup = 1
&end

! Save the new lattice for later
!================================
&save_lattice  
    filename = ALL_Matched.lte 
&end 








