예제 #1
0
def sigma(deltafamilies):
#########################
    global betx, bety, gamma, ex, ey, SF1, SD0, order 
    #not necessary since no longer calling function
    
    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt
    
    SF1 = 0
    SD0 = 0
    order = 3
    gaussian = False    
    betx=64.99988501
    bety=17.99971417
    gamma=3e6
    ex=68e-8
    ey=2e-8
    
    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()
    t0.elems[74].K2L = SF1
    t0.elems[82].K2L = SD0
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    
    print 'Deltafamilies = ', deltafamilies
    t0.elems[74].K2L = deltafamilies[0]
    t0.elems[82].K2L = deltafamilies[1]
    print 'SF1 =',t0.elems[74].K2L, 'and SD0 = ', t0.elems[82].K2L
    sigmaFFS = [sqrt(ex*betx/gamma), sqrt(ex/betx/gamma), sqrt(ey*bety/gamma), sqrt(ey/bety/gamma), 0.01, 0.002]
    return(sqrt(m0.sigma('x', sigmaFFS, gaussian).real))
예제 #2
0
def siglength(deltafamilies):
    #########################
    global betx, bety, gamma, ex, ey, SF1, SD0
    #not necessary since no longer calling function

    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt

    order = 9

    gaussian = False
    betx = 64.99988501
    bety = 17.99971417
    gamma = 3e6
    ex = 68e-8
    ey = 2e-8

    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()

    sext = [24, 38, 43, 74, 82]
    pos = [0] * 5
    for i in range(0, len(sext)):
        while deltafamilies[i] < -1 * t0.elems[
                sext[i] - 1].L or deltafamilies[i] > t0.elems[sext[i] + 1].L:
            deltafamilies[i] = deltafamilies[i] / 2
            print "Adjusting guess for sextupole", sext[i]
        sys.stdout.flush()
        t = t0.alterElem(sext[i], dPos=deltafamilies[i])
        if t is None:
            break
            print "Position for ", i, " is outside drifts."
        else:
            t0 = t
    #print 'Deltafamilies = ', deltafamilies
    #print "positions are", pos
    #for i in [24, 38, 43, 74, 82]:
    #    print 'Position of element', i, ' = ', t0.elems[i].S
    #for i in [24, 30, 31, 32, 43, 49, 74, 82]:
    #    print 'Strength of element', i, ' = ', t0.elems[i].K2L

    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    sigmaFFS = [
        sqrt(ex * betx / gamma),
        sqrt(ex / betx / gamma),
        sqrt(ey * bety / gamma),
        sqrt(ey / bety / gamma), 0.01, 0.002
    ]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9  #sigmaFFS[0]
    j0 = 1e-9  #sigmaFFS[2]

    chi = (h - h0)**2 / 40**2 + (j - j0)**2
    print 'chi2 = ', chi

    return ((h - h0)**2 / 40**2 + (j - j0)**2)
예제 #3
0
def siglength(deltafamilies):
#########################
    global betx, bety, gamma, ex, ey, SF1, SD0 
    #not necessary since no longer calling function
    
    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt
    
    order = 3
    
    gaussian = False    
    betx=64.99988501
    bety=17.99971417
    gamma=3e6
    ex=68e-8
    ey=2e-8
    
    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()
    
    sext = [24, 38, 43, 74, 82] 
    pos = [0]*5
    for i in range(0, len(sext)):
        while deltafamilies[i] < -1*t0.elems[sext[i]-1].L or deltafamilies[i] > t0.elems[sext[i]+1].L:       
            deltafamilies[i] = deltafamilies[i]/2
            print "Adjusting guess for sextupole", sext[i]
        sys.stdout.flush()
        t = t0.alterElem(sextlen[i], dPos = deltafamilies[i])
        if t is None:
            break
            print "Position for ",i," is outside drifts."
        else:
            t0 = t
    #print 'Deltafamilies = ', deltafamilies
            #print "positions are", pos
    #for i in [24, 38, 43, 74, 82]:
    #    print 'Position of element', i, ' = ', t0.elems[i].S
    #for i in [24, 30, 31, 32, 43, 49, 74, 82]:
    #    print 'Strength of element', i, ' = ', t0.elems[i].K2L    
        
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    sigmaFFS = [sqrt(ex*betx/gamma), sqrt(ex/betx/gamma), sqrt(ey*bety/gamma), sqrt(ey/bety/gamma), 0.01, 0.002]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9 #sigmaFFS[0]
    j0 = 1e-9  #sigmaFFS[2]

    chi = (h-h0)**2/40**2 + (j-j0)**2
    print 'chi2 = ',chi
    #for i in range(1,6):
     #   M = Map2(t0, terr=None, order = i, nbProc = 2)
     #   H = sqrt(M.sigma('x', sigmaFFS, gaussian).real)
     #   J = sqrt(M.sigma('y', sigmaFFS, gaussian).real)
     #   hit = (H-h0)**2/40**2 + (J-j0)**2
     #   print "order = ", i, "chi = ", hit
    return((h-h0)**2/40**2 + (j-j0)**2)
