Page 1 of 1

elegant2astra bug

Posted: 27 Jul 2015, 09:39
by michael_borland
A bug in elegant2astra was reported by Piotr Traczykowski (Univ. Strathclyde). The conversion of time coordinate (used by elegant) to dz (used by ASTRA) was incorrect by the factor beta/betaz. The corrected verison of the script is attached.

--Michael

Re: elegant2astra bug

Posted: 07 Jun 2018, 12:18
by Biaobin
Hi Michael,

I am reading the elegant2astra csh scripts, I am confused about the calculation of betaz in line 35 and z in line 36. Why betaz=pz/sqrt(px^2+py^2+pz^2) ? According to this definition, betaz=vz/v (not vz/c). I searched the forum, you said that "ASTRA is a snapshot of the beam at a fixed time rather than a record of particle coordinates crossing a fixed z plane." Is this the reason that causes such differences?

And also I am confused about the calculation of x and y in line 44 and 45, x_astra = x_elegant + dz * xp, it means that x_astra = x_elegant + dz * px/pz. why?

Best,
Biaobin

Re: elegant2astra bug

Posted: 08 Jun 2018, 12:08
by michael_borland
Biaobin,

You are correct that there is a bug. Line 35 should be changed from

Code: Select all

"-define=column,betaz,pz px sqr py sqr + pz sqr + sqrt /"
to

Code: Select all

"-define=column,betaz,pz px sqr py sqr + pz sqr + 1 + sqrt /"
That is, betaz = pz/gamma. For highly relativistic particles it won't make any difference.

As for your second question px/pz = vx/vz = (dx/dt)/(dz/dt) = dx/dz, which is why we use that expression.

I've attached a corrected version of the script. Thanks for reporting the bug.

--Michael

Re: elegant2astra bug

Posted: 08 Jun 2018, 13:40
by Biaobin
Hi Michael,

Sorry for misleading you, I think the initial one is right. I think I understand it now.
betaz = vz/c = (m vz)/(mc) = pz/(mv * c/v) = (pz/p)*beta.
For highly relativistic particles beta is about 1. So betaz = pz/p, that's what you are using in your code.
And for low energy case, beta = sqrt(gamma^2 —1)/gamma = p / sqrt(p^2 + m0^2 * c^2), where p=sqrt(px^2 + py^2 + pz^2), and m0 is the rest mass. As we often perform the simulation with elegant begins at about 100 MeV to 150 MeV, it is highly relativistic case. Is this the reason that you are using the approximation formula ?

And for the second question, my confusion is that when transfer from elegant to astra, x_astra = x_elegant + dz * dx/dz, why it is not just x_astra = x_elegant ?

Re: elegant2astra bug

Posted: 08 Jun 2018, 14:32
by michael_borland
Biaobin,

I think the original version was incorrect for non-relativistic particles:
pz = betaz*gamma, so betaz = pz/gamma = pz/sqrt(px^2+py^2+pz^2+1). Only when p>>1 is betaz = pz/p approximately right.
You are right that elegant2astra was used mostly for highly relativistic particles, so practically speaking it probably doesn't matter.

The reason for the adjustment of x is that ASTRA needs a snapshot of the beam at a particular time (t= constant, z varies), whereas elegant outputs the time at which all particles cross a z plane (z=constant, t varies). Since the particles provided to ASTRA have to have their z coordinates adjusted, the x and y coordinates need to change according to the slopes.

--Michael

Re: elegant2astra bug

Posted: 08 Jun 2018, 16:21
by Biaobin
Hi Michael,

Actually we are talking about the same thing, we are using different units.

- (px, py, pz, p) in my previous reply are all in units of [eV/c]

- (px, py, pz, p) in your previous reply are all dimensionless, p = beta*gamma, pz = betaz* gamma

- In the code, (px, py, pz) are in units of [eV/c], (xp, yp, p) are dimensionless, p = beta*gamma

So in order to include the non-relativistic situation, line 35 should be modified as

Code: Select all

"-define=column,beta,p p sqr 1 + sqrt /" \
"-define=column,betaz,pz px sqr py sqr + pz sqr + sqrt / beta *" \

Re: elegant2astra bug

Posted: 08 Jun 2018, 17:37
by michael_borland
Biaobin,

You are correct. I missed the units issue. Here's the corrected version.

Thanks for your help.

--Michael