Skip to content

Commit 6dd7ad1

Browse files
Lint and light reformat of code
1 parent 842b01a commit 6dd7ad1

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

tests/test_beamstrahlung_pic.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ def test_beambeam3d_beamstrahlung_pic(test_context):
2323

2424
print(repr(test_context))
2525

26-
# fcc ttbar 4 IP
26+
# fcc ttbar 4 IP
2727
# https://indico.cern.ch/event/1202105/contributions/5408583/attachments/2659051/4608141/FCCWeek_Optics_Oide_230606.pdf
28-
bunch_intensity = 1.55e11 # [e]
28+
bunch_intensity = 1.55e11 # [e]
2929
energy = 182.5 # [GeV]
3030
p0c = 182.5e9 # [eV]
3131
mass0 = 511000 # [eV]
3232
phi = 15e-3 # [rad] half xing
3333
physemit_x = 1.59e-09 # [m]
34-
physemit_y = 9e-13 # [m]
34+
physemit_y = 9e-13 # [m]
3535
beta_x = 1 # [m]
3636
beta_y = 1.6e-3 # [m]
3737
sigma_x = np.sqrt(physemit_x*beta_x) # [m]
@@ -46,7 +46,7 @@ def test_beambeam3d_beamstrahlung_pic(test_context):
4646
n_macroparticles_b2 = int(1e6)
4747

4848
################
49-
# create beams #
49+
# create beams #
5050
################
5151

5252
#e-
@@ -124,7 +124,7 @@ def test_beambeam3d_beamstrahlung_pic(test_context):
124124
bbpic_ip1_b2.pipeline_manager = pipeline_manager
125125

126126
######################
127-
# set up xtrack line #
127+
# set up xtrack line #
128128
######################
129129

130130
line_b1 = xt.Line(elements=[bbpic_ip1_b1])
@@ -139,7 +139,7 @@ def test_beambeam3d_beamstrahlung_pic(test_context):
139139
enable_debug_log=True, verbose=True)
140140

141141
################
142-
# configure BS #
142+
# configure BS #
143143
################
144144

145145
assert line_b1._needs_rng == False
@@ -156,7 +156,7 @@ def test_beambeam3d_beamstrahlung_pic(test_context):
156156
xf.BeamBeamPIC3D, capacity={"beamstrahlungtable": int(3e5)})
157157

158158
#####################
159-
# track 1 collision #
159+
# track 1 collision #
160160
#####################
161161

162162
multitracker.track(num_turns=1)
@@ -218,7 +218,7 @@ def test_beambeam3d_beamstrahlung_pic(test_context):
218218
photons_pic_b1 = set(record_b1_pic.beamstrahlungtable.photon_energy)
219219
photons_pic_b2 = set(record_b2_pic.beamstrahlungtable.photon_energy)
220220

221-
# compare the upper part of the energy spectrum bc it has better statistics than low end tail
221+
# compare the upper part of the energy spectrum bc it has better statistics than low end tail
222222
hist_pic_b1 = np.histogram(np.array([*photons_pic_b1]), bins=bins)[0][int(n_bins/2):]
223223
hist_pic_b2 = np.histogram(np.array([*photons_pic_b2]), bins=bins)[0][int(n_bins/2):]
224224

xfields/beam_elements/beambeam3dpic.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55

66
import numpy as np
77
from scipy.constants import e as qe
8-
from scipy.constants import c as clight
98

109
import xobjects as xo
1110
import xtrack as xt
12-
import pickle as pkl
13-
14-
from ..general import _pkg_root
15-
from .beambeam3d import _init_alpha_phi
1611
from xfields import TriLinearInterpolatedFieldMap
12+
from .beambeam3d import _init_alpha_phi
13+
from ..general import _pkg_root
14+
1715

1816
class BeamstrahlungTable(xo.HybridClass):
1917
"""
@@ -30,7 +28,7 @@ class BeamstrahlungTable(xo.HybridClass):
3028
particle_id: [1] array index in the xpart.Particles object of the primary macroparticle emitting the photon
3129
primary_energy: [eV] total energy of primary macroparticle before emission of this photon
3230
photon_id: [1] counter for photons emitted from the same primary in the same collision with a single slice
33-
 photon_energy: [eV] total energy of a beamstrahlung photon
31+
photon_energy: [eV] total energy of a beamstrahlung photon
3432
photon_critical_energy (with quantum BS only): [eV] critical energy of a beamstrahlung photon
3533
rho_inv (with quantum BS only): [m^-1] (Fr/dz) inverse bending radius of the primary macroparticle
3634
"""
@@ -44,7 +42,7 @@ class BeamstrahlungTable(xo.HybridClass):
4442
'photon_energy': xo.Float64[:],
4543
'photon_critical_energy': xo.Float64[:],
4644
'rho_inv': xo.Float64[:],
47-
}
45+
}
4846

4947
class LumiTable(xo.HybridClass):
5048
"""
@@ -61,24 +59,23 @@ class LumiTable(xo.HybridClass):
6159
luminosity: [m^-2] integrated luminosity per bunch crossing for one turn, obtained from the charge density grid. Turn by turn lumi. This is overwritten at every call.
6260
"""
6361
_xofields = {
64-
'_index': xt.RecordIndex,
65-
'at_turn': xo.Int64[:],
66-
'at_element': xo.Int64[:], # size: n_turns
67-
'luminosity': xo.Float64[:], # size: n_turns
68-
}
62+
'_index': xt.RecordIndex,
63+
'at_turn': xo.Int64[:],
64+
'at_element': xo.Int64[:], # size: n_turns
65+
'luminosity': xo.Float64[:], # size: n_turns
66+
}
6967

