@@ -14,7 +14,8 @@ struct elem
14
14
double Vy ;
15
15
double Frequency ;
16
16
double Energy ;
17
- double Phase ;
17
+ double TimeLag ;
18
+ double PhaseLag ;
18
19
double SigPhi ;
19
20
double SigVV ;
20
21
};
@@ -37,7 +38,7 @@ static void CrabCavityPass(double *r_in, double le, double nvx, double nvy,
37
38
double k = TWOPI * freq /C0 ;
38
39
39
40
if (sigphi > 0.0 )
40
- phi = phi + atrandn_r (rng , 0.0 , sigphi );
41
+ phi += atrandn_r (rng , 0.0 , sigphi );
41
42
if (sigvv > 0.0 ) {
42
43
nvx *= atrandn_r (rng , 1.0 , sigvv );
43
44
nvy *= atrandn_r (rng , 1.0 , sigvv );
@@ -75,15 +76,17 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
75
76
double * r_in , int num_particles , struct parameters * Param )
76
77
{
77
78
double energy ;
79
+ double lag , t0f , phiref ;
78
80
79
81
if (!Elem ) {
80
- double Length , * Voltages , Energy , Frequency , Phase , SigPhi , SigVV ;
82
+ double Length , * Voltages , Energy , Frequency , TimeLag , PhaseLag , SigPhi , SigVV ;
81
83
Length = atGetDouble (ElemData ,"Length" ); check_error ();
82
84
Voltages = atGetDoubleArray (ElemData ,"Voltages" ); check_error ();
83
85
Frequency = atGetDouble (ElemData ,"Frequency" ); check_error ();
84
86
/* Optional fields */
85
87
Energy = atGetOptionalDouble (ElemData ,"Energy" ,Param -> energy ); check_error ();
86
- Phase = atGetOptionalDouble (ElemData ,"Phase" ,0.0 ); check_error ();
88
+ TimeLag = atGetOptionalDouble (ElemData ,"TimeLag" ,0.0 ); check_error ();
89
+ PhaseLag = atGetOptionalDouble (ElemData ,"PhaseLag" ,0.0 ); check_error ();
87
90
SigPhi = atGetOptionalDouble (ElemData ,"SigPhi" ,0.0 ); check_error ();
88
91
SigVV = atGetOptionalDouble (ElemData ,"SigVV" ,0.0 ); check_error ();
89
92
@@ -93,13 +96,17 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
93
96
Elem -> Vy = Voltages [1 ];
94
97
Elem -> Energy = Energy ;
95
98
Elem -> Frequency = Frequency ;
96
- Elem -> Phase = Phase ;
99
+ Elem -> TimeLag = TimeLag ;
100
+ Elem -> PhaseLag = PhaseLag ;
97
101
Elem -> SigPhi = SigPhi ;
98
102
Elem -> SigVV = SigVV ;
99
103
}
100
104
energy = atEnergy (Param -> energy , Elem -> Energy );
105
+ t0f = Elem -> Frequency * Param -> T0 ;
106
+ lag = TWOPI * Elem -> Frequency * Elem -> TimeLag /C0 + Elem -> PhaseLag ;
107
+ phiref = TWOPI * (t0f - round (t0f )) * Param -> nturn - lag ;
101
108
CrabCavityPass (r_in , Elem -> Length , Elem -> Vx /energy , Elem -> Vy /energy ,
102
- Elem -> Frequency , Elem -> Phase , Elem -> SigPhi , Elem -> SigVV , Param -> common_rng , num_particles );
109
+ Elem -> Frequency , phiref , Elem -> SigPhi , Elem -> SigVV , Param -> common_rng , num_particles );
103
110
return Elem ;
104
111
}
105
112
@@ -111,6 +118,7 @@ MODULE_DEF(CrabCavityPass) /* Dummy module initialisation */
111
118
void mexFunction (int nlhs , mxArray * plhs [], int nrhs , const mxArray * prhs [])
112
119
{
113
120
if (nrhs >= 2 ) {
121
+ double lag , phiref ;
114
122
double * r_in ;
115
123
double rest_energy = 0.0 ;
116
124
double charge = -1.0 ;
@@ -121,7 +129,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
121
129
double Frequency = atGetDouble (ElemData ,"Frequency" ); check_error ();
122
130
/* Optional fields */
123
131
double Energy = atGetOptionalDouble (ElemData ,"Energy" ,0.0 ); check_error ();
124
- double Phase = atGetOptionalDouble (ElemData ,"Phase" ,0.0 ); check_error ();
132
+ double TimeLag = atGetOptionalDouble (ElemData ,"TimeLag" ,0.0 ); check_error ();
133
+ double PhaseLag = atGetOptionalDouble (ElemData ,"PhaseLag" ,0.0 ); check_error ();
125
134
double SigPhi = atGetOptionalDouble (ElemData ,"SigPhi" ,0.0 ); check_error ();
126
135
double SigVV = atGetOptionalDouble (ElemData ,"SigVV" ,0.0 ); check_error ();
127
136
if (nrhs > 2 ) atProperties (prhs [2 ], & Energy , & rest_energy , & charge );
@@ -130,20 +139,23 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
130
139
/* ALLOCATE memory for the output array of the same size as the input */
131
140
plhs [0 ] = mxDuplicateArray (prhs [1 ]);
132
141
r_in = mxGetDoubles (plhs [0 ]);
142
+ lag = TWOPI * Frequency * TimeLag /C0 + PhaseLag ;
143
+ phiref = - lag ;
133
144
CrabCavityPass (r_in , Length , Voltages [0 ]/Energy , Voltages [1 ]/Energy ,
134
- Frequency , Phase , SigPhi , SigVV , & pcg32_global , num_particles );
145
+ Frequency , phiref , SigPhi , SigVV , & pcg32_global , num_particles );
135
146
}
136
147
else if (nrhs == 0 ) {
137
148
plhs [0 ] = mxCreateCellMatrix (3 ,1 );
138
149
mxSetCell (plhs [0 ],0 ,mxCreateString ("Length" ));
139
150
mxSetCell (plhs [0 ],1 ,mxCreateString ("Voltages" ));
140
151
mxSetCell (plhs [0 ],2 ,mxCreateString ("Frequency" ));
141
152
if (nlhs > 1 ) { /* optional fields */
142
- plhs [1 ] = mxCreateCellMatrix (4 ,1 );
153
+ plhs [1 ] = mxCreateCellMatrix (5 ,1 );
143
154
mxSetCell (plhs [0 ],0 ,mxCreateString ("Energy" ));
144
- mxSetCell (plhs [1 ],1 ,mxCreateString ("Phase" ));
145
- mxSetCell (plhs [1 ],2 ,mxCreateString ("SigPhi" ));
146
- mxSetCell (plhs [1 ],3 ,mxCreateString ("SigVV" ));
155
+ mxSetCell (plhs [1 ],1 ,mxCreateString ("TimeLag" ));
156
+ mxSetCell (plhs [1 ],2 ,mxCreateString ("PhaseLag" ));
157
+ mxSetCell (plhs [1 ],3 ,mxCreateString ("SigPhi" ));
158
+ mxSetCell (plhs [1 ],4 ,mxCreateString ("SigVV" ));
147
159
}
148
160
}
149
161
else {
0 commit comments