Example of tracking with active main and 3rd-harmonic cavities using
lattice and cavity parameters supplied by Yong-Chul Chae (DESY) for
PETRA-IV.

Uses pseudo-multibunch mode to avoid tracking many bunches.
The charge is ramped up over 5000 turns to improve stability.
Longitudinal feedback is used to stabilize the bunch centroid.

--Michael Borland, 2021/8/26

====
Source files (see below for usage sequence):

P4_PR_23g.lte --- PETRA-IV lattice.
lattice.lte --- Lattice file using ILMATRIX, SREFFECTS, and RFMODE elements for
                fast longitudinal tracking

AmpFeedbackFilters.sdds
PhaseFeedbackFilters.sdds
        From T. Berenc, used to model rf feedback for main cavity for APS and APS-U.

Basic.ele
        Basic run for setting up fast tracking, getting lattice parameters.
        Uses the P4_PR_23g.lte file

ILMatrixSetup
ILMatrix.xref
        Set up ILMATRIX for fast tracking. Makes the file ILMatrix.param
        One can also copy this file from elsewhere, e.g., from a tracking
        based determination.

SREffectsSetup
SREffects.xref
        Set up SREFFECTS For fast tracking. Makes SREffects.param

RFMODEsetup
setupRFMODE.xref
        Used to prepare data for the RFMODE elements. Makes optimumRf.param

makeBunch
makeBunch.ele
        Makes a single bunch (duplicated for tracking).


====        

Sequence of operations

** Set up lattice model
elegant Basic.ele
SREffectsSetup
ILMatrixSetup

** Find optimum cavity settings
RFMODEsetup
This script also puts the optimum bunch profile Basic.twi.longit, which is needed for the next step.

makeBunch -rootname bunch10kP -nPerBunch 10000 -profile Basic.twi.longit

mpiexec -np <cores> Pelegant runRFMODE.ele 

sddscontour -shade -waterfall=param=Pass,indep=dt,color=dtFrequency runRFMODE.h00
sddsplot -col=Pass,'(Cdelta,Sdelta,St)' -sep -layout=1,3 -join=x runRFMODE.wp00 -group=names -sep=names -graph=line,vary 

runRFMODE.h00 --- histogram of longitudinal data 
runRFMODE.new --- lattice file reflecting all changes from the command file
runRFMODE.rfh3 --- record of harmonic cavity
runRFMODE.rfm-fb --- record of main cavity feedback
runRFMODE.rfmm --- record of main cavity
runRFMODE.wp00 --- bunch parameters vs pass
runRFMODE.zfb --- longitudinal feedback record

