

## LEGENDA
# p_central --> reference beam mean energy
# order_transport --> transport matrix order in particle coordinates
# nturns --> number of turns per run (orbit statistics, transverse acceptance, dynamic aperture, etc.)
# nsteps --> number of error seeds for orbit statistics. *** NB: THIS PARAMETER/NUMBER MUST BE SET ALSO IN THIS SCRIPT ***
# momentum_minus --> minimum fractional momentum for: working point variation with momentum; off-energy transverse acceptance; off-energy dynamic aperture 
# momentum_puls --> maximum fractional momentum for: working point variation with momentum; off-energy transverse acceptance; off-energy dynamic aperture 
# momentum_steps --> fractional momentum step for computation of the working point
# momentum_index --> number of steps for computation of the transverse acceptance
# xmin, xmax, ymin, ymax --> range of coordinates for searching transverse acceptance and dynamic aperture
# n_lines --> number of lines in the (x,y) space for search of the transverse acceptance
# nx_fma, ny_fma --> number of lines for search of the dynamic aperture
## All successive parameters are for the calculation of the Touschek lifetime


#**************************************************************************************************************
# This is an initial setting suitable for ../Lattices/2015-10-29_Elettra_6B_V0.lat (Elettra 2.0)
#**************************************************************************************************************

sddsmakedataset settings.sdds \
    \
    -parameter=nux,type=double -data=33.276 \
    -parameter=nuy,type=double -data=9.347 \
    -parameter=chromx,type=double -data=0.25 \
    -parameter=chromy,type=double -data=0.25 \
    \
    -parameter=p_central,type=double -data=3914 \
    -parameter=order_transport,type=double -data=2 \
    -parameter=nturns,type=double -data=500 \
    -parameter=nsteps,type=double -data=1 \
    \
    -parameter=momentum_minus,type=double -data=-3e-2 \
    -parameter=momentum_plus,type=double -data=3e-2 \
    -parameter=momentum_steps,type=double -data=11 \
    -parameter=momentum_index,type=double -data=3 \
    \
    -parameter=xmin,type=double -data=-0.015 \
    -parameter=xmax,type=double -data=0.015 \
    -parameter=ymin,type=double -data=1e-4 \
    -parameter=ymax,type=double -data=0.008 \
    \
    -parameter=n_lines,type=double -data=11 \
    \
    -parameter=nx_fma,type=double -data=51 \
    -parameter=ny_fma,type=double -data=21 \
    \
    -parameter=beam_current_ave,type=double -data=330 \
    -parameter=nbunches,type=double -data=390 \
    -parameter=Vrf,type=double -data=1.68 \
    -parameter=harmonic,type=double -data=432 \
    -parameter=circumf,type=double -data=259.2 \
    -parameter=bunch_duration,type=double -data=12 \
    -parameter=coupling,type=double -data=0.01



## *********************************************************##
## Run Elegant with errors and make trajectory statistics.  ##
## *********************************************************##

elegant elettra_run1.ele


# **** Plot the closed orbit in the presence of errors and correction 

sddsxref elettra1bis.cen elettra1bis.twi elettra1bis.mag elettra1bis.tmp
cp elettra1bis.tmp elettra1bis.kick
cp elettra1bis.tmp elettra1bis.mon 

sddsprocess elettra1bis.mon  -match=col,ElementType=MONI -noWarning
sddsprocess elettra1bis.kick -match=col,ElementName=*KICK* -noWarning

sddsplot \
	-column=s,Cx -legend=spec=X-BPM -unsup=y -split=Pages \
        -zoom=yfac=0.87,qcent=0.53 elettra1bis.mon -ticksettings=yscaleChars=1.4 \
	-graphics=symbol,type=1,subtype=4,thickness=5 -yscale=id=1 \
	-col=s,Cx -unsup=y -legend=spec=X-Orbit -split=Pages \
	-zoom=yfac=0.87,qcent=0.53 elettra1bis.tmp -graphic=line,type=3,thickness=3 -yscale=id=1 \
        -column=s,Profile elettra1bis.tmp \
        -overlay=xmode=normal,yfactor=0.05,qoffset=0.43,ycenter,ymode=unit \
        -column=s,Cy -legend=spec=Y-BPM -unsup=y -split=Pages \
        -zoom=yfac=0.87,qcent=0.53 elettra1bis.mon \
	-graphics=symbol,type=1,subtype=2,thickness=5 -yscale=id=1 \
	-col=s,Cy -unsup=y -legend=spec=Y-Orbit -split=Pages \
	-zoom=yfac=0.87,qcent=0.53 elettra1bis.tmp -graphic=line,type=1,thickness=3 -yscale=id=1 \
        -column=s,Profile elettra1bis.tmp \
        -overlay=xmode=normal,yfactor=0.05,qoffset=0.43,ycenter,ymode=unit \
        -title='Lattice with Errors and Orbit Correction' -toptitle

