Skip to content

Commit 73e6151

Browse files
authored
Bug in piwinski touschek scattering B2 term (#765)
* correct bug, improve help and fix pep8 * refactor eq and multiply by 4 second term
1 parent ed24055 commit 73e6151

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

pyat/at/acceptance/touschek.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
def get_bunch_length_espread(ring, zn=None, bunch_curr=None, espread=None):
1919
"""Haissinski equation solver
20-
20+
2121
Solves the Haissinski formula and returns the bunch length and energy
2222
spread for given bunch current and :math:`Z/n`. If both ``zn`` and
2323
``bunch_curr`` are ``None``, zero current case, otherwise both are needed
@@ -77,8 +77,12 @@ def get_beam_sizes(ring, bunch_curr, zn=None, emitx=None,
7777

7878

7979
def int_piwinski(k, km, B1, B2):
80-
"""
80+
r"""
8181
Integrand of the piwinski formula
82+
In case the Bessel function has too large value
83+
(more than :math:`10^251`) it
84+
is substituted by its exponential approximation:
85+
:math:`I_0(x)~\frac{\exp(x)}{\sqrt{2 \pi x}}`
8286
"""
8387
t = numpy.tan(k)**2
8488
tm = numpy.tan(km)**2
@@ -125,7 +129,7 @@ def _get_vals(ring, rp, ma, emity, bunch_curr, emitx=None,
125129
bg2i = 1/(2*beta2*gamma2)
126130
B1 = bg2i*numpy.sum(bs, axis=1)
127131
B2sq = bg2i*bg2i*(numpy.diff(bs, axis=1).T**2 +
128-
sigh2*sigh2*numpy.prod(bxy2*dt2, axis=1) /
132+
4*sigh2*sigh2*numpy.prod(bxy2*dt2, axis=1) /
129133
numpy.prod(sigb2*sigb2, axis=1))
130134
B2 = numpy.squeeze(numpy.sqrt(B2sq))
131135

@@ -138,8 +142,8 @@ def _get_vals(ring, rp, ma, emity, bunch_curr, emitx=None,
138142
for ii in range(len(rp)):
139143
args = (km[ii], B1[ii], B2[ii])
140144
val[i, ii], *_ = integrate.quad(int_piwinski, args[0], numpy.pi/2,
141-
args=args, epsabs=epsabs,
142-
epsrel=epsrel)
145+
args=args, epsabs=epsabs,
146+
epsrel=epsrel)
143147

144148
val[i] *= (_e_radius**2*clight*nc /
145149
(8*numpy.pi*gamma2*sigs *
@@ -210,7 +214,7 @@ def _init_ma_rp(ring, refpts=None, offset=None, momap=None,
210214
def get_lifetime(ring, emity, bunch_curr, emitx=None, sigs=None, sigp=None,
211215
zn=None, momap=None, refpts=None, offset=None, **kwargs):
212216
"""Touschek lifetime calculation
213-
217+
214218
Computes the touschek lifetime using the Piwinski formula
215219
216220
args:
@@ -223,8 +227,9 @@ def get_lifetime(ring, emity, bunch_curr, emitx=None, sigs=None, sigp=None,
223227
sigs=None: rms bunch length
224228
sigp=None: energy spread
225229
zn=None: full ring :math:`Z/n`
226-
momap=None: momentum aperture, has to be consistent with ``refpts``
227-
if provided the momentum aperture is not calculated
230+
momap=None: momentum aperture, has to be consistent with
231+
``refpts`` if provided the momentum aperture is
232+
not calculated
228233
refpts=None: ``refpts`` where the momentum aperture is calculated,
229234
the default is to compute it for all elements in the
230235
ring, ``len(refpts)>2`` is required
@@ -245,7 +250,7 @@ def get_lifetime(ring, emity, bunch_curr, emitx=None, sigs=None, sigp=None,
245250
epsabs, epsrel: integral absolute and relative tolerances
246251
247252
Returns:
248-
tl: touschek lifetime, double expressed in seconds
253+
tl: touschek lifetime, double expressed in seconds
249254
ma: momentum aperture (len(refpts), 2) array
250255
refpts: refpts used for momentum aperture calculation
251256
(len(refpts), ) array
@@ -281,8 +286,9 @@ def get_scattering_rate(ring, emity, bunch_curr, emitx=None, sigs=None,
281286
sigs=None: rms bunch length
282287
sigp=None: energy spread
283288
zn=None: full ring :math:`Z/n`
284-
momap=None: momentum aperture, has to be consistent with ``refpts``
285-
if provided the momentum aperture is not calculated
289+
momap=None: momentum aperture, has to be consistent with
290+
``refpts`` if provided the momentum aperture
291+
is not calculated
286292
refpts=None: ``refpts`` where the momentum aperture is calculated,
287293
the default is to compute it for all elements in the
288294
ring, ``len(refpts)>2`` is required
@@ -317,7 +323,8 @@ def get_scattering_rate(ring, emity, bunch_curr, emitx=None, sigs=None,
317323
vals = _get_vals(ring, rp, ma, emity, bunch_curr, emitx=emitx,
318324
sigs=sigs, sigp=sigp, zn=zn, epsabs=epsabs,
319325
epsrel=epsrel)
320-
scattering_rate = numpy.mean(vals, axis=0)*bunch_curr/ring.revolution_frequency/qe
326+
scattering_rate = (numpy.mean(vals, axis=0)*bunch_curr /
327+
ring.revolution_frequency / qe)
321328
return scattering_rate, ma, rp
322329

323330

0 commit comments

Comments
 (0)