I have some problems in understanding my result. In bold you can see the two questions I have for you. I will explain you briefly.
The configuration is the following:
single field map from OPERA
nominal energy: 185 MeV
RING definition + Local Cartesian Offset
Particle distribution from file
From this configuration, the beam envelope looks reasonable and agrees with COSY-Infinity.
However, the dispersion seems not to be completely suppressed at the end of the beamline. This means that I need to study more the dispersion and the off-momentum beam.
1st Analysis: Dispersion function
In the distribution file, I set one particle with 1% momentum shift (py = 1% p0) with respect to the nominal momentum. The tracking of this particle represents the dispersion function. The result is attached (Dispersion-Test1)
2nd Analysis: Off-Momentum Beam
The goal is to study the beamline behaviour with a beam that has 5% momentum shift from the nominal value. Then I have prepared a new distribution, where all the particles (except 2 particles) has a momentum shift of 5% (py = 5% p0).
In the OPAL input file, I let 185 MeV as nominal energy (EDES = 0.185), the shift in momentum comes from the beam distribution.
The two not-updated particles are:
1- reference particle: py = 0
2- dispersion function: py = 1% p0
Since the majority of the particles have a different energy, the mean beam energy has been updated to 202 MeV. Has this an influence in the tracking?
At the end of this “off-momentum run”, I displayed again the dispersion function, expecting to get the same result as in the first Analysis. The nominal energy, EDES, (185 MeV) did not change and the field map as well.
Instead I got a completely different trajectory (see Dispersion-Test2).
Which is the best way to perform this kind of analysis?
Does SBEND3D use a local coordinate system, relative to the
beginning of the element? If so, how is this coordinate system
defined?
Is the OPAL manual's description of the LENGTHUNITS correct? When
adding an SBEND3D, the diagnostic output from OPAL specifies the
lengths in both 'm' and 'mm,' it seems one of these is wrong and
confusing. I.e. zini= -1.0000000000000000e+03 m; zfinal= 1.0000000000000000e+03 mm for the input file attached.
As a test case, I have tried to propagate a beam through a simple π/6
sector (input files attached). However, the beam travels straight in
the initial direction, indicating to me that my element is either the
wrong size or placed incorrectly relative to the beam. Perhaps you can
shed some light on what I am misunderstanding about how this element
interacts with the global coordinate system.
I have repeated the same analysis with a simplified field map of a Combined Function Magnet.
Field map
Dipole angle: 120°
Nominal energy: 230 MeV (P0 = 0.74186 BetaGamma)
Hard-Edge model
1 - First analysis: nominal energy
Edes = 230 MeV
Beam distribution from file: track of a special particle -> dispersion function with 1% dp/p from the reference momentum
0.000 0.0000 0.0000 0.0074186 0.0000 0.0000
The result is
2- Second analysis: off-momentum beam
Edes = 230 MeV
Beam distribution from file: All the particles (except 2) have a shift in momentum (py = 0.100151) that corresponds to an energy of 288 MeV. The two not-shifted particles are:
Reference particle
0.0 0.0 0.0 0.0 0.0 0.0
Dispersion function defined as before. The 1% dp/p is calculated with respect to the nominal energy (230 MeV) and not to the off-energy (288 MeV)
The trajectory for the dispersion and the reference particle is shown here
Comments
In case of an off-momentum beam, the mean energy differers from EDES (set in the input file) and is correctly displayed in the cout.
The reference trajectory in the plot is not a straight line as supposed to be, but behaves as a particle with a certain momentum shift with respect to the mean evaluated energy.
In the same way, the dispersion function is supposed to be referred to the 230 MeV and to have a same behavior in both simulation.
For this sort of analysis I usually consider particles in the global frame; for analysis I handle any transformations to the local frame by hand. E.g. for the ring work I do, I usually do a transformation into cylindrical coordinate system. OPAL does all tracking in the global frame (RK4 in Cartesian coordinate system).
You hope that whatever output code will transform into some other coordinate system, maybe the coordinate system of some reference particle? How are you doing the output? What coordinate system do you want the output to be in?
For this kind of analysis, I use only the H5file: TH5Dataset data("SCGantry.h5");
For each time step t, I access to the NTuple, containing the position and the coordinates in Local Frame of a specific particle (reference or dispersion)
I was thinking to do the transformation in the data analysis too, because something is not really clear to me in the local frame statistics (see also Issue #25 (closed)).
The global frame works fine if the beam has no momentum shift and only few particles have some py-offset. In this case:
the beam energy evaluated from the distribution coincides with EDES (design energy)
the particle 0.0 0.0 0.0 0.0 0.0 0.0 corresponds to the reference particle
I could use the two or three off-momentum particles to test the achromaticity of the system. As first analysis, this is perfectly fine since I get something like Global-Frame
When I want to simulate the effect of a completely off-momentum beam and study some beam properties (beam size, position, divergence, emittance ...) then
the beam energy evaluated from the distribution does not coincides with EDES (design energy)
the particle 0.0 0.0 0.0 0.0 0.0 0.0 does not corresponds to the reference particle (as you can see from Off-Momentum-Reference)
it seems that the tracking of the particles is refererred to the new evaluated energy and not to EDES.
How would you set your input file for this kind of analysis? Assuming that 230 MeV is your nominal energy and 288 MeV the shifted beam:
I cannot upload the file here in gitlab. The field map is too huge.
I could copy them in a shared directory on Dropbox or give you access to the afs directory where I run my simulation. Please, tell me what you prefer.
If you have a PSI account, then Achim could easily give you access.
Units should be added to the H5root GUI for the REFR
SPOS indicates the bunch position always in LOCAL FRAME
It is better to keep the LCO in the beamline definition (even if it set to zero) since it create an infinite space where the particles survive -> beam is not lost at the end of the field map.
before closing the issue, I would like to understand the Reference trajectory plot. I will briefly summarize my simulation.
The plot shows the trajectory of the particle ID1 with:
(x,px,y,py,z,pz) = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
where py = 0.0 indicates that the longitudinal momentum of ID1 corresponds to the nominal beam energy Edes. So for a beam with energy Edes, the particle ID1 would be the reference particle.
However, this plot refers to a particular simulation: all the particles in the beam (except ID1) have a non-zero py. The resulting beam energy is hence different from Edes -> OPAL evaluated it properly.
After reading the particle distribution from a file, I load the magnetic field map of my beamline. The value of the magnetic field has been set in order to bend a beam with energy Edes. What I am trying to test is the effect of an off-momentum beam on the beamline.
In summary:
The magnetic field values are fixed because reading from an external field map.
The beam energy is different from the nominal Edes because of the particles shift in the py-component.
However the definition of the particle ID1 should be unchanged.
In conclusion:
Particle ID1 has the right energy, or better, the design energy of the field map.
Therefore, I don't understand why the trajectory of the ID1 is not a straight line (as, I think it should be) but this
What do you think about? I hope the situation is clear. If it is not, please, ask me again. I will try to explain it better.
I think the plot shows the position of particle with ID1 relative to the mean position and momentum of the bunch. You could try plotting the mean position of the bunch in Global coordinates, compared with the position of particle ID1, and demonstrate that they are different.
Yes, you are right. Here attached the plot in global frame:
where:
the centroid (green line) reflects the trajectory of the off-momentum beam -> OK
the ID1 (red line) reflects the trajectory of the reference particle -> OK
I think I got why in the local frame the plot is wrong: it is related on what you wrote in the Issue25: I noted that the "transform to local coordinates" algorithm transforms to the coordinate system of the ensemble mean R and P.
Of course in my case, the meanP and meanR were updated to the new shifted-beam energy and this means that the transformation global -> local returns not the expected result.
I think the better solution is to use a reference trajectory for the local frame. I can put it on my job list to change the global-to-local coordinate transform but at the moment I am full for most of the year!
documentation says:
\item[PSDUMPFRAME]
\index{OPTION!PSDUMPFRAME}
Control option that defines the frame in which the phase space data is written for h5 and stat files.
\begin{itemize}
\item \verb|GLOBAL|: data is written in the global Cartesian frame;
\item \verb|BUNCH_MEAN|: data is written in the bunch mean frame or;
\item \verb|REFERENCE|: data is written in the frame of the reference particle.
\end{itemize}
added the option: OPTION, PSDUMPFRAME = "REFERENCE"
performed data analysis with root scripts -> trajectories of:
reference particle ID1 @ 230 MeV
off-momentum: ID14 @ 288 MeV
other momentum offset: ID11 Dp/p = 10%
Summary:
In the local frame, the trajectory of a reference particle does not follow a straight line as expected. Due to #102 (closed) or to a problem related to the defined reference particle in OPAL?
In the global frame, the tracking of a reference particle follows the reference orbit as expected.
I think that the code is working. I attach 2017-04-22_local-coords.tar.gz. This file contains a lattice with 500 mm drift only. When I run the lattice in reference/bunch_mean/global mode, I get the h5 files in the tarball like
I found a python library to load h5 files, which I have used for testing. It's in the script load_h5.py. I print the x position for each setting at step 1 and step 3 respectively:
PSDumpTest_global.h5
Step#0
x 1.001
x 1.001
x 1.01
x 1.1
x 1.12
x 1.15
Step#3
x 1.001
x 1.001
x 1.01
x 1.1
x 1.12
x 1.15
PSDumpTest_reference.h5
Step#0
x 0.001
x 0.001
x 0.01
x 0.1
x 0.12
x 0.15
Step#3
x 0.001
x 0.001
x 0.01
x 0.1
x 0.12
x 0.15
PSDumpTest_bunch_mean.h5
Step#0
x -0.0625
x -0.0625
x -0.0535
x 0.0365
x 0.0565
x 0.0865
Step#3
x -0.0625
x -0.0625
x -0.0535
x 0.0365
x 0.0565
x 0.0865
I note that even in Reference mode, the "0" particle does not get x = 0. This is because a new feature has been implemented that creates a special "reference" particle automatically to have radius corresponding to the RING_DEFINITION BEAM_RINIT and momentum corresponding to the BEAM PC. Does that help any?
The fact that in a drift space the ID0 particle does not get x = 0 was suspicious to me. I had the feeling that the #ID0 particle stored in h5 file has been removed and replaced with a copy of #ID1. This was an artificial way to fix the problem with the "old reference particle ID0".
So I ran your input file: PSDumpTest.in with OPAL-1.6, set OPTION, PSDUMPFRAME=REFERENCE; and changed the first three particles of your beam in the following way:
60.000 0.00 0.000 0.00 0.00 0.000.150 0.00 0.000 0.00 0.00 0.000.000 0.00 0.000 0.00 0.00 0.00--- original beam from Chris
Here the plot of the horizontal position of these three particles:
The black line of #ID0 is hidden by the purple line of #ID1. This is confirmed looking at the content of the first step of PSDumpTest.h5. It shows that the first two particles are identical: the particle #ID0 has been removed and replaced with a copy of #ID1, as suspected.
You could check yourself if this is the case also for you... it could be that I did a mess with the OPAL versions.
Hi,
I will have to read through this long post more carefully, I think, but to answer your last question @ext-rogers_c, I did not yet upload any changes w.r.t. the reference particle stuff. @adelmann wrote a nice little class for tracer particles that will replace the reference particle within the bunch completely soon. But for now, as far as I know - and this is cyclotron tracker only! - for > 2 particles, the particle with ID0 is artificially set to have local position 0, 0, 0 and momentum 0, 0, 0 at the very beginning, during initialization, and is supposed to be the reference particle. I was not aware of it being overwritten with ID1 at any point. The particle with ID1 is an arbitrary other particle from the bunch, or presumably the second particle in the file when TYPE=fromfile.
Is all of this using OPAL-cycl? Or are you seeing the same behavior in OPAL-T? Which tracker are you using (MTS, RK4, LF2)?
You can compare the particle data with the *-trackOrbit.dat file which is written by a different method and only stores particles ID0 and ID1.
if PSDUMPFRAME = REFERENCE the conversion global frame -> local is done using a reference particle with coordinates (0,0,0).
if the beam OFFSETZ >0.0, the beam and the reference particle have different position since the vertical coordinate of the reference particle is not updated in the same way.
The different position of the beam and reference particle leads to a wrong conversion global->local frame.
A possible solution would be:
shift the field map and place the mid-plane to z = 0
the beam and the reference particle have the same vertical position
however it seems that there are problems in reading a field map with negative vertical coordinates (@adelmann further tests are needed)
The immediate solution for this issue would be performed the conversion global->local autonomously in the post processing analysis.
shift the field map and place the mid-plane to z = 0
3D field map placement is possible, but it would take a bit longer. Getting the coordinate transformation right may be fiddly.
the beam and the reference particle have the same vertical position
Implementing capability to have reference trajectory off the midplane would be a new feature. It would not be too difficult to implement.
however it seems that there are problems in reading a field map with negative vertical coordinates
I think negative vertical coordinates are not implemented. I could make the error message clearer. The code assumes that 0 is the midplane, and gets confused if it is not.
@gsell I have almost implemented a fix which would enable PROBE-like output in the coordinate system of the reference trajectory, which I think addresses this issue. I need to do some testing and debugging. I thought we agreed not to target OPAL2.2 for this feature. Do you want me to try to get it done for 2.2?
@adelmann I would love to - it isn't done yet however. This is effectively a feature request (PROBE in frame of reference particle). I have proto-code but not got the proper level of testing.