! Mult-step run with errors:
! 1. Correct chromaticity, save sextuoples
! 2. Set sextupoles to zero, add bend FSE and TILT errors, plus quad offsets, then corrector orbit
!    The sextupoles are set to zero as an illustration, since this is helpful sometimes when the sextupoles
!    are very strong.  In this case, it really doesn't matter.
! 3. Turn sextupoles back on and load previous errors/correction, add strength errors for quads and sextupoles, touch up the orbit, tunes, and chromaticities
! 4. Tracking


! Step 3

&run_setup
    lattice = "Lattice_Booster_V2.lte",
    p_central_mev = 300,
	rootname=step3
    use_beamline= Ring
!    parameters = %s.param
	output =%s.out
	magnets =  %s.mag
	centroid = %s.cen
!	sigma=%s.sig
	!default_order=1
	!concat_order=1
	wrap_around=0

&end

&run_control 
             n_steps = <seed>
			 n_passes = 4
!			 n_passes_fiducial=1
&end

&twiss_output
        matched = 1
        filename = %s.twi
		radiation_integrals = 1
        output_at_each_step = 1
&end


&error_control error_log = %s.erl &end
&error_element name=*, element_type=CSBEN*, item=FSE, amplitude=1e-3, bind=0 &end
!&error_element name=*, element_type=CSBEN*, item=DX, amplitude=1e-4, bind=0 &end
!&error_element name=*, element_type=CSBEN*, item=DY, amplitude=1e-4, bind=0 &end
&error_element name=*, element_type=CSBEN*, item=TILT, amplitude=0.25e-3, bind=0 &end
&error_element name=*, element_type=KQUAD, item=DX, amplitude=1e-4, bind=0 &end
&error_element name=*, element_type=KQUAD, item=DY, amplitude=1e-4, bind=0 &end

&correct
        mode = orbit,
        method = global
        n_iterations = 50
!        prezero_correctors = 0
!		n_xy_cycles = 100,
        correction_fraction[0] = 0.5, 0.5,
        bpm_noise[0] = 0e-6, 0e-6,
		corrector_limit[0]=0.5e-3,0.5e-3
!        correction_accuracy[0] = 1e-6, 1e-6,
        trajectory_output = "%s.orb",
        corrector_output = "%s.cor",
        statistics = "%s.scor",
        closed_orbit_iteration_fraction = 0.5,
        closed_orbit_iterations = 400,
        closed_orbit_accuracy = 1e-9,

		
&end


!&error_control error_log = %s.erl &end
!&error_element name=*, element_type=KQUAD, item=FSE, amplitude=1e-2, bind=0 &end
!&error_element name=*, element_type=KSEXT, item=FSE, amplitude=1e-2, bind=0 &end

&closed_orbit
        output = %s.clo
&end

&correction_matrix_output
        response[0] = %s.hrm, %s.vrm
        inverse[0] = %s.hirm, %s.virm
&end

&bunched_beam &end

&track &end
