Skip to content

Commit a7e622f

Browse files
authored
Merge pull request #77 from lhcopt/Release/v1.3.1
Release/v1.3.1
2 parents af9c7aa + a6237b8 commit a7e622f

File tree

16 files changed

+2653
-34
lines changed

16 files changed

+2653
-34
lines changed

pymask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "v1.3.0"
1+
__version__ = "v1.3.1"
22

33
from .beambeam import *
44
from .madpoint import *

pymask/pymasktools.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44

55
import numpy as np
6+
import pandas as pd
67

78
import xtrack as xt
89
import xpart as xp
@@ -375,7 +376,8 @@ def get_optics_and_orbit_at_start_ring(mad, seq_name, with_bb_forces=False,
375376
px = twiss_table.px[0],
376377
y = twiss_table.y[0],
377378
py = twiss_table.py[0],
378-
psigma = twiss_table.pt[0]/mad_beam.beta,
379+
ptau = twiss_table.pt[0],
380+
zeta = twiss_table.t[0] * mad_beam.beta
379381
)
380382
particle_on_madx_co.zeta = (twiss_table.t[0]
381383
*particle_on_madx_co.beta0
@@ -544,3 +546,59 @@ def _restore_beam_beam(line):
544546
del(ee._temp_Ddelta_sub)
545547
else:
546548
raise ValueError('What?!')
549+
550+
551+
552+
def seqedit(mad,seq_name,editing,madInput = True):
553+
"""Wrapper for MADX seqedit function
554+
555+
-> editing: dict or pd.DataFrame,
556+
"mode" needs to be specified for each element {install, remove, replace, skip}
557+
other columns need to be specified depending on the chosen mode, based on the parameters from the MADX user guide.
558+
-> madInput: bool,
559+
used to skip the mad.input() call and simply return the string
560+
"""
561+
562+
# Converting to pd.DataFrame
563+
if type(editing) is dict:
564+
editing = pd.DataFrame(editing)
565+
566+
# SORTING prior to the installation
567+
if 'at' in list(editing.columns):
568+
editing.sort_values('at',inplace=True)
569+
570+
571+
# ELEMENTS
572+
def installStr(row):
573+
return f'{row["mode"]},element = {row["element"]},class={row["class"]},at = {row["at"]},from = {row["from"]};'
574+
575+
def removeStr(row):
576+
return f'{row["mode"]},element = {row["element"]};'
577+
578+
def replaceStr(row):
579+
return f'{row["mode"]},element = {row["element"]},by = {row["by"]};'
580+
581+
def skipStr(row):
582+
return ''
583+
584+
entryStr = {'install':installStr,'remove':removeStr,'replace':replaceStr,'skip':skipStr}
585+
elementsEntry = '\n'.join(filter(None, [entryStr[row['mode']](row) for _,row in editing.iterrows()]))
586+
587+
588+
# Generating MADX call
589+
output = f'''
590+
use, sequence = {seq_name};
591+
SEQEDIT, SEQUENCE={seq_name};
592+
FLATTEN;
593+
{elementsEntry}
594+
FLATTEN;
595+
ENDEDIT;
596+
597+
use, sequence = {seq_name};
598+
'''
599+
600+
601+
# Sending input to mad and returning it as a string
602+
if madInput:
603+
mad.input(output)
604+
return output

python_examples/hl_lhc_collisions_python/checks_and_doc/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def track_particle_sixtrack(
154154
px_tbt[:, i_part] = sixdump_part.px
155155
y_tbt[:, i_part] = sixdump_part.y
156156
py_tbt[:, i_part] = sixdump_part.py
157-
zeta_tbt[:, i_part] = sixdump_part.zeta
157+
zeta_tbt[:, i_part] = sixdump_part.tau * sixdump_part.beta0
158158
delta_tbt[:, i_part] = sixdump_part.delta
159159

160160
extra = {}

python_examples/hl_lhc_collisions_python/checks_and_doc/install_miniconda.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ pip install cpymad
77
pip install xsuite
88
git clone [email protected]:lhcopt/lhcerrors.git
99
git clone [email protected]:lhcopt/lhctoolkit.git
10-
git clone [email protected]:lhcopt/lhcmask.git
10+
git clone [email protected]:lhcopt/lhcmask.git
11+
git clone [email protected]:lhcopt/beambeam_macros.git
12+
cd beambeam_macros
13+
gfortran headonslice.f -o headonslice
14+
cd ..
1115
cd lhcmask
12-
git checkout release/v1.3.0
16+
git checkout release/v1.3.1
1317
pip install -e .
1418
cd ../
1519
git clone https://github.com/PyCOMPLETE/FillingPatterns.git
1620
pip install ./FillingPatterns
17-
python -m pip install sixtracktools
18-
python -m pip install NAFFlib
21+
python -m pip install sixtracktools
22+
python -m pip install NAFFlib

python_examples/hl_lhc_collisions_python/checks_and_doc/t005_check_crabs.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
phi_weak = Phi
2222
phi_c_weak = Phi_c
2323

24-
# # B1 ip1
25-
# beam_track = 'b1'
26-
# ip_choice = 1
27-
# plane = 'x'
28-
# phi_weak = Phi
29-
# phi_c_weak = Phi_c
30-
31-
# # B4 ip5
32-
# beam_track = 'b4'
33-
# ip_choice = 5
34-
# plane = 'y'
35-
# phi_weak = Phi
36-
# phi_c_weak = Phi_c
37-
38-
# # B4 ip1
39-
# beam_track = 'b4'
40-
# ip_choice = 1
41-
# plane = 'x'
42-
# phi_weak = -Phi
43-
# phi_c_weak = -Phi_c
24+
# B1 ip1
25+
beam_track = 'b1'
26+
ip_choice = 1
27+
plane = 'x'
28+
phi_weak = Phi
29+
phi_c_weak = Phi_c
30+
31+
# B4 ip5
32+
beam_track = 'b4'
33+
ip_choice = 5
34+
plane = 'y'
35+
phi_weak = Phi
36+
phi_c_weak = Phi_c
37+
38+
# B4 ip1
39+
beam_track = 'b4'
40+
ip_choice = 1
41+
plane = 'x'
42+
phi_weak = -Phi
43+
phi_c_weak = -Phi_c
4444

4545
phi_strong = -phi_weak
4646
phi_c_strong = -phi_c_weak
@@ -60,7 +60,7 @@ def prepare_line(path, input_type):
6060
elif input_type == 'sixtrack':
6161
print('Build xsuite from sixtrack input:')
6262
sixinput_test = sixtracktools.sixinput.SixInput(path)
63-
ltest = xt.Line.from_sixinput(sixinput_test)
63+
ltest = sixinput_test.generate_xtrack_line()
6464
print('Done')
6565
else:
6666
raise ValueError('What?!')

python_examples/hl_lhc_collisions_python/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Links to be made for tools and scripts
22
links:
3-
tracking_tools: /afs/cern.ch/eng/tracking-tools
3+
tracking_tools: auto
44
modules: tracking_tools/modules
55
tools: tracking_tools/tools
66
beambeam_macros: tracking_tools/beambeam_macros

python_examples/ions_python/checks_and_doc/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def track_particle_sixtrack(
154154
px_tbt[:, i_part] = sixdump_part.px
155155
y_tbt[:, i_part] = sixdump_part.y
156156
py_tbt[:, i_part] = sixdump_part.py
157-
zeta_tbt[:, i_part] = sixdump_part.zeta
157+
zeta_tbt[:, i_part] = sixdump_part.tau * sixdump_part.beta0
158158
delta_tbt[:, i_part] = sixdump_part.delta
159159

160160
extra = {}

python_examples/run3_collisions_python/checks_and_doc/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def track_particle_sixtrack(
154154
px_tbt[:, i_part] = sixdump_part.px
155155
y_tbt[:, i_part] = sixdump_part.y
156156
py_tbt[:, i_part] = sixdump_part.py
157-
zeta_tbt[:, i_part] = sixdump_part.zeta
157+
zeta_tbt[:, i_part] = sixdump_part.tau * sixdump_part.beta0
158158
delta_tbt[:, i_part] = sixdump_part.delta
159159

160160
extra = {}

python_examples/run3_collisions_python/checks_and_doc/t008_check_against_sixtrack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
print(x_tbt_sixtrack)
4545

4646
assert np.allclose(tracker.record_last_track.x[0, :], x_tbt_sixtrack[:,0],
47-
rtol=1e-15, atol=9e-11)
47+
rtol=1e-14, atol=9e-10)
4848
assert np.allclose(tracker.record_last_track.y[0, :], y_tbt_sixtrack[:,0],
49-
rtol=1e-15, atol=15e-11)
49+
rtol=1e-14, atol=9e-10)
5050
assert np.allclose(tracker.record_last_track.delta[0, :], delta_tbt_sixtrack[:,0],
51-
rtol=1e-15, atol=5e-11)
51+
rtol=1e-14, atol=5e-10)

python_examples/run3_collisions_wire/000_Q4LR.ipynb

Lines changed: 472 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)