!**********************************************************************
! Uncorrected orbit
!**********************************************************************

&run_setup
        lattice = run1.new,
	rootname =  run2
	use_beamline = rmatrix
	magnets = %s.mag
	sigma = %s.sig
	centroid = %s.cen
!	default_order = 2
!	concat_order = 1
!     	random_number_seed = 2019365748
!     	correction_iterations = 1
     	p_central = 195.7
!        always_change_p0 = 1
!      	tracking_updates = 1
!      	final = %s.fin
      	parameters = %s.param
&end

&alter_elements
	name = ACC*
	item = PHASE_REFERENCE
	verbose = 1
	value = 0.0
&end

&run_control   &end


&twiss_output
	filename="%s.twi"
	matched = 0                                              
	beta_x=19,beta_y=19,alpha_x=0.,alpha_y=0.               
	statistics = 1
        output_at_each_step = 1
&end

!**********************************************    ERRORS    *****************************************************

&error_control
	clear_error_settings = 1,
	error_log = %s_stat.erl
&end


&error_element name=*MXY*,item = dx,type="gaussian",additive = 1,amplitude = 40e-6 &end, cutoff=2
&error_element name=*MXY*,item = dy,type="gaussian",additive = 1,amplitude = 40e-6 &end, cutoff=2
&error_element name=*MXY*,item = dxp,type="gaussian",additive = 1,amplitude = 5e-6 &end, cutoff=2
&error_element name=*MXY*,item = dyp,type="gaussian",additive = 1,amplitude = 5e-6 &end, cutoff=2

!&error_element element_type=*CSRCSBEN*,item = angle,type="gaussian",fractional = 1,amplitude = 1e-4 &end, cutoff=3
!&error_element element_type=*CSRCSBEN*,item = dz,type="gaussian",additive = 1,amplitude = 150e-6   &end, cutoff=3
!&error_element element_type=*CSRCSBEN*,item = dx,type="gaussian",additive = 1,amplitude = 150e-6 &end, cutoff=3
!&error_element element_type=*CSRCSBEN*,item = dy,type="gaussian",additive = 1,amplitude = 150e-6 &end, cutoff=3
!&error_element element_type=*CSRCSBEN*,item = etilt,type="gaussian",additive = 1,amplitude = 0.5e-3   &end, cutoff=3

!&error_element element_type=*QUAD*,item = k1,type="gaussian",fractional = 1,amplitude = 1e-4 &end, cutoff=3
!&error_element element_type=*QUAD*,item = dz,type="gaussian",additive = 1,amplitude = 215e-6 &end, cutoff=3
!&error_element element_type=*QUAD*,item = dx,type="gaussian",additive = 1,amplitude = 150e-6 &end, cutoff=3
!&error_element element_type=*QUAD*,item = dy,type="gaussian",additive = 1,amplitude = 150e-6 &end, cutoff=3
!&error_element element_type=*QUAD*,item = tilt,type="gaussian",additive = 1,amplitude = 0.5e-3 &end, cutoff=3

!&error_element element_type=*RFCA*,item = dx,type="gaussian",additive = 1,amplitude = 300e-6, bind=0 &end, cutoff=3
!&error_element element_type=*RFCA*,item = dy,type="gaussian",additive = 1,amplitude = 300e-6, bind=0 &end, cutoff=3

!&error_element element_type=*MONI*,item = dx,type="gaussian",additive = 1,amplitude = 150e-6 &end, cutoff=3
!&error_element element_type=*MONI*,item = dy,type="gaussian",additive = 1,amplitude = 150e-6 &end, cutoff=3
&error_element element_type=*MONI*,item = dx,type="plus_or_minus",additive = 1,amplitude = 0.0 &end, cutoff=3
&error_element element_type=*MONI*,item = dy,type="plus_or_minus",additive = 1,amplitude = 0.0 &end, cutoff=3


&error_control
	summarize_error_settings = 1,
&end


&correct
	   trajectory_output="%s.traj"
	   corrector_output = "%s.cor"
	   statistics=%s.scor
	   verbose=2
	   mode="trajectory"                 !!!!! here starts commands to manipulate the elegant correction
	   method="global"   !!!"one-to-one"
	   corrector_tweek[0]=1e-3,1e-3
	   corrector_limit[0]=1.5e-3,1.5e-3
	   n_xy_cycles = 1
	   n_iterations = 1
          bpm_noise_distribution[0] = "gaussian","gaussian"
	   bpm_noise[0] = 5e-6, 5e-6
          bpm_noise_cutoff[0] = 3,3
	   remove_smallest_SVs[0]=0.9,0.9   !!!!! here starts commands to manipulate the IRM
	   minimum_SV_ratio[0]=0.2,0.2
	   auto_limit_SVs[0]=0
	   keep_largest_SVs[0]=20
&end

&correction_matrix_output
	  response[0]=%s.hrm,%s.vrm
	  inverse[0]=%s.hirm, %s.virm
	  output_at_each_step=0
&end



!&matrix_output
!SDDS_output = hirm,
!SDDS_output_order = 1
!&end



&bunched_beam   &end

&track  &end 

&save_lattice filename = %s.new 
	output_seq = 1
&end

&stop &end