7068
# currently not possible to have a record table with elements of different size so lumigrid is an attribute
7169

7270
class BeamBeamPIC3DRecord(xo.HybridClass):
7371
_xofields = {
7472
'beamstrahlungtable': BeamstrahlungTable,
7573
'lumitable': LumiTable,
76-
}
74+
}
7775

7876
class BeamBeamPIC3D(xt.BeamElement):
7977

8078
_xofields = {
81-
8279
'_sin_phi': xo.Float64,
8380
'_cos_phi': xo.Float64,
8481
'_tan_phi': xo.Float64,
@@ -112,7 +109,7 @@ class BeamBeamPIC3D(xt.BeamElement):
112109
# beamstrahlung
113110
'flag_beamstrahlung': xo.Int64,
114111

115-
# luminosity
112+
# luminosity
116113
'flag_luminosity': xo.Int64,
117114
'flag_lumigrid': xo.Int64,
118115
}
@@ -325,16 +322,16 @@ def track(self, particles):
325322
pp.x = -pp.x
326323
self.fieldmap_self.update_from_particles(particles=pp, update_phi=False)
327324

328-
# for visualizing luminous region, size (2, nt=nz, nx, ny, nz), 0: self, 1: other
325+
# for visualizing luminous region, size (2, nt=nz, nx, ny, nz), 0: self, 1: other
329326
at_turn = pp._xobject.at_turn[0] # On CPU there is always an active particle in position 0
330327
nx, ny, nz, dx, dy, dz = (self.fieldmap_self.nx, self.fieldmap_self.ny, self.fieldmap_self.nz,
331328
self.fieldmap_self.dx, self.fieldmap_self.dy, self.fieldmap_self.dz)
332329

333-
# scaling from [C] to [macroparts]
330+
# scaling from [C] to [macroparts]
334331
weight = pp._xobject.weight[0] # number of elementary charges per macroparticle
335-
pwei = (dx*dy*dz) / (qe * weight) # qe=1.6e-19 [C] from scipy.constants
332+
pwei = (dx*dy*dz) / (qe * weight) # qe=1.6e-19 [C] from scipy.constants
336333

337-
# other beam: fixed in center of grid, self beam: moves in and out of grid
334+
# other beam: fixed in center of grid, self beam: moves in and out of grid
338335
if self.flag_lumigrid:
339336

340337
# unit: [1] (macroparticle dist.)
@@ -343,13 +340,13 @@ def track(self, particles):
343340
[self.fieldmap_self.rho.flatten(), self.fieldmap_other.rho.flatten()]
344341
) * pwei)
345342

346-
# 2: kinematic factor, dt(=dz): integral over the time, unit: [m^-2]
343+
# 2: kinematic factor, dt(=dz): integral over the time, unit: [m^-2]
347344
num_macroparts_in_grid_self = np.abs(np.sum(self.fieldmap_self.rho )*pwei)
348345
num_macroparts_in_grid_other = np.abs(np.sum(self.fieldmap_other.rho)*pwei)
349346
self.record.lumitable.luminosity[at_turn] += (dz*2*weight**2 * num_macroparts_in_grid_self * num_macroparts_in_grid_other *
350347
self.compute_lumi_integral_3d(self.fieldmap_self.rho, self.fieldmap_other.rho, dx, dy, dz))
351348

352-
# move self beam back to center of its own grid
349+
# move self beam back to center of its own grid
353350
pp.zeta = -pp.zeta + z_step_other + z_step_self
354351
pp.x = -pp.x
355352
self.fieldmap_self.update_from_particles(particles=pp, update_phi=False)
@@ -442,24 +439,27 @@ def compute_lumi_integral_3d(self, lumigrid_my_beam, lumigrid_other_beam, dx, dy
442439
h_multiplied[0, 0, nz-1] + h_multiplied[nx-1, 0, nz-1] +
443440
h_multiplied[0, ny-1, nz-1] + h_multiplied[nx-1, ny-1, nz-1])
444441

445-
# interior points
442+
# interior points
446443
secondPart = self._buffer.context.nplike_lib.sum(
447444
h_multiplied[1:nx-1, 1:ny-1, 1:nz-1])
448445

449-
# x boundaries
446+
# x boundaries
450447
thirdPart = self._buffer.context.nplike_lib.sum(
451448
h_multiplied[1:nx-1, 0, 1:nz-1] + h_multiplied[1:nx-1, ny-1, 1:nz-1])
452449

453-
# y boundaries
450+
# y boundaries
454451
fourthPart = self._buffer.context.nplike_lib.sum(
455452
h_multiplied[0, 1:ny-1, 1:nz-1] + h_multiplied[nx-1, 1:ny-1, 1:nz-1])
456453

457-
# z boundaries
454+
# z boundaries
458455
fifthPart = self._buffer.context.nplike_lib.sum(
459456
h_multiplied[1:nx-1, 1:ny-1, 0] + h_multiplied[1:nx-1, 1:ny-1, nz-1])
460457

461-
# 3D trapezoid integral
458+
# 3D trapezoid integral
462459
integralf = integral + 0.125 * dx * dy * dz * (
463460
8 * secondPart + 4 * thirdPart + 4 * fourthPart + 4 * fifthPart)
464461

465-
return integralf if not self._buffer.context.nplike_lib.isnan(integralf) else 0
462+
if self._buffer.context.nplike_lib.isnan(integralf):
463+
return 0
464+
465+
return integralf

0 commit comments

Comments
 (0)