!particle is proton

&change_particle
	name = proton
&end


&run_setup
        lattice="transport.lte",    
        use_beamline="Transport",
        default_order = 3,
        sigma="%s.sig",
        output="%s.out",
        magnets="%s.mag"
        centroid="%s.cen",
	acceptance="%s.acc",
	final="%s.fin",
        rootname = run-100,
        p_central_mev = 100,
&end


&run_control
&end

&optimization_setup
	tolerance = 1e-14,
	target = 1e-10,
	method = "simplex",
	mode = "minimize",
	n_passes = 3,
	n_restarts = 10,
	n_evaluations = 1500,
	verbose = 1
&end

!!! Want equal beam sizes in both planes
&optimization_term
	term = "M1#1.Sx M1#1.Sy 1e-5 sene"
&end

!!! Want minimum average beam size
&optimization_term
	term = "M1#1.Sy M1#1.Sx + 1e3 * 2 /" 
&end

&optimization_variable
        name = Q1, item = K1, lower_limit=-100, upper_limit=100, step_size=0.1 
&end
&optimization_variable
        name = Q2, item = K1, lower_limit=-100, upper_limit=100, step_size=0.1
&end

&twiss_output
	filename="%s.twi",
        matched = 0,
	beta_x = 0.2,
	alpha_x = 0.20412,
	beta_y = 0.23308,
	alpha_y = 0.10050,
	concat_order = 1,
        output_at_each_step = 1,
	statistics = 1
&end

&bunched_beam
 	bunch                    = %s.bun,
        n_particles_per_bunch    = 1000,
	!!! Corrected these expressions using proper syntax "(<expression>)", "pi" instead of "Pi"
	emit_x                   = "(17.1611e-6 pi /)", 
        emit_y                   = "(20.9923e-6 pi /)",
	beta_x			 = 0.2,
	alpha_x			 = 0.20412
	beta_y			 = 0.23308
	alpha_y			 = 0.10050
        sigma_dp                 = 0.00596,
        sigma_s                  = 0,
        distribution_type[0]     = "gaussian",
        distribution_type[1]     = "gaussian",
        distribution_type[2]     = "gaussian",
        distribution_cutoff[0]   = 3.0,
        distribution_cutoff[1]   = 3.0,
        distribution_cutoff[2]   = 3.0,
        symmetrize               = 1,
        enforce_rms_values[0]    = 1,
        enforce_rms_values[1]    = 1,
        enforce_rms_values[2]    = 1,   
&end

&optimize &end



