Dear Vadim and all,
I have been trying to correct the Elettra lattice by considering a superbend magnet in the 3 cells of the lattice (cell4, cell8, and cell12). In this case, the measured lattice is the lattice with superbends and the ideal lattice is the one without super bends. I thought that maybe I can use calculateTwissCorrection for it. Is it possible? I also try the simplex method but It doesn't work for me.
For using the claculateTwissCorrection, first I run the ideal.ele for lattice without superbend (let's call it ideal lattice: converted_ideal.lte) and the target value is generated as step1.param.
Then, I used elettra.ele file for correcting tune, chromaticity and orbit of the measured lattice (lattice with superbends: converted.lte).
In this step, I thought that by using ./runCorrection workDir pwd correctionMode beta measLatticeParamFile step3.param outputFile result.beta.param, I can correct the beta and dispersion function, but I faced a crash and error which I can't solve it. Would you mind if I can ask you to take a look at my files and tell me if the method I used is correct or not?
P.s: I used the same name for introducing superbends in the lattice, but the values for sbb1a, sbb1b, sbb2, and sbdrift are different in converted and converted_ideal lattice.
Thanks in advance,
Sara
Matching twiss function in lattice with superbends
Moderators: cyao, michael_borland
Matching twiss function in lattice with superbends
 Attachments

 calculateTwissCorrection.zip
 (8.54 MiB) Downloaded 18 times
Sara
Re: Matching twiss function in lattice with superbends
Sara,
First of all, you are correct  the twiss correction program can be used for superbend lattice correction. To do that, you need to understand a few details, which I give below.
The program calculateTwissCorrection requires many options. All those options are specified in the runCorrection script, which I created for convenience, so that you do not have to type all those options. The options that describe the ideal and measured machines are given below as they are written in the runCorrection script:
...
lteMeasured $lteFile \
beamlineMeasured $beamlineName \
paramFileListMeasured \"$measLatticeParamFile\" \
lteDesired $lteFile \
beamlineDesired $beamlineName \
paramFileListDesired \"$targetParamFileList\" \
...
As you can see, the runCorrection script uses the same .lte file $lteFile for both measured and ideal machines. However, you use different .lte files for measured and ideal machines. When the program runs converted.lte with step1.param, all SBB* elements get redefined according to values from converted_ideal.lte, but SBDRIFT does not get redefined since it is defined as EDRIFT in converted.lte and therefore does not have parameters ANGLE and K1. The resulting lattice misses focusing and bend from SBDRIFT and does not have beta functions in vertical plane. That's why you get an error.
There are 2 ways to fix it. First, you could change SBDRIFT in converted.lte file from
sbdrift : edrift, l = 0.000000
to
sbdrift : csbend, l = 0.000000
Second, you could change the options in runCorrection script to distinguish 2 different .lte files:
set lteFileIdeal $workDir/converted_ideal.lte
set lteFileMeasured $workDir/converted.lte
...
lteMeasured $lteFileMeasured \
beamlineMeasured $beamlineName \
paramFileListMeasured \"$measLatticeParamFile\" \
lteDesired $lteFileIdeal \
beamlineDesired $beamlineName \
paramFileListDesired \"$targetParamFileList\" \
...
And since your .lte files already describe the measured and ideal lattices, you do not need to supply parameter files:
...
lteMeasured $lteFileMeasured \
beamlineMeasured $beamlineName \
lteDesired $lteFileIdeal \
beamlineDesired $beamlineName \
...
After that you can run the correction program. You will see that the achieved correction is not that good. There could be a few reasons for that. I will describe below how to achieve good correction.
You can never achieve perfect beta correction on all BPMs, because close to the superbends you do not have enough correcting quadrupoles. The beta functions close to the superbends will always be different from the ideal case. This sometimes is called a beta function bump (like a closed orbit bump).
The correcting program tries to minimize rms beta function errors on all BPMs, but it can never achieve zeros on BPMs close to the superbends, so it settles with some beta functions that give minimum rms errors over all BPMs. This is not how you want to run the correction program in this case. You need to exclude BPMs that are inside the area where you cannot correct beta functions (inside the beta function bump). Then the program will be able to converge to zero beta function errors on all other BPMs. In addition, you probably don't want to use all quadrupoles for the correction  only those close to the superbends.
I suggest the following correction configuration: use only quadrupoles in cells 4, 8, and 12; and use all BPMs except BPMs in cells 4, 8, and 12. To do that, I modified the program makeElementListFile.
If you run runCorrection now, you will get an error due to wrong singular value number in the inversion of the beta function response matrix. The program uses N=80 (because there were 96 quadrupoles for the initial correction), but now we only use 24 quadrupoles, so the number has to be changed. You can plot the singular values:
sddsplot tmp/twissCorrectionMatrixFiltered.sdds.SV col=Index,SingularValues graph=sym,con mode=linlog
From this plot, the number should be 1517. The number has to be changed inside runCorrection. After that, you can successfully run the correction program. However, it still cannot reach zero beta function errors. To improve correction, I added BQF1, BQF2, BQF3, BQF4 quadrupoles to the correction. Now the correction is nearly perfect outside of cells 4, 8, 12:
sddsplot graph=line,vary col=s,etax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betay tmp/desired.twi tmp/achieved.twi
The changes I described are now included into attached runCorrection and makeElementListFile. You can play with configuration correction  include more BPMs, and may be use less quadrupoles. But every time, you need to make sure you use an appropriate SV number, which you can figure out only after you ran the correction once and plotted the singular values.
Hope this helps, do not hesitate to ask more questions.
Vadim
First of all, you are correct  the twiss correction program can be used for superbend lattice correction. To do that, you need to understand a few details, which I give below.
The program calculateTwissCorrection requires many options. All those options are specified in the runCorrection script, which I created for convenience, so that you do not have to type all those options. The options that describe the ideal and measured machines are given below as they are written in the runCorrection script:
...
lteMeasured $lteFile \
beamlineMeasured $beamlineName \
paramFileListMeasured \"$measLatticeParamFile\" \
lteDesired $lteFile \
beamlineDesired $beamlineName \
paramFileListDesired \"$targetParamFileList\" \
...
As you can see, the runCorrection script uses the same .lte file $lteFile for both measured and ideal machines. However, you use different .lte files for measured and ideal machines. When the program runs converted.lte with step1.param, all SBB* elements get redefined according to values from converted_ideal.lte, but SBDRIFT does not get redefined since it is defined as EDRIFT in converted.lte and therefore does not have parameters ANGLE and K1. The resulting lattice misses focusing and bend from SBDRIFT and does not have beta functions in vertical plane. That's why you get an error.
There are 2 ways to fix it. First, you could change SBDRIFT in converted.lte file from
sbdrift : edrift, l = 0.000000
to
sbdrift : csbend, l = 0.000000
Second, you could change the options in runCorrection script to distinguish 2 different .lte files:
set lteFileIdeal $workDir/converted_ideal.lte
set lteFileMeasured $workDir/converted.lte
...
lteMeasured $lteFileMeasured \
beamlineMeasured $beamlineName \
paramFileListMeasured \"$measLatticeParamFile\" \
lteDesired $lteFileIdeal \
beamlineDesired $beamlineName \
paramFileListDesired \"$targetParamFileList\" \
...
And since your .lte files already describe the measured and ideal lattices, you do not need to supply parameter files:
...
lteMeasured $lteFileMeasured \
beamlineMeasured $beamlineName \
lteDesired $lteFileIdeal \
beamlineDesired $beamlineName \
...
After that you can run the correction program. You will see that the achieved correction is not that good. There could be a few reasons for that. I will describe below how to achieve good correction.
You can never achieve perfect beta correction on all BPMs, because close to the superbends you do not have enough correcting quadrupoles. The beta functions close to the superbends will always be different from the ideal case. This sometimes is called a beta function bump (like a closed orbit bump).
The correcting program tries to minimize rms beta function errors on all BPMs, but it can never achieve zeros on BPMs close to the superbends, so it settles with some beta functions that give minimum rms errors over all BPMs. This is not how you want to run the correction program in this case. You need to exclude BPMs that are inside the area where you cannot correct beta functions (inside the beta function bump). Then the program will be able to converge to zero beta function errors on all other BPMs. In addition, you probably don't want to use all quadrupoles for the correction  only those close to the superbends.
I suggest the following correction configuration: use only quadrupoles in cells 4, 8, and 12; and use all BPMs except BPMs in cells 4, 8, and 12. To do that, I modified the program makeElementListFile.
If you run runCorrection now, you will get an error due to wrong singular value number in the inversion of the beta function response matrix. The program uses N=80 (because there were 96 quadrupoles for the initial correction), but now we only use 24 quadrupoles, so the number has to be changed. You can plot the singular values:
sddsplot tmp/twissCorrectionMatrixFiltered.sdds.SV col=Index,SingularValues graph=sym,con mode=linlog
From this plot, the number should be 1517. The number has to be changed inside runCorrection. After that, you can successfully run the correction program. However, it still cannot reach zero beta function errors. To improve correction, I added BQF1, BQF2, BQF3, BQF4 quadrupoles to the correction. Now the correction is nearly perfect outside of cells 4, 8, 12:
sddsplot graph=line,vary col=s,etax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betay tmp/desired.twi tmp/achieved.twi
The changes I described are now included into attached runCorrection and makeElementListFile. You can play with configuration correction  include more BPMs, and may be use less quadrupoles. But every time, you need to make sure you use an appropriate SV number, which you can figure out only after you ran the correction once and plotted the singular values.
Hope this helps, do not hesitate to ask more questions.
Vadim
 Attachments

 modifiedScripts.tar
 (10 KiB) Downloaded 12 times
Re: Matching twiss function in lattice with superbends
Dear Vadim,
It is amazing. Thanks a lot for the complete explanation of the procedure of correction and the details of it. It is also great that I understood what was the origin of the error that I faced. I did it and as you said the correction looks perfect.
Regards,
Sara
It is amazing. Thanks a lot for the complete explanation of the procedure of correction and the details of it. It is also great that I understood what was the origin of the error that I faced. I did it and as you said the correction looks perfect.
Regards,
Sara
Sara
Re: Matching twiss function in lattice with superbends
Dear Vadim,
I tried to correct the superbend lattice without using inverse bends (BQF1, BQF2, BQF3, and BQF4), and instead use sbb1a and sbb1b in the 4th, 8th, and 12th cells. I assumed that in this case, I should make changes on the makeElementListFile, and I can make the element list, but by using the runCorrection command I faced an error. Would you mind if I ask you to take a look at my file and let me know what is the problem with my calculation?
Regards,
Sara
I tried to correct the superbend lattice without using inverse bends (BQF1, BQF2, BQF3, and BQF4), and instead use sbb1a and sbb1b in the 4th, 8th, and 12th cells. I assumed that in this case, I should make changes on the makeElementListFile, and I can make the element list, but by using the runCorrection command I faced an error. Would you mind if I ask you to take a look at my file and let me know what is the problem with my calculation?
Regards,
Sara
 Attachments

 correction.zip
 (2.04 KiB) Downloaded 17 times
Sara
Re: Matching twiss function in lattice with superbends
Sara,
The correction program uses tag names for all elements. The tag names are built as <elementname>#<elementoccurence>. For example, BQF1#3 is the third occurrence of BQF1 in the beamline.
Your present lappend command adds SBB1A#4, SBB1A#8, and SBB1A#12 (and same for SBB1B). But there are only 3 SBB1A and 3 SBB1B magnets in the beamline. The program cannot find element SBB1A#4 and gives error. Therefore you should use the following line:
lappend quadList SBB1A#[expr $i/4] SBB1B#[expr $i/4]
This command will add SBB1A#1, SBB1A#2, and SBB1A#3 and the same for SBB1B.
I tried this correction, but results were not good. I thought that may be the problem is that SBB1A and SBB1B are very close to each other, so they might fight each other in the solution. So I used only SBB1B:
lappend quadList SBB1B#[expr $i/4]
I had to increase the number of iterations from 10 to 20: "iterations 20", because the solution first jumps to large error and then converges to good solution. So this gave very good correction outside of cells 4, 8, and 12, but inside those cells the beta functions were not that good:
sddsplot graph=line,vary col=s,etax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betay tmp/desired.twi tmp/achieved.twi
The required quadrupole corrections looked strange: large corrections on QD1/QF1 but almost nothing on SBB1B:
sddsplot result.beta.param col=TagName,ParameterValue graph=sym,con
After that, I decided to try correction without SBB1B, which is actually your initial configuration, but this time I reduced the weight of tunes in the solution:
from "set weightList "1 1 100 1000"" to "set weightList "1 1 100 10"".
I also changed SVratio to 18. Now the correction is really good, even inside cells 4, 8, and 12 it is not bad. The quadrupole corrections are also reasonable. So this is good correction configuration. The only problem left is that the tunes are not exactly what you need: Qx = 32.3217, Qy = 9.1539. You could use all other cells to correct for this small tune change. This is actually a reasonable approach: use local quadrupoles to correct for local beta function distortion, then use global quadrupole knobs to correct for the betatron tunes.
I attach my new version of the scripts.
Vadim
The correction program uses tag names for all elements. The tag names are built as <elementname>#<elementoccurence>. For example, BQF1#3 is the third occurrence of BQF1 in the beamline.
Your present lappend command adds SBB1A#4, SBB1A#8, and SBB1A#12 (and same for SBB1B). But there are only 3 SBB1A and 3 SBB1B magnets in the beamline. The program cannot find element SBB1A#4 and gives error. Therefore you should use the following line:
lappend quadList SBB1A#[expr $i/4] SBB1B#[expr $i/4]
This command will add SBB1A#1, SBB1A#2, and SBB1A#3 and the same for SBB1B.
I tried this correction, but results were not good. I thought that may be the problem is that SBB1A and SBB1B are very close to each other, so they might fight each other in the solution. So I used only SBB1B:
lappend quadList SBB1B#[expr $i/4]
I had to increase the number of iterations from 10 to 20: "iterations 20", because the solution first jumps to large error and then converges to good solution. So this gave very good correction outside of cells 4, 8, and 12, but inside those cells the beta functions were not that good:
sddsplot graph=line,vary col=s,etax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betax tmp/desired.twi tmp/achieved.twi
sddsplot graph=line,vary col=s,betay tmp/desired.twi tmp/achieved.twi
The required quadrupole corrections looked strange: large corrections on QD1/QF1 but almost nothing on SBB1B:
sddsplot result.beta.param col=TagName,ParameterValue graph=sym,con
After that, I decided to try correction without SBB1B, which is actually your initial configuration, but this time I reduced the weight of tunes in the solution:
from "set weightList "1 1 100 1000"" to "set weightList "1 1 100 10"".
I also changed SVratio to 18. Now the correction is really good, even inside cells 4, 8, and 12 it is not bad. The quadrupole corrections are also reasonable. So this is good correction configuration. The only problem left is that the tunes are not exactly what you need: Qx = 32.3217, Qy = 9.1539. You could use all other cells to correct for this small tune change. This is actually a reasonable approach: use local quadrupoles to correct for local beta function distortion, then use global quadrupole knobs to correct for the betatron tunes.
I attach my new version of the scripts.
Vadim
 Attachments

 modifiedScripts1.tar
 (10 KiB) Downloaded 15 times
Re: Matching twiss function in lattice with superbends
Dear Vadim,
Many thanks for your very kind help and detailed solution. As, you suggest I used local quads for twiss correction and global ones for correcting tunes. It seems that every thing is good and perfect now.
Regards,
Sara
Many thanks for your very kind help and detailed solution. As, you suggest I used local quads for twiss correction and global ones for correcting tunes. It seems that every thing is good and perfect now.
Regards,
Sara
Sara