예제 #4
0
파일: simplex5.py 프로젝트: pylhc/MapClass2
def sigma(deltafamilies):
    #########################
    #global betx, bety, gamma, ex, ey, SF1, SD0
    #not necessary since no longer calling function

    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt

    order = 9

    gaussian = False
    betx = 64.99988501
    bety = 17.99971417
    gamma = 3e6
    ex = 68e-8
    ey = 2e-8

    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()
    sext = [24, 38, 43, 74, 82]
    positions = [
        -0.19078705557404368, -0.071001213587260539, 0.066302461879649,
        -0.011871072667854801, -0.0097637289616161835
    ]
    #    for i in range(0, len(positions)):
    #        t0.elems[sext[i]].S = t0.elems[sext[i]].S + positions[i]

    print 'Deltafamilies = ', deltafamilies
    t0.elems[24].K2L = deltafamilies[0]
    t0.elems[30].K2L = deltafamilies[1]
    t0.elems[31].K2L = deltafamilies[2]
    t0.elems[32].K2L = deltafamilies[3]
    t0.elems[38].K2L = deltafamilies[4]
    t0.elems[43].K2L = deltafamilies[5]
    t0.elems[49].K2L = deltafamilies[6]
    t0.elems[74].K2L = deltafamilies[7]
    t0.elems[82].K2L = deltafamilies[8]
    #for i in [24, 38, 43, 74, 82]:
    #    print 'Position of element', i, ' = ', t0.elems[i].S
    #for i in [24, 30, 31, 32, 43, 49, 74, 82]:
    #    print 'Strength of element', i, ' = ', t0.elems[i].K2L
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    #print 'SF1 =',t0.elems[74].K2L, 'and SD0 = ', t0.elems[82].K2L
    sigmaFFS = [
        sqrt(ex * betx / gamma),
        sqrt(ex / betx / gamma),
        sqrt(ey * bety / gamma),
        sqrt(ey / bety / gamma), 0.01, 0.002
    ]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9  #sigmaFFS[0]
    j0 = 1e-9  #sigmaFFS[2]
    chi = (h - h0)**2 / 40**2 + (j - j0)**2
    print 'chi2 = ', chi, 'sig x = ', h, 'sig y = ', j
    return ((h - h0)**2 / 40**2 + (j - j0)**2)
예제 #5
0
  def setUp(self):
    from metaclass2 import twiss2

    for root, subFolders, files in os.walk('assets/twiss/'):
      if 'twiss' in files and 'fort.18' in files:
        print "\nTesting: ", root
        twissfile = os.path.join(root, "twiss")
        fortfile = os.path.join(root, "fort.18")
        self.t = twiss2(twissfile)
        self.m = Map2(self.t)
        self.mm = Map2(filename=fortfile)
예제 #6
0
def sigma(deltafamilies):
#########################
    #global betx, bety, gamma, ex, ey, SF1, SD0
    #not necessary since no longer calling function
    
    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt
    
    order = 9
    
    gaussian = False    
    betx=64.99988501
    bety=17.99971417
    gamma=3e6
    ex=68e-8
    ey=2e-8
    
    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()
    sext = [24, 38, 43, 74, 82] 
    positions =  [-0.19078705557404368, -0.071001213587260539, 0.066302461879649, -0.011871072667854801, -0.0097637289616161835]
#    for i in range(0, len(positions)):
#        t0.elems[sext[i]].S = t0.elems[sext[i]].S + positions[i]
    
 
    print 'Deltafamilies = ', deltafamilies
    t0.elems[24].K2L = deltafamilies[0]
    t0.elems[30].K2L = deltafamilies[1]
    t0.elems[31].K2L = deltafamilies[2]
    t0.elems[32].K2L = deltafamilies[3]
    t0.elems[38].K2L = deltafamilies[4]
    t0.elems[43].K2L = deltafamilies[5]
    t0.elems[49].K2L = deltafamilies[6]
    t0.elems[74].K2L = deltafamilies[7]
    t0.elems[82].K2L = deltafamilies[8]
    #for i in [24, 38, 43, 74, 82]:
    #    print 'Position of element', i, ' = ', t0.elems[i].S
    #for i in [24, 30, 31, 32, 43, 49, 74, 82]:
    #    print 'Strength of element', i, ' = ', t0.elems[i].K2L    
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    #print 'SF1 =',t0.elems[74].K2L, 'and SD0 = ', t0.elems[82].K2L
    sigmaFFS = [sqrt(ex*betx/gamma), sqrt(ex/betx/gamma), sqrt(ey*bety/gamma), sqrt(ey/bety/gamma), 0.01, 0.002]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9 #sigmaFFS[0]
    j0 = 1e-9 #sigmaFFS[2]
    chi = (h-h0)**2/40**2 + (j-j0)**2
    print 'chi2 = ',chi, 'sig x = ', h, 'sig y = ', j
    return((h-h0)**2/40**2 + (j-j0)**2)
예제 #7
0
def duo(deltafamilies):
#########################
    #global betx, bety, gamma, ex, ey, SF1, SD0
    #not necessary since no longer calling function
    
    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt
    
    order = 8
    
    gaussian = False    
    betx=64.99988501
    bety=17.99971417
    gamma=3e6
    ex=68e-8
    ey=2e-8
    
    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()

    sextlen = [24, 38, 43, 74, 82]
    sextstr = [24, 30, 31, 32, 38, 43, 49, 74, 82]
 
    for i in range(0, len(sextlen)):
        while deltafamilies[i] < -1*t0.elems[sextlen[i]-1].L or deltafamilies[i] > t0.elems[sextlen[i]+1].L:       
            deltafamilies[i] = deltafamilies[i]/2
            print "Adjusting guess for sextupole", sextlen[i]
        sys.stdout.flush()
        t = t0.alterElem(sextlen[i], dPos = deltafamilies[i])
        if t is None:
            break
            print "Position for ",i," is outside drifts."
        else:
            t0 = t
            
    for i in range(0, len(sextstr)):
        t0.elems[sextstr[i]].K2L = deltafamilies[i+5]
        
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    #print 'SF1 =',t0.elems[74].K2L, 'and SD0 = ', t0.elems[82].K2L
    sigmaFFS = [sqrt(ex*betx/gamma), sqrt(ex/betx/gamma), sqrt(ey*bety/gamma), sqrt(ey/bety/gamma), 0.01, 0.002]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9 #sigmaFFS[0]
    j0 = 1e-9 #sigmaFFS[2]
    
    chi = (h-h0)**2/40**2 + (j-j0)**2
    print 'chi2 = ', chi
    return((h-h0)**2/40**2 + (j-j0)**2)
예제 #8
0
def sigma(deltafamilies):
    #########################
    global betx, bety, gamma, ex, ey, SF1, SD0
    #not necessary since no longer calling function

    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt

    order = 3

    gaussian = False
    betx = 64.99988501
    bety = 17.99971417
    gamma = 3e6
    ex = 68e-8
    ey = 2e-8

    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()

    #print 'Deltafamilies = ', deltafamilies
    t0.elems[24].K2L = deltafamilies[0]
    t0.elems[30].K2L = deltafamilies[1]
    t0.elems[31].K2L = deltafamilies[2]
    t0.elems[32].K2L = deltafamilies[3]
    t0.elems[38].K2L = deltafamilies[4]
    t0.elems[43].K2L = deltafamilies[5]
    t0.elems[49].K2L = deltafamilies[6]
    t0.elems[74].K2L = deltafamilies[7]
    t0.elems[82].K2L = deltafamilies[8]
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    #print 'SF1 =',t0.elems[74].K2L, 'and SD0 = ', t0.elems[82].K2L
    sigmaFFS = [
        sqrt(ex * betx / gamma),
        sqrt(ex / betx / gamma),
        sqrt(ey * bety / gamma),
        sqrt(ey / bety / gamma), 0.01, 0.002
    ]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9  #sigmaFFS[0]
    j0 = 1e-9  #sigmaFFS[2]
    chi = (h - h0)**2 / 40**2 + (j - j0)**2
    #print 'chi2 = ',chi, 'sig x = ', h, 'sig y = ', j
    return ((h - h0)**2 / 40**2 + (j - j0)**2)
예제 #9
0
def sigma(deltafamilies):
#########################
    global betx, bety, gamma, ex, ey, SF1, SD0
    #not necessary since no longer calling function
    
    from metaclass2 import twiss2
    from mapclass import Map2
    from math import sqrt
    
    order = 3
    
    gaussian = False    
    betx=64.99988501
    bety=17.99971417
    gamma=3e6
    ex=68e-8
    ey=2e-8
    
    t0 = twiss2('assets/ffs.twiss')
    t0 = t0.stripLine()
    t0 = t0.mergeElems()
 
    #print 'Deltafamilies = ', deltafamilies
    t0.elems[24].K2L = deltafamilies[0]
    t0.elems[30].K2L = deltafamilies[1]
    t0.elems[31].K2L = deltafamilies[2]
    t0.elems[32].K2L = deltafamilies[3]
    t0.elems[38].K2L = deltafamilies[4]
    t0.elems[43].K2L = deltafamilies[5]
    t0.elems[49].K2L = deltafamilies[6]
    t0.elems[74].K2L = deltafamilies[7]
    t0.elems[82].K2L = deltafamilies[8]
    m0 = Map2(t0, terr=None, order=order, nbProc=2)
    #print 'SF1 =',t0.elems[74].K2L, 'and SD0 = ', t0.elems[82].K2L
    sigmaFFS = [sqrt(ex*betx/gamma), sqrt(ex/betx/gamma), sqrt(ey*bety/gamma), sqrt(ey/bety/gamma), 0.01, 0.002]
    h = sqrt(m0.sigma('x', sigmaFFS, gaussian).real)
    j = sqrt(m0.sigma('y', sigmaFFS, gaussian).real)
    h0 = 40e-9 #sigmaFFS[0]
    j0 = 1e-9 #sigmaFFS[2]
    chi = (h-h0)**2/40**2 + (j-j0)**2
    #print 'chi2 = ',chi, 'sig x = ', h, 'sig y = ', j
    return((h-h0)**2/40**2 + (j-j0)**2)
예제 #10
0
#! /usr/bin/env python

import sys

if len(sys.argv) < 2:
    sys.stderr.write('Usage: sys.argv[0] dir')
    sys.exit(1)

sys.path.append(sys.argv[1])

from metaclass2 import twiss2
from mapclass import Map2

t = twiss2()

m = Map2(t)

mm = Map2(order=6)

v = ['x', 'px', 'y', 'py']

print mm.compc(m, v).real
예제 #11
0

### Argument reading

parser = argparse.ArgumentParser(description="FFS test for MapClass2")
parser.add_argument('-o', help="Order at which run the test. Default is 3 (for fast results), 6 would be in the order of 3 minutes.",
                    type=int, default=3, dest='order')
parser.add_argument('-g', help="Run with Gaussian Delta or not. By default it doesn't",
                    action='store_true', dest='gaussian')
parser.add_argument('-n', help="How many cores to run on. By default it is 1",
                    type=int, default=1, dest='nbProc')                    
                    

args = parser.parse_args()

t = twiss2('assets/ffs.twiss')
t = t.stripLine()
t = t.mergeElems()

sext1 = [24, 38, 43, 74, 82]
sext2 = [24, 30, 31, 32, 38, 43, 49, 74, 82]

#for i in range(0, len(sext1)):
#    print t.elems[sext1[i]].S
    
positions = [0.07967687682559, 0.049979477525608, 0.052613241375277, 0.193170454943335, 0.00738902713769]
strengths = [10.2881885328145, 133.508521888545, -109.469292468306, 68.8207501444652, -5.09437310259855, 15.5187207629783, -1.27849821750552, -6.01584279027468, 21.8375550635217]

#sys.stdout.write(".")
sys.stdout.flush()
예제 #12
0
v = ['x','px','y','py']

betx=64.99988501
bety=17.99971417
gamma=3e6
ex=68e-8
ey=2e-8
sigmaFFS=[sqrt(ex*betx/gamma), sqrt(ex/betx/gamma), sqrt(ey*bety/gamma), sqrt(ey/bety/gamma), 0.01, 0.002]
###

tmpDir = "_tmp/"
filename = "sigma.dat"

fsigma = open(tmpDir + filename, 'w')

t = twiss2(path + 'doc/FFSexample/assets/ffs.twiss')

print "SLOW: Takes a while to run. Lower the upperbound of the range to 7 for faster results"

for o in range(1,8):

    print "* Order " + str(o)

    # Suppress printing
    old_stdout = sys.stdout
    sys.stdout = DummyFile()
    try:
      m = Map2(t,order=o)
    finally:
      sys.stdout = old_stdout
예제 #13
0
파일: compare.py 프로젝트: pylhc/MapClass2
                    action='store_true', dest='gaussian')
parser.add_argument('-n', help="How many cores to run on. By default it is 1",
                    type=int, default=1, dest='nbProc')                    
parser.add_argument('-m', help="Which formula to use for multipoles",
                    type=int, default=0, dest='fmultipole')
parser.add_argument('-ns', help="Do not strip the line of unused elements (MATRIX, MONITOR, MARKER): default true",
                    action='store_false', default=True, dest='strpl')
                    

args = parser.parse_args()

### Setup

startTime = time.time()

t = twiss2('assets/ffs.twiss')
t = t.stripLine()# already done in c++ by default
t = t.mergeElems()
# The following is a call to construct the Map using the C++ Map construction from a twiss file
#m = Map2('assets/ffs.twiss',filenameerr=None, order=args.order, nbProc=args.nbProc, strpl=args.strpl) 

# The following is call to the old mapclass which uses Python map construction
#m = Map2(t, "old", order=args.order) 

# The following is a call to construct the Map from a Twiss Python object
m = Map2(t, terr=None, order=args.order, nbProc=args.nbProc, fmultipole=args.fmultipole, strpl=args.strpl)

mm = Map2(filename='assets/fort.18',order=args.order) #from fort call

v = ['x','px','y','py']
예제 #14
0
파일: test.py 프로젝트: orblancog/MapClass2
#! /usr/bin/env python

import sys

if len(sys.argv) < 2:
  sys.stderr.write('Usage: sys.argv[0] dir')
  sys.exit(1)

sys.path.append(sys.argv[1])

from metaclass2 import twiss2
from mapclass import Map2

t = twiss2()

m = Map2(t)

mm = Map2(order=6)

v = ['x','px','y','py']

print mm.compc(m,v).real
예제 #15
0
파일: errPlot.py 프로젝트: pylhc/MapClass2
ex = 68e-8
ey = 2e-8
sigmaFFS = [
    sqrt(ex * betx / gamma),
    sqrt(ex / betx / gamma),
    sqrt(ey * bety / gamma),
    sqrt(ey / bety / gamma), 0.01, 0.002
]
###

tmpDir = "_tmp/"
filename = "sigma.dat"

fsigma = open(tmpDir + filename, 'w')

t = twiss2(path + 'doc/FFSexample/assets/ffs.twiss')

print "SLOW: Takes a while to run. Lower the upperbound of the range to 7 for faster results"

for o in range(1, 8):

    print "* Order " + str(o)

    # Suppress printing
    old_stdout = sys.stdout
    sys.stdout = DummyFile()
    try:
        m = Map2(t, order=o)
    finally:
        sys.stdout = old_stdout