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

DX,DY misalingments are not properly assigned to sliced elements #38

Closed
roman-martin opened this issue Jan 9, 2020 · 2 comments
Closed

Comments

@roman-martin
Copy link

The following example assumes #34 is 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;

    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="MQ1", slice=2;
    makethin, sequence=testseq;

    use, sequence=testseq;

    !---misalign collimator
    select, flag = error, clear;
    select, flag = error, pattern = "MQ1";
    ealign, dx :=  0.01, dy :=0.01;
    select, flag = error, clear;
    select, flag = error, pattern = "MQ2";
    ealign, dx :=  0.02, dy :=0.02;
    select, flag = error, full;

    !---/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.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 generates a MAD-X sequence with misaligned quadrupoles and transfers everything to pysixtrack. In the end it outputs the line (element_names and elements).
MQ1 is sliced into multiple slices, MQ2 is a single multipole.

You can see that the DX and DY misalignments of the multi-slice quadrupole are assigned to the start marker and twice to the first slice while the single slice quadrupole is misaligned properly.

@roman-martin
Copy link
Author

I looked a little into this and the problem seems to be the use of element vs element_name
apply_madx_errors(): element_name -> element
add_offset_error_to(element): element -> idx_el
However, the intermittent element is not unique for slices and any kind of marker, so the first marker gets every offset for markers the first multipole slice gets every offset for similar multipoles, etc.

@aoeftiger
Copy link

fixed by PR #37 , follow-up discussion how to handle general multiple occurrences of the same name posted as a new issue: #52

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

No branches or pull requests

2 participants