atcollab / at

Accelerator Toolbox
Apache License 2.0
48 stars 31 forks source link

Also scaling families in tune and chromaticity fits #783

Closed swhite2401 closed 2 weeks ago

swhite2401 commented 2 weeks ago

This PR introduces the possibility to fit tunes and chromaticities by scaling the families instead of adding a delta. This is useful in case a family is defined with several magnet types in order to keep their ratio constant. The default behavior is unchanged

swhite2401 commented 2 weeks ago

Here is the code used to test it

import numpy
import at

path = '../lattice/'
filename = 'S28F.mat'
key = 'LOW_EMIT_RING_INJ'
latticef = path+filename
ring = at.load_lattice(latticef,key=key)
ring.radiation_off()

print(ring.get_tune(get_integer=True))
print(ring.get_chrom())

d0 = {}
for e in ring['QF1*']:
    d0[e.FamName] = e.PolynomB[1]
for e in ring['QD2*']:
    d0[e.FamName] = e.PolynomB[1]
for e in ring['S[FD]*']:
    d0[e.FamName] = e.PolynomB[2]

at.fit_tune(ring, 'QF1*', 'QD2*', [76.18, 27.34])
at.fit_chrom(ring, 'SF*', 'SD*', [0.0, 0.0])

print(ring.get_tune(get_integer=True))
print(ring.get_chrom())

d = {}
for e in ring['QF1*']:
    d[e.FamName] = e.PolynomB[1]
for e in ring['QD2*']:
    d[e.FamName] = e.PolynomB[1]
for e in ring['S[FD]*']:
    d[e.FamName] = e.PolynomB[2]

for k in d0.keys():
    print(k, d0[k]/d[k])

ring = at.load_lattice(latticef,key=key)
ring.radiation_off()

d0 = {}
for e in ring['QF1*']:
    d0[e.FamName] = e.PolynomB[1]
for e in ring['QD2*']:
    d0[e.FamName] = e.PolynomB[1]
for e in ring['S[FD]*']:
    d0[e.FamName] = e.PolynomB[2]

at.fit_tune(ring, 'QF1*', 'QD2*', [76.18, 27.34], scaling=True)
at.fit_chrom(ring, 'SF*', 'SD*', [0.0, 0.0], scaling=True)

print(ring.get_tune(get_integer=True))
print(ring.get_chrom())

d = {}
for e in ring['QF1*']:
    d[e.FamName] = e.PolynomB[1]
for e in ring['QD2*']:
    d[e.FamName] = e.PolynomB[1]
for e in ring['S[FD]*']:
    d[e.FamName] = e.PolynomB[2]

for k in d0.keys():
    print(k, d0[k]/d[k])
simoneliuzzo commented 2 weeks ago

dear @swhite2401 this works perfectly for me!

simoneliuzzo commented 2 weeks ago

The same applies for chromaticity?

swhite2401 commented 2 weeks ago

Yes the same applies for chromaticity

simoneliuzzo commented 1 week ago

Tested also for chromaticity, I approve!