Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge_consecutive_drifts() can prevent aperture misalignment #42

Closed
roman-martin opened this issue Jan 15, 2020 · 1 comment · Fixed by #60
Closed

merge_consecutive_drifts() can prevent aperture misalignment #42

roman-martin opened this issue Jan 15, 2020 · 1 comment · Fixed by #60

Comments

@roman-martin
Copy link

Example assumes #38 to be fixed

import cpymad.madx
import pysixtrack

# code from help(pysixtrack.Line.apply_madx_errors) with minimal madx sequence
madx = cpymad.madx.Madx()
madx.input('''
    !----EXAMPLE----------------------------------------------------------------
    MQ1: Quadrupole, K1:=KQ1, L=1.0;
    MQ2: Quadrupole, K1:=KQ2, L=1.0, apertype=circle, aperture=0.2;

    KQ1 = 0.02;
    KQ2 = -0.02;

    testseq: SEQUENCE, l = 20.0;
        MQ1, at = 5;
        MQ2, at=18;
    ENDSEQUENCE;

    !---the usual stuff
    BEAM, PARTICLE=PROTON, ENERGY=7000.0, EXN=2.2e-6, EYN=2.2e-6;
    USE, SEQUENCE=testseq;


    Select, flag=makethin, pattern="MQ2", slice=2;
    makethin, sequence=testseq, style=collim;

    use, sequence=testseq;

    !---misalign collimator
    select, flag = error, clear;
    select, flag = error, pattern = "MQ2";
    ealign, dx=-0.04;

    !---/EXAMPLE----------------------------------------------------------------
''')
seq = madx.sequence.testseq
madx.command.esave(file='lattice_errors.err')
madx.command.readtable(file='lattice_errors.err', table="errors")
errors = madx.table.errors
pysixtrack_line = pysixtrack.Line.from_madx_sequence(seq,install_apertures=True)
pysixtrack_line.merge_consecutive_drifts(inplace=True);
pysixtrack_line.apply_madx_errors(errors)

print('\n')
print('Line content:')
for name,element in zip(pysixtrack_line.element_names,pysixtrack_line.elements):
    print("{0:30} : {1}".format(name,element))

The example creates a sliced quad that has a marker with an aperture in the middle. If merge_consecutive_drifts() is called before apply_madx_errors() the centre aperture is not misaligned because the corresponding zero-length drift is gone.

Solution: either search for aperture markers if an element is not found, or make sure that zero length drifts are only removed after applying errors.

@aoeftiger
Copy link

I believe we should only allow the order where mad-x errors are applied first.

pysixtrack_line.apply_madx_errors(errors)
pysixtrack_line.merge_consecutive_drifts(inplace=True);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants