From 30b4a33ffd03678523a8867d29ab9bb74a3b592d Mon Sep 17 00:00:00 2001 From: Sven Date: Mon, 4 May 2026 16:19:43 +0200 Subject: [PATCH] Added matching into Porthos for P-cube experiment --- .../Reference-SwissFEL/matchPorthos.madx | 50 +++++++++++++++++++ matchmaker.py | 19 ++++++- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 Scripts/Current/Reference-SwissFEL/matchPorthos.madx diff --git a/Scripts/Current/Reference-SwissFEL/matchPorthos.madx b/Scripts/Current/Reference-SwissFEL/matchPorthos.madx new file mode 100644 index 0000000..8d89fa0 --- /dev/null +++ b/Scripts/Current/Reference-SwissFEL/matchPorthos.madx @@ -0,0 +1,50 @@ +use,sequence=swissfel; +Print,text='MATCH POINT: Match into Porthos switchyard'; +MATCH,SEQUENCE=swissfel,range=s20SY02$start/sarma02$start,beta0=twisssep; +VARY,NAME=sposy01.mqua030.k1,STEP=0.0001; +VARY,NAME=sposy01.mqua060.k1,STEP=0.0001; +VARY,NAME=sposy01.mqua100.k1,STEP=0.0001; +VARY,NAME=sposy01.mqua130.k1,STEP=0.0001; +CONSTRAINT,SEQUENCE=swissfel,range=sposy01.dbpm080$end, dx = -0.2; +CONSTRAINT,SEQUENCE=swissfel,range=sposy01.dbpm080$end, dpx = 0; +CONSTRAINT,SEQUENCE=swissfel,range=sposy01$end, dx = 0.; +CONSTRAINT,SEQUENCE=swissfel,range=sposy01$end, dpx = 0; +LMDIF,CALLS=100,TOLERANCE=1.e-21; +ENDMATCH; + +twiss,sequence=swissfel,range=s20SY02$start/sposy01$end,beta0=twisssep; +plot,haxis=s,vaxis=betx,bety,range=S30CB15$START/sposy01$end,colour=100; + +Print,text='MATCH POINT: Match symmetric optics in Porthos switchyard'; +MATCH,SEQUENCE=swissfel,range=s20SY02$start/sposy02$start,beta0=twisssep; +VARY,NAME=s30cb12.mqua430.k1,STEP=0.0001,lower=-1,upper=1; +VARY,NAME=s30cb13.mqua430.k1,STEP=0.0001,lower=-1,upper=1; +VARY,NAME=s30cb14.mqua430.k1,STEP=0.0001,lower=-1,upper=1; +VARY,NAME=s30cb15.mqua430.k1,STEP=0.0001,lower=-1,upper=1; +CONSTRAINT,SEQUENCE=swissfel,range=sposy01.dbpm080$end, alfx = 0; +CONSTRAINT,SEQUENCE=swissfel,range=sposy01.dbpm080$end, alfy =0; +CONSTRAINT,SEQUENCE=swissfel,range=s30cb15.mqua430$end, betx < 10; +CONSTRAINT,SEQUENCE=swissfel,range=s30cb15.mqua430$end, bety < 80; +LMDIF,CALLS=100,TOLERANCE=1.e-21; +ENDMATCH; + +sposy02.mqua010.k1=-2.5; +sposy02.mqua110.k1=2.5; +sposy03.mqua020.k1=-2; +sposy03.mqua120.k1=2; +sposy03.mqua220.k1=0; +use,sequence=swissfel; + +Print,text='MATCH POINT: Match onto SPOP301-Screen'; +MATCH,SEQUENCE=swissfel,range=s20SY02$start/spop301$end,beta0=twisssep; +VARY,NAME=sposy03.mqua020.k1,STEP=0.0001,lower=-3,upper=3; +VARY,NAME=sposy03.mqua120.k1,STEP=0.0001,lower=-3,upper=3; +CONSTRAINT,SEQUENCE=swissfel,range=spop301.dscr002.mark, betx = 10000; +CONSTRAINT,SEQUENCE=swissfel,range=spop301.dscr002.mark, bety = 10000; + +LMDIF,CALLS=100,TOLERANCE=1.e-21; +ENDMATCH; + +twiss,sequence=swissfel,range=s20SY02$start/spop301$end,beta0=twisssep; +plot,haxis=s,vaxis=betx,bety,range=S30CB12$START/spop301$end,colour=100; +plot,haxis=s,vaxis=dx,dy,range=S30CB12$START/spop301$end,colour=100; diff --git a/matchmaker.py b/matchmaker.py index fb333a4..0b32f7d 100644 --- a/matchmaker.py +++ b/matchmaker.py @@ -50,6 +50,7 @@ class MatchMaker: self.filter['injector']='s[i1].*k[12]|s20cb.*k1|s20sy01.*k1' self.filter['athos']='sat.*mqua.*k1|sat.*msex.*k2|s20sy02.*m[kq]' self.filter['aramis'] = 's[3a][0r].*k[12]|s20sy03.*k1' + self.filter['porthos'] = 'spo.*k[12]' with open(file,'r') as f: lines = f.readlines() for line in lines: @@ -88,6 +89,8 @@ class MatchMaker: os.chdir(self.scriptdir) if Athos: target = 'SATBD02' + elif Porthos: + target = 'SPOP301' else: target = 'SARBD02' @@ -117,7 +120,7 @@ class MatchMaker: if Aramis: f.truncate(0) print('Matching Aramis ...') - if target=='SATBD02': + if target=='SATBD02' or target=='SPOP301': target = 'SARUN20' om.setBranch(target, 'SINLH01') madx.updateLattice(om, target) # write lattice @@ -126,8 +129,20 @@ class MatchMaker: madx.madx.call('matchAramis.madx') self.updateOnlineModel(om, madx.madx, self.filter['aramis']) self.parseMatchOutput(f.getvalue().split('\n'), 'Aramis') - os.chdir(cwd) + if Porthos: + f.truncate(0) + print('Matching Porthos ...') + if target == 'SATBD02' or target == 'SARUN20': + target = 'SPOP301' + om.setBranch(target, 'SINLH01') + madx.updateLattice(om, target) # write lattice + madx.commonHeader('SwissFEL', '#s/#e', None) # sets header + madx.madx.call('initTwiss.madx') + madx.madx.call('matchPorthos.madx') + self.updateOnlineModel(om, madx.madx, self.filter['porthos']) + self.parseMatchOutput(f.getvalue().split('\n'), 'Porthos') + os.chdir(cwd) return madx.madx.table.twiss def parseMatchOutput(self, result,prefix,full=False):