Skip to content

Commit e5fad72

Browse files
authored
Merge pull request #165 from xsuite/release/v0.7.0
Release 0.7.0
2 parents d224faa + bc25af8 commit e5fad72

File tree

180 files changed

+9972
-2246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+9972
-2246
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
xcoll/lib
22
xcoll/config
3-
3+
tests/assets/
4+
tests/pytest*results.html
45

56
# Byte-compiled / optimized / DLL files
67
__pycache__/
@@ -19,6 +20,8 @@ downloads/
1920
eggs/
2021
.eggs/
2122
lib/
23+
!xcoll/scattering_routines/geant4/collimasim/lib/
24+
!xcoll/scattering_routines/geant4/collimasim/lib/pybind11/
2225
lib64/
2326
parts/
2427
sdist/

.gitmodules

Whitespace-only changes.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Collimation in xtrack simulations
2424
* pandas
2525
* xsuite (in particular xobjects, xdeps, xtrack, xpart)
2626

27+
* Geant4 and BDSIM: conda install bdsim-g4 -c conda-forge
28+
2729
### Installing
2830
`xcoll` is packaged using `poetry`, and can be easily installed with `pip`:
2931
```bash

examples/adt.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
import matplotlib.pyplot as plt
8+
from pathlib import Path
89
import time
910
start_time = time.time()
1011

@@ -13,6 +14,9 @@
1314
import xpart as xp
1415
import xcoll as xc
1516

17+
path = Path(__file__).parent
18+
19+
1620
# This example is a more realistic example of the ADT in the LHC. Each
1721
# particle in a bunch gets the same kick (this is the default for a BlowUp).
1822
# Note that this realistic behaviour shakes the beam around at every pass:
@@ -37,7 +41,7 @@
3741

3842

3943
# Import a Run 3 LHC lattice without apertures
40-
line = xt.Line.from_json(xc._pkg_root.parent / 'examples' / 'machines' / f'lhc_run3_b{beam}_no_aper.json')
44+
line = xt.Line.from_json(path / 'machines' / f'lhc_run3_b{beam}_no_aper.json')
4145

4246

4347
# Create the ADT

examples/adt_simplified.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
import matplotlib.pyplot as plt
8+
from pathlib import Path
89
import time
910
start_time = time.time()
1011

@@ -13,6 +14,9 @@
1314
import xpart as xp
1415
import xcoll as xc
1516

17+
path = Path(__file__).parent
18+
19+
1620
# This example is a simplified example of the ADT in the LHC. Each
1721
# particle gets a different kick, randomly sampled. This allows for
1822
# a quicker and more controlled emittance growth (though less realistic).
@@ -27,7 +31,7 @@
2731

2832

2933
# Import a Run 3 LHC lattice without apertures
30-
line = xt.Line.from_json(xc._pkg_root.parent / 'examples' / 'machines' / f'lhc_run3_b{beam}_no_aper.json')
34+
line = xt.Line.from_json(path / 'machines' / f'lhc_run3_b{beam}_no_aper.json')
3135

3236

3337
# Create the ADT

examples/colldb/lhc_run3.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ All:
2828

2929
families:
3030
# Momentum cleaning
31-
- &TCP3 { <<: *ALL, gap: 15, stage: primary, material: C, length: 0.6 }
32-
- &TCSG3 { <<: *ALL, gap: 18, stage: secondary, material: C, length: 1 }
31+
- &TCP3 { <<: *ALL, gap: 15, stage: primary, material: CFC, length: 0.6 }
32+
- &TCSG3 { <<: *ALL, gap: 18, stage: secondary, material: CFC, length: 1 }
3333
- &TCLA3 { <<: *ALL, gap: 20, stage: tertiary, material: Iner, length: 1 }
3434
# Betatron cleaning
35-
- &TCP7 { <<: *ALL, gap: 5, stage: primary, material: C, length: 0.6 }
36-
- &TCSG7 { <<: *ALL, gap: 6.5, stage: secondary, material: C, length: 1 }
35+
- &TCP7 { <<: *ALL, gap: 5, stage: primary, material: CFC, length: 0.6 }
36+
- &TCSG7 { <<: *ALL, gap: 6.5, stage: secondary, material: CFC, length: 1 }
3737
- &TCLA7 { <<: *ALL, gap: 10, stage: tertiary, material: Iner, length: 1 }
3838
- &CRY7 { <<: *ALL, gap: null, stage: special, material: Si, length: 0.004, side: left, crystal: strip, active: false }
3939
# Injection protection
40-
- &TCLI { <<: *ALL, gap: null, stage: tertiary, material: C, length: 1, angle: 90 }
40+
- &TCLI { <<: *ALL, gap: null, stage: tertiary, material: CFC, length: 1, angle: 90 }
4141
- &TDI { <<: *ALL, gap: null, stage: tertiary, material: CU, length: 1.565, angle: 90 }
4242
# Dump protection
43-
- &TCDQ { <<: *ALL, gap: 7.3, stage: tertiary, material: C, length: 3, angle: 0, side: left }
44-
- &TCSP { <<: *ALL, gap: 7.3, stage: secondary, material: C, length: 1, angle: 0 }
43+
- &TCDQ { <<: *ALL, gap: 7.3, stage: tertiary, material: CFC, length: 3, angle: 0, side: left }
44+
- &TCSP { <<: *ALL, gap: 7.3, stage: secondary, material: CFC, length: 1, angle: 0 }
4545
# Triplet protection
4646
- &TCT15 { <<: *ALL, gap: 8.5, stage: tertiary, material: Iner, length: 1, parking: 0.020 }
4747
- &TCT2 { <<: *ALL, gap: 37, stage: tertiary, material: Iner, length: 1, }

examples/colldb/lhc_run3_crystals.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ All:
2828

2929
families:
3030
# Momentum cleaning
31-
- &TCP3 { <<: *ALL, gap: 15, stage: primary, material: C, length: 0.6 }
32-
- &TCSG3 { <<: *ALL, gap: 18, stage: secondary, material: C, length: 1 }
31+
- &TCP3 { <<: *ALL, gap: 15, stage: primary, material: CFC, length: 0.6 }
32+
- &TCSG3 { <<: *ALL, gap: 18, stage: secondary, material: CFC, length: 1 }
3333
- &TCLA3 { <<: *ALL, gap: 20, stage: tertiary, material: Iner, length: 1 }
3434
# Betatron cleaning
35-
- &TCP7 { <<: *ALL, gap: 6, stage: primary, material: C, length: 0.6 }
36-
- &TCSG7 { <<: *ALL, gap: 6.5, stage: secondary, material: C, length: 1 }
35+
- &TCP7 { <<: *ALL, gap: 6, stage: primary, material: CFC, length: 0.6 }
36+
- &TCSG7 { <<: *ALL, gap: 6.5, stage: secondary, material: CFC, length: 1 }
3737
- &TCLA7 { <<: *ALL, gap: 8, stage: tertiary, material: Iner, length: 1 }
3838
- &CRY7 { <<: *ALL, gap: 5, stage: special, material: Si, length: 0.004, side: left, crystal: strip, active: true}
3939
# Injection protection
40-
- &TCLI { <<: *ALL, gap: null, stage: tertiary, material: C, length: 1, angle: 90 }
40+
- &TCLI { <<: *ALL, gap: null, stage: tertiary, material: CFC, length: 1, angle: 90 }
4141
- &TDI { <<: *ALL, gap: null, stage: tertiary, material: CU, length: 1.565, angle: 90 }
4242
# Dump protection
43-
- &TCDQ { <<: *ALL, gap: 7.3, stage: tertiary, material: C, length: 3, angle: 0, side: left }
44-
- &TCSP { <<: *ALL, gap: 7.3, stage: secondary, material: C, length: 1, angle: 0 }
43+
- &TCDQ { <<: *ALL, gap: 7.3, stage: tertiary, material: CFC, length: 3, angle: 0, side: left }
44+
- &TCSP { <<: *ALL, gap: 7.3, stage: secondary, material: CFC, length: 1, angle: 0 }
4545
# Triplet protection
4646
- &TCT15 { <<: *ALL, gap: 9.5, stage: tertiary, material: Iner, length: 1, parking: 0.020 }
4747
- &TCT2 { <<: *ALL, gap: 37, stage: tertiary, material: Iner, length: 1, }

examples/colldb/lhc_tcp_b1.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# name opening/fam mat. length[m] angle[deg] offset[m]
2-
tcp.6l3.b1 15.0 C 0.6 0.0 0.
2+
tcp.6l3.b1 15.0 CFC 0.6 0.0 0.
33
tcp.d6l7.b1 5.0 MoGR 0.6 90.0 0.
44
tcp.c6l7.b1 5.0 MoGR 0.6 0.0 0.
5-
tcp.b6l7.b1 5.0 C 0.6 127.5 0.
5+
tcp.b6l7.b1 5.0 CFC 0.6 127.5 0.

examples/everest_collimator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ######################################### #
55

66
import numpy as np
7+
from pathlib import Path
78
import matplotlib.pyplot as plt
89

910
import xobjects as xo
@@ -22,7 +23,7 @@
2223
# context = xo.ContextPyopencl() # For OpenCL GPUs
2324

2425
beam = 1
25-
path_in = xc._pkg_root.parent / 'examples'
26+
path_in = Path(__file__).parent
2627

2728

2829
# Load from json

examples/geant4_benchmark.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import numpy as np
2+
import xpart as xp
3+
import xtrack as xt
4+
import xtrack.particles.pdg as pdg
5+
import xcoll as xc
6+
from xcoll import constants as xcs
7+
import time
8+
9+
import matplotlib.pyplot as plt
10+
11+
12+
if xc.geant4.engine.is_running():
13+
xc.geant4.engine.stop()
14+
15+
16+
# Make some Geant4 and Everest collimators to preload materials
17+
g4_colls = []
18+
ev_colls = []
19+
for material in ['Air', 'Water', 'Beryllium', 'MoGR', 'Inermet180']:
20+
for length in [1.e-3, 2.e-2, 0.1, 0.4, 1]:
21+
g4_colls.append(xc.Geant4Collimator(length=length, material=material, jaw=0.001))
22+
ev_colls.append(xc.EverestCollimator(length=length, material=material, jaw=0.001))
23+
24+
25+
# Start the engine
26+
xc.geant4.engine.particle_ref = xt.Particles('proton', p0c=6.8e12)
27+
xc.geant4.engine.start(elements=g4_colls, clean=True, verbose=False)
28+
29+
30+
# Create an initial distribution of particles
31+
num_part = 5000
32+
x_init = np.random.normal(loc=0.05, scale=0.2e-3, size=num_part)
33+
px_init = np.random.normal(loc=0., scale=5.e-6, size=num_part)
34+
y_init = np.random.normal(loc=0., scale=1e-3, size=num_part)
35+
py_init = np.random.normal(loc=0., scale=5.e-6, size=num_part)
36+
zeta_init = np.random.normal(loc=0., scale=1.e-2, size=num_part)
37+
delta_init = np.random.normal(loc=0., scale=5.e-4, size=num_part)
38+
part_init = xp.build_particles(x=x_init, px=px_init, y=y_init, py=py_init,
39+
zeta=zeta_init, delta=delta_init,
40+
particle_ref=xc.geant4.engine.particle_ref,
41+
_capacity=num_part*2)
42+
43+
for ev_coll, g4_coll in zip(ev_colls, g4_colls):
44+
print(f"\nBenchmarking collimator: length={g4_coll.length} m, material={g4_coll.material.name}")
45+
# Copy initial particles for each collimator
46+
part = part_init.copy()
47+
print(f" Tracking {num_part} protons with Everest... ", end='', flush=True)
48+
start = time.time()
49+
ev_coll.track(part)
50+
print(f"Done in {(time.time()-start)*1000:.3}ms. Dead: {np.sum((part.state < 1) & (part.state > -999999))}. "
51+
f"Alive: {np.sum(part.state == 1)}", flush=True)
52+
part = part_init.copy()
53+
print(f" Tracking {num_part} protons with Geant4... ", end='', flush=True)
54+
start = time.time()
55+
g4_coll.track(part)
56+
print(f"Done in {time.time()-start:.3}s. Dead: {np.sum((part.state < 1) & (part.state > -999999))}. "
57+
f"Alive: {np.sum(part.state == 1)}", flush=True)

0 commit comments

Comments
 (0